From 0e3bf8fe600072a715764a150dc3c27b6e57da58 Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Wed, 9 Nov 2016 20:27:16 +0000 Subject: Added tag support --- src/md.py | 24 +++++++++++++++++++++++- src/templ/base.thtml | 3 ++- 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/md.py b/src/md.py index a37d5ce..8c131a4 100755 --- a/src/md.py +++ b/src/md.py @@ -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:: @@ -97,6 +100,24 @@ class TocMixin(): 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: @@ -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 diff --git a/src/templ/base.thtml b/src/templ/base.thtml index 2d6b53a..dc647d7 100644 --- a/src/templ/base.thtml +++ b/src/templ/base.thtml @@ -7,7 +7,8 @@ - {% block title %}{% endblock %} + {{article.title}} + {% if article.keywords %}{% endif %} -- cgit v1.2.3