From ab159d2c1b45baf2aa3f209d0397492ae23635ed Mon Sep 17 00:00:00 2001 From: Joel Coulon Date: Tue, 17 Sep 2024 21:59:05 +0200 Subject: [PATCH] updated name and escaping --- app.py | 57 ++++++++++++++++++++++++--------------------- templates/main.html | 4 ++-- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/app.py b/app.py index dbe6173..8b06193 100644 --- a/app.py +++ b/app.py @@ -16,37 +16,24 @@ def index(): return render_template("main.html", num_events=int(num_events)) -# shamelessly stolen from docs (https://python-markdown.github.io/extensions/api/#example_3) -class DelInlineProcessor(InlineProcessor): - def handleMatch(self, m, data): - el = etree.Element("del") - el.text = m.group(1) - return el, m.start(0), m.end(0) - - -class DelExtension(Extension): - def extendMarkdown(self, md): - DEL_PATTERN = r"~~(.*?)~~" # like ~~del~~ - md.inlinePatterns.register(DelInlineProcessor(DEL_PATTERN, md), "del", 175) - - @app.route("/createEmail", methods=["POST"]) def create_email(): json = request.get_json() - week_no = json["weekNo"] - introduction = json["introduction"] + week_no = sanitize(json["weekNo"]) + introduction = sanitize(json["introduction"]) events = json["events"] + # apply markdown to the escaped description for event in events: - event["description"] = markdown( - escape(event["description"]), extensions=[DelExtension()] - ) - conclusion = json["conclusion"] - name = json["name"] - whatsapp = json["whatsapp"] - instagram = json["instagram"] - email = json["email"] - facebook = json["facebook"] - website = json["website"] + event["title"] = sanitize(event["title"]) + event["description"] = sanitize(event["description"]) + event["tldr"] = sanitize(event["tldr"]) + conclusion = sanitize(json["conclusion"]) + name = sanitize(json["name"]) + whatsapp = sanitize(json["whatsapp"]) + instagram = sanitize(json["instagram"]) + email = sanitize(json["email"]) + facebook = sanitize(json["facebook"]) + website = sanitize(json["website"]) return render_template( "newsletter.html", week_no=week_no, @@ -60,3 +47,21 @@ def create_email(): facebook=facebook, website=website, ) + + +# shamelessly stolen from docs (https://python-markdown.github.io/extensions/api/#example_3) +class DelInlineProcessor(InlineProcessor): + def handleMatch(self, m, data): + el = etree.Element("del") + el.text = m.group(1) + return el, m.start(0), m.end(0) + + +class DelExtension(Extension): + def extendMarkdown(self, md): + DEL_PATTERN = r"~~(.*?)~~" # like ~~del~~ + md.inlinePatterns.register(DelInlineProcessor(DEL_PATTERN, md), "del", 175) + + +def sanitize(input): + return markdown(escape(input), extensions=[DelExtension()]) diff --git a/templates/main.html b/templates/main.html index 43f8029..9579c25 100644 --- a/templates/main.html +++ b/templates/main.html @@ -1,7 +1,7 @@ - DofE Emails + DofEmails @@ -16,7 +16,7 @@
-

DofE Email Generator

+

DofEmail Generator

Becuase the SU website is a pain in the ass

How to use