Skip to content

Commit

Permalink
updated name and escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
Mole1424 committed Sep 17, 2024
1 parent 93bd3ea commit ab159d2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
57 changes: 31 additions & 26 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()])
4 changes: 2 additions & 2 deletions templates/main.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>DofE Emails</title>
<title>DofEmails</title>
<link rel="stylesheet" type="text/css" href="/static/main.css">
<script src="/static/main.js"></script>
<link rel="icon" type="image/png" sizes="32x32" href="/static/favicon-32x32.png">
Expand All @@ -16,7 +16,7 @@
</div>
<div class="header-item">
<div class="header-text">
<h1>DofE Email Generator</h1>
<h1>DofEmail Generator</h1>
<h2>Becuase the SU website is a pain in the ass</h2>
<p><a href="https://www.youtube.com/watch?v=dQw4w9WgXcQ">How to use</a></p>
</div>
Expand Down

0 comments on commit ab159d2

Please sign in to comment.