markslider toc
This commit is contained in:
@@ -111,7 +111,7 @@ class slide_reader:
|
|||||||
for row in f:
|
for row in f:
|
||||||
if not row:
|
if not row:
|
||||||
continue
|
continue
|
||||||
row=row.decode('utf-8').rstrip("\n\r")
|
row=row.decode('utf-8').rstrip("\n\r ")
|
||||||
if row.startswith("#") and not row.startswith("##"):
|
if row.startswith("#") and not row.startswith("##"):
|
||||||
if len(new_page)>0:
|
if len(new_page)>0:
|
||||||
self.data.append(new_page)
|
self.data.append(new_page)
|
||||||
@@ -119,9 +119,10 @@ class slide_reader:
|
|||||||
new_page.append(row)
|
new_page.append(row)
|
||||||
if len(new_page)>0:
|
if len(new_page)>0:
|
||||||
self.data.append(new_page)
|
self.data.append(new_page)
|
||||||
|
self.toc()
|
||||||
self.pages=len(self.data)
|
self.pages=len(self.data)
|
||||||
self.inc_page_no(0)
|
self.inc_page_no(0)
|
||||||
self.toc()
|
|
||||||
|
|
||||||
def get_data(self):
|
def get_data(self):
|
||||||
return self.data
|
return self.data
|
||||||
@@ -162,16 +163,25 @@ class slide_reader:
|
|||||||
def toc(self):
|
def toc(self):
|
||||||
if self.opts.toc:
|
if self.opts.toc:
|
||||||
TOC=["# "+self.opts.toc,""]
|
TOC=["# "+self.opts.toc,""]
|
||||||
for h1,page in enumerate(self.data):
|
for h1,page in enumerate(self.data[(self.opts.toc_page-1):]):
|
||||||
title=page[0].strip("# ")
|
title=page[0].strip("# ")
|
||||||
TOC.append("%d. %s"%(h1+1,title))
|
TOC.append("%d. %s"%(h1+1,title))
|
||||||
h2=0
|
subh=[0,0,0]
|
||||||
for line in page:
|
if self.opts.toc_depth>1:
|
||||||
if re.search("^##[^#]", line):
|
for line in page:
|
||||||
h2+=1
|
|
||||||
title=line.strip("# ")
|
title=line.strip("# ")
|
||||||
TOC.append(" %d.%d. %s"%(h1+1,h2,title))
|
if re.search("^##[^#]", line):
|
||||||
self.data.insert(1,TOC)
|
subh=[ subh[0]+1, 0, 0 ]
|
||||||
|
TOC.append(" %d.%d. %s"%(h1+1,subh[0],title))
|
||||||
|
if self.opts.toc_depth==2: continue
|
||||||
|
if re.search("^###[^#]", line):
|
||||||
|
subh=[ subh[0], subh[1]+1, 0 ]
|
||||||
|
TOC.append(" %d.%d.%d. %s"%(h1+1,subh[0],subh[1],title))
|
||||||
|
if self.opts.toc_depth==3: continue
|
||||||
|
if re.search("^####[^#]", line):
|
||||||
|
subh=[ subh[0], subh[1], subh[2]+1 ]
|
||||||
|
TOC.append(" %d.%d.%d.%d. %s"%(h1+1,subh[0],subh[1],subh[2],title))
|
||||||
|
self.data.insert(self.opts.toc_page-1,TOC)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -196,22 +206,27 @@ def setup_options():
|
|||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
epilog=__author__)
|
epilog=__author__)
|
||||||
|
|
||||||
parser.add_argument("--no-color","-n",action="store_false",dest="color",default=True,
|
|
||||||
help="Disable color.")
|
|
||||||
parser.add_argument("-v","--version",action="version",version=__version__)
|
parser.add_argument("-v","--version",action="version",version=__version__)
|
||||||
parser.add_argument("-m",action="store_true",dest="autocolor",default=False,
|
|
||||||
help="Color by markdown structure.")
|
|
||||||
parser.add_argument("--dc",action="store_true",dest="dark_colors",default=False,
|
parser.add_argument("--dc",action="store_true",dest="dark_colors",default=False,
|
||||||
help="Use dark colorscheme, better for white background terminals.")
|
help="Use dark colorscheme, better for white background terminals.")
|
||||||
parser.add_argument("--toc",action="store_true",dest="toc",default=False,
|
parser.add_argument("-m",action="store_true",dest="autocolor",default=False,
|
||||||
help="Display TOC as 2nd slide.")
|
help="Color by markdown structure.")
|
||||||
|
parser.add_argument("--no-color","-n",action="store_false",dest="color",default=True,
|
||||||
|
help="Disable color.")
|
||||||
parser.add_argument("-s",action="store_false",dest="menu",default=True,
|
parser.add_argument("-s",action="store_false",dest="menu",default=True,
|
||||||
help="Disable status bar.")
|
help="Disable status bar.")
|
||||||
parser.add_argument("-w",action="store_false",dest="wrap",default=True,
|
parser.add_argument("-w",action="store_false",dest="wrap",default=True,
|
||||||
help="Disable line wrapping. Cuts long lines.")
|
help="Disable line wrapping. Cuts long lines.")
|
||||||
parser.add_argument("-t",action="store",dest="toc",default=False,
|
parser.add_argument("--toc",action="store",dest="toc",default=False,
|
||||||
const="Table of contents", type=str, nargs='?',
|
const="Table of contents", type=str, nargs='?',
|
||||||
help="Insert table of contents as page 2. Define the header, or use default: %(const)s")
|
help="Insert table of contents. Define the header, or use default: %(const)s")
|
||||||
|
parser.add_argument("--toc-page",action="store",dest="toc_page",default=2, type=int,
|
||||||
|
help="Insert table of contents on a chosen page. default: %(const)s")
|
||||||
|
parser.add_argument("--toc-depth",action="store",dest="toc_depth",default=2, type=int,
|
||||||
|
choices=xrange(1,5),
|
||||||
|
help="Table of contents display depth. default: %(const)s")
|
||||||
parser.add_argument("filename",type=str,
|
parser.add_argument("filename",type=str,
|
||||||
help="File to show")
|
help="File to show")
|
||||||
opts=parser.parse_args()
|
opts=parser.parse_args()
|
||||||
|
|||||||
Reference in New Issue
Block a user