diff options
Diffstat (limited to 'src/md.py')
-rwxr-xr-x | src/md.py | 24 |
1 files changed, 23 insertions, 1 deletions
@@ -7,6 +7,9 @@ from jinja2 import Environment, PackageLoader, Template, FileSystemLoader import mistune +#global name for templates +article = {} + class TocMixin(): """TOC mixin for Renderer, mix this with Renderer:: @@ -98,6 +101,24 @@ class TocRenderer(TocMixin, mistune.Renderer): pass ################################################################################ +#get first tags and use them to configure some bits +def get_tags(data): + text = "" + tag_section = True + for line in data.split("\n"): + if tag_section: + tag = line.split(":") + l = len(tag) + if l != 2: + tag_section = False + text += line+"\n" + else: + article[tag[0]] = tag[1] + else: + text += line+"\n" + return text + +################################################################################ #check if there is input file if len(sys.argv) < 2: print "Need more arguments" @@ -114,6 +135,7 @@ t = templ_env.get_template("main.thtml") #get md file f = open( md_fn, "r" ) data = f.read() +data = get_tags(data) toc = TocRenderer() md = mistune.Markdown(rule=True,renderer=toc) @@ -122,4 +144,4 @@ md.parse(data) md_rend_toc = toc.render_toc(level=3) md_rend = md_rend_toc + md.render( data ) -print t.render( block = md_rend )
\ No newline at end of file +print t.render( article=article, block = md_rend )
\ No newline at end of file |