rename dupes

This commit is contained in:
q
2019-04-11 21:29:27 +03:00
parent 8bbe668c46
commit de67182cc8
3 changed files with 26 additions and 5 deletions

View File

@@ -20,7 +20,7 @@
'''Markslider: a slideshow engine based on markdown.'''
__author__ = "Ville Rantanen <ville.q.rantanen@gmail.com>"
__version__ = "1.1"
__version__ = "1.2"
import sys,os,argparse,re,datetime
from argparse import ArgumentParser
@@ -49,7 +49,7 @@ class EndProgram( Exception ):
class slide_reader:
""" Class for reading files. """
def __init__(self,files,opts):
def __init__(self, files, opts):
self.filename = files[0]
self.files = files
self.reader = None
@@ -105,6 +105,7 @@ class slide_reader:
self.file_start_page.append(len(self.data))
if len(self.data)==0:
raise ValueError("File does not have a # header")
self.rename_duplicates()
self.toc()
self.pages=len(self.data)
self.inc_page_no(0)
@@ -257,6 +258,23 @@ class slide_reader:
return return_value
# return [s]
def rename_duplicates(self):
if not opts.rename_title:
return
titles = {}
page_nos = []
for page in self.data:
if not page[0] in titles:
titles[page[0]] = 0
titles[page[0]] += 1
page_nos.append(titles[page[0]])
for page, page_no in zip(self.data, page_nos):
if titles[page[0]] > 1:
page[0] += " [%d/%d]"%( page_no, titles[page[0]] )
def get_interactive_help_text():
return ''' left/right,page up/down,home,end
@@ -308,6 +326,8 @@ Keyboard shortcuts:
help="Disable color by markdown structure.")
content.add_argument("--no-color","-n",action="store_false",dest="color",default=True,
help="Disable color.")
content.add_argument("--no-rename","--nr",action="store_false",dest="rename_title", default=True,
help="Disable automatic renaming of duplicate titles.")
execution.add_argument("-e",action="store_true",dest="execute",default=False,
help="Execute commands in `! or `> tags at show time with Enter key. WARNING: Potentially very dangerous to run others' slides with this switch!")