Skip to content

Commit f3bad31

Browse files
committed
199 Markdown specification (part 2 of 2)
1 parent cee8549 commit f3bad31

17 files changed

+552
-0
lines changed

notifications_utils/template2.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
def render_notify_markdown(markdown: str, personalization: dict = {}, as_html: bool = True) -> str:
2+
"""
3+
Substitute personalization values into markdown, and return the markdown as HTML or plain text.
4+
"""
5+
6+
# TODO - Perform substitutions in the markdown. Raise ValueError for missing fields.
7+
8+
if as_html:
9+
# TODO - pass the markdown to the HTML renderer
10+
pass
11+
else:
12+
# TODO - pass the markdown to the plain text renderer
13+
pass
14+
15+
raise NotImplementedError
16+
17+
18+
# TODO - The signature and return type might change after #213, during integration with notifcation-api.
19+
def render_email(
20+
html_content: str | None = None,
21+
plain_text_content: str | None = None,
22+
subject_personalization: dict = {}
23+
) -> tuple[str | None, str | None]:
24+
"""
25+
In addition to the content body, e-mail notifications might have personalization values in the
26+
subject line, and the content body might be plugged into a Jinja2 template.
27+
28+
The two "content" parameters generally are the output of render_notify_markdown (above).
29+
30+
returns: A 2-tuple in which the first value is the full HTML e-mail; the second, the plain text e-mail.
31+
"""
32+
33+
if html_content is None and plain_text_content is None:
34+
raise ValueError('You must supply one of these parameters.')
35+
36+
# TODO - Perform substitutions in the subject. Raise ValueError for missing fields.
37+
# TODO - Jinja2 template substitution
38+
39+
raise NotImplementedError
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<p><a href="https://www.youtube.com/watch?v=dQw4w9WgXcQ"><img alt="call to action img" src="https://dev-va-gov-assets.s3-us-gov-west-1.amazonaws.com/img/vanotify-action-link.png" class="action_link"><b>click</b></a></p>
2+
<p><a href="https://www.youtube.com/watch?v=dQw4w9WgXcQ"><img alt="call to action img" src="https://dev-va-gov-assets.s3-us-gov-west-1.amazonaws.com/img/vanotify-action-link.png" class="action_link"><b>action link</b></a></p>
3+
<p><a href="https://www.youtube.com/watch?v=dQw4w9WgXcQ"><img alt="call to action img" src="https://dev-va-gov-assets.s3-us-gov-west-1.amazonaws.com/img/vanotify-action-link.png" class="action_link"><b>click</b></a></p>
4+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<p><a href="https://www.youtube.com/watch?v=dQw4w%20%20%209WgXcQ"><img alt="call to action img" src="https://dev-va-gov-assets.s3-us-gov-west-1.amazonaws.com/img/vanotify-action-link.png" class="action_link"><b>click this</b></a></p>
2+
<p><a href="https%3A%2F%2Fwww.example.com%3Ft%3Dabc%20def"><img alt="call to action img" src="https://dev-va-gov-assets.s3-us-gov-west-1.amazonaws.com/img/vanotify-action-link.png" class="action_link"><b>action link</b></a></p>
3+
<p><a href="https%3A%2F%2Fwww.example.com%3Ft%3Dabc%20def"><img alt="call to action img" src="https://dev-va-gov-assets.s3-us-gov-west-1.amazonaws.com/img/vanotify-action-link.png" class="action_link"><b>click this</b></a></p>
4+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<h1>Block Quotes With Placeholders</h1>
2+
<h2>Github markdown syntax</h2>
3+
<blockquote>Your claims: <ul><li>one</li><li>two</li><li>three</li></ul></blockquote>
4+
<blockquote><ul><li>A</li><li>B</li><li>C</li></ul><blockquote><ul><li>D</li><li>E</li><li>F</li></ul></blockquote><ul><li>G</li><li>H</li><li>I</li></ul></blockquote>
5+
<h2>Notify markdown syntax</h2>
6+
<h1>Block Quotes With Placeholders</h1>
7+
<h2>Github markdown syntax</h2>
8+
<blockquote>Your claims: <ul><li>one</li><li>two</li><li>three</li></ul></blockquote>
9+
<blockquote><ul><li>A</li><li>B</li><li>C</li></ul><blockquote><ul><li>D</li><li>E</li><li>F</li></ul></blockquote><ul><li>G</li><li>H</li><li>I</li></ul></blockquote>
10+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<h1>Block Quotes With Placeholders</h1>
2+
<h2>Github markdown syntax</h2>
3+
<blockquote>Your claims: one, two, three</blockquote>
4+
<blockquote>A<blockquote>B</blockquote>C</blockquote>
5+
<h2>Notify markdown syntax</h2>
6+
<h1>Block Quotes With Placeholders</h1>
7+
<h2>Github markdown syntax</h2>
8+
<blockquote>Your claims: one, two, three</blockquote>
9+
<blockquote>A<blockquote>B</blockquote>C</blockquote>
10+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<h1>Links With Placeholders</h1>
2+
<h2>Links that are the entire line</h2>
3+
<p><a href='https://www.youtube.com/watch?v=dQw4w9WgXcQ'>here</a></p>
4+
<p><a href='https://www.youtube.com/watch?v=dQw4w9WgXcQ'>click</a></p>
5+
<p><a href='https://www.youtube.com/watch?v=dQw4w9WgXcQ'>click</a></p>
6+
<p><a href='https://www.youtube.com/watch?v=dQw4w9WgXcQ'>YouTube link</a></p>
7+
<h2>Links with other text</h2>
8+
<p>right <a href='https://www.youtube.com/watch?v=dQw4w9WgXcQ'>here</a> right now</p>
9+
<p>cat <a href='https://www.youtube.com/watch?v=dQw4w9WgXcQ'>click</a> dog</p>
10+
<p>peanut butter <a href='https://www.youtube.com/watch?v=dQw4w9WgXcQ'>click</a> jelly</p>
11+
<p>Behold! <a href='https://www.youtube.com/watch?v=dQw4w9WgXcQ'>this</a> is a YouTube link</p>
12+
<h2>Substitution in the middle of a link</h2>
13+
<p><a href='https://www.theonion.com'>here</a></p>
14+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<h1>Links With Placeholders</h1>
2+
<h2>Links that are the entire line</h2>
3+
<p><a href='https%3A%2F%2Fwww.example.com%3Ft%3Dabc%20def'>here</a></p>
4+
<p><a href='https://www.youtube.com/watch?v=dQw4w9WgXcQ'>click this</a></p>
5+
<p><a href='https%3A%2F%2Fwww.example.com%3Ft%3Dabc%20def'>click this</a></p>
6+
<p><a href='https://www.youtube.com/watch?v=dQw4w%20%20%209WgXcQ'>YouTube link</a></p>
7+
<h2>Links with other text</h2>
8+
<p>right <a href='https%3A%2F%2Fwww.example.com%3Ft%3Dabc%20def'>here</a> right now</p>
9+
<p>cat <a href='https://www.youtube.com/watch?v=dQw4w9WgXcQ'>click this</a> dog</p>
10+
<p>peanut butter <a href='https%3A%2F%2Fwww.example.com%3Ft%3Dabc%20def'>click this</a> jelly</p>
11+
<p>Behold! <a href='https://www.youtube.com/watch?v=dQw4w%20%20%209WgXcQ'>this</a> is a YouTube link</p>
12+
<h2>Substitution in the middle of a link</h2>
13+
<p><a href='https://www.the%20onion.com'>here</a></p>
14+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
>>[((url_text))](https://www.youtube.com/watch?v=((yt_video_id)))
2+
3+
>>[action link](((url)))
4+
5+
>>[((url_text))](((url)))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Block Quotes With Placeholders
2+
3+
## Github markdown syntax
4+
5+
> Your claims: ((claims))
6+
7+
> ((top))
8+
> > ((nested))
9+
> ((bottom))
10+
11+
## Notify markdown syntax
12+
13+
^ Your claims: ((claims))
14+
15+
^ ((top))
16+
^ ^ ((nested))
17+
^ ((bottom))
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Links With Placeholders
2+
3+
## Links that are the entire line
4+
5+
[here](((url)))
6+
7+
[((url_text))](https://www.youtube.com/watch?v=dQw4w9WgXcQ)
8+
9+
[((url_text))](((url)))
10+
11+
[YouTube link](https://www.youtube.com/watch?v=((yt_video_id)))
12+
13+
## Links with other text
14+
15+
right [here](((url))) right now
16+
17+
cat [((url_text))](https://www.youtube.com/watch?v=dQw4w9WgXcQ) dog
18+
19+
peanut butter [((url_text))](((url))) jelly
20+
21+
Behold! [This](https://www.youtube.com/watch?v=((yt_video_id))) is a YouTube link.
22+
23+
## Substitution in the middle of a link
24+
25+
[here](https://www.((url_fragment)).com)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
click: https://www.youtube.com/watch?v=dQw4w9WgXcQ
2+
3+
action link: https://www.youtube.com/watch?v=dQw4w9WgXcQ
4+
5+
click: https://www.youtube.com/watch?v=dQw4w9WgXcQ
6+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
click this: https://www.youtube.com/watch?v=dQw4w%20%20%209WgXcQ
2+
3+
action link: https%3A%2F%2Fwww.example.com%3Ft%3Dabc%20def
4+
5+
click this: https%3A%2F%2Fwww.example.com%3Ft%3Dabc%20def
6+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
3+
4+
Block Quotes With Placeholders
5+
-----------------------------------------------------------------
6+
7+
8+
Github markdown syntax
9+
-----------------------------------------------------------------
10+
11+
12+
Your claims:
13+
• one
14+
• two
15+
• three
16+
17+
18+
• A
19+
• B
20+
• C
21+
22+
23+
• D
24+
• E
25+
• F
26+
27+
28+
• G
29+
• H
30+
• I
31+
32+
33+
Notify markdown syntax
34+
-----------------------------------------------------------------
35+
36+
37+
Your claims:
38+
• one
39+
• two
40+
• three
41+
42+
43+
• A
44+
• B
45+
• C
46+
47+
48+
• D
49+
• E
50+
• F
51+
52+
53+
• G
54+
• H
55+
• I
56+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
3+
4+
Block Quotes With Placeholders
5+
-----------------------------------------------------------------
6+
7+
8+
Github markdown syntax
9+
-----------------------------------------------------------------
10+
11+
12+
Your claims: one, two, three
13+
14+
15+
A
16+
17+
18+
B
19+
20+
21+
C
22+
23+
24+
Notify markdown syntax
25+
-----------------------------------------------------------------
26+
27+
28+
Your claims: one, two, three
29+
30+
31+
A
32+
33+
34+
B
35+
36+
37+
C
38+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
3+
4+
Links With Placeholders
5+
-----------------------------------------------------------------
6+
7+
8+
Links that are the entire line
9+
-----------------------------------------------------------------
10+
here: https://www.youtube.com/watch?v=dQw4w9WgXcQ
11+
12+
click: https://www.youtube.com/watch?v=dQw4w9WgXcQ
13+
14+
click: https://www.youtube.com/watch?v=dQw4w9WgXcQ
15+
16+
YouTube link: https://www.youtube.com/watch?v=dQw4w9WgXcQ
17+
18+
19+
Links with other text
20+
-----------------------------------------------------------------
21+
right here: https://www.youtube.com/watch?v=dQw4w9WgXcQ right now
22+
23+
cat click: https://www.youtube.com/watch?v=dQw4w9WgXcQ dog
24+
25+
peanut butter click: https://www.youtube.com/watch?v=dQw4w9WgXcQ jelly
26+
27+
Behold! This: https://www.youtube.com/watch?v=dQw4w9WgXcQ is a YouTube link.
28+
29+
30+
Substitution in the middle of a link
31+
-----------------------------------------------------------------
32+
here: https://www.theonion.com
33+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
3+
4+
Links With Placeholders
5+
-----------------------------------------------------------------
6+
7+
8+
Links that are the entire line
9+
-----------------------------------------------------------------
10+
here: https%3A%2F%2Fwww.example.com%3Ft%3Dabc%20def
11+
12+
click this: https://www.youtube.com/watch?v=dQw4w9WgXcQ
13+
14+
click this: https%3A%2F%2Fwww.example.com%3Ft%3Dabc%20def
15+
16+
YouTube link: https://www.youtube.com/watch?v=dQw4w%20%20%209WgXcQ
17+
18+
19+
Links with other text
20+
-----------------------------------------------------------------
21+
right here: https%3A%2F%2Fwww.example.com%3Ft%3Dabc%20def right now
22+
23+
cat click this: https://www.youtube.com/watch?v=dQw4w9WgXcQ dog
24+
25+
peanut butter click this: https%3A%2F%2Fwww.example.com%3Ft%3Dabc%20def jelly
26+
27+
Behold! This: https://www.youtube.com/watch?v=dQw4w%20%20%209WgXcQ is a YouTube link.
28+
29+
30+
Substitution in the middle of a link
31+
-----------------------------------------------------------------
32+
here: https://www.the%20onion.com
33+

0 commit comments

Comments
 (0)