From acde0e1538bb16ed41ecb938348341e7cf9c6308 Mon Sep 17 00:00:00 2001 From: Dan Goldsmith Date: Fri, 4 Sep 2020 07:14:41 +0100 Subject: [PATCH 1/2] Parser updated to pre-render --- remarkable/parser.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/remarkable/parser.py b/remarkable/parser.py index 46c7e82..c461949 100644 --- a/remarkable/parser.py +++ b/remarkable/parser.py @@ -19,6 +19,7 @@ import logging import re +import jinja2 import yaml import remarkable.section as section @@ -43,6 +44,7 @@ class MarkdownParser(): #And things we are storing self.sections = None self.header = None + self.page = None #Add this for the generic template self.sectionOrder = [] @@ -163,10 +165,27 @@ class MarkdownParser(): sections based on the line headings. """ + + + + + #TODO: Fix this Kludge + tempHeader = {"page":{"meta":self.header}} + + #First pass of the text with jinja + preRender = jinja2.Template("\n".join(theText)) + postRender = preRender.render(tempHeader) + print(postRender) + postRender = postRender.split("\n") + currentSection = None out = [] sections = {} - for line in theText: + #for line in theText: + for line in postRender: + print("------") + print(line) + print("-------") #self.log.debug(" {0}".format(line)) if line.startswith("# "): #Kludgy Space for matching if currentSection: From f7a0ce63c662964d3ed750796285fc2f88dc3e25 Mon Sep 17 00:00:00 2001 From: Dan Goldsmith Date: Fri, 4 Sep 2020 07:18:22 +0100 Subject: [PATCH 2/2] Add Page Meta as a template Var --- examples/cw_brief2.md | 3 +++ remarkable/parser.py | 2 +- remarkable/renderer.py | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/cw_brief2.md b/examples/cw_brief2.md index c3556e4..1ec15a0 100644 --- a/examples/cw_brief2.md +++ b/examples/cw_brief2.md @@ -41,3 +41,6 @@ passwords of any length, with (almost) all ASCII characters as valid symbols, making use of a flaw in the binaries that allows a "timing attack". +## Due date + +The couresework is due by {{page.meta.due}} diff --git a/remarkable/parser.py b/remarkable/parser.py index c461949..93a17dc 100644 --- a/remarkable/parser.py +++ b/remarkable/parser.py @@ -169,7 +169,7 @@ class MarkdownParser(): - #TODO: Fix this Kludge + #TODO: ---------- Fix this Kludge ------------ tempHeader = {"page":{"meta":self.header}} #First pass of the text with jinja diff --git a/remarkable/renderer.py b/remarkable/renderer.py index 2dcbd0f..0eda896 100644 --- a/remarkable/renderer.py +++ b/remarkable/renderer.py @@ -138,5 +138,6 @@ class HTMLRenderer(Renderer): out = self.template.render({"content":sections, "header": header, "order": theParser.sectionOrder, - "calcs": calcs}) + "calcs": calcs, + "page":{"meta": header}}) return out