forked from cds-snc/notification-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
199 Markdown specification (part 2 of 2)
- Loading branch information
Showing
17 changed files
with
552 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
def render_notify_markdown(markdown: str, personalization: dict = {}, as_html: bool = True) -> str: | ||
""" | ||
Substitute personalization values into markdown, and return the markdown as HTML or plain text. | ||
""" | ||
|
||
# TODO - Perform substitutions in the markdown. Raise ValueError for missing fields. | ||
|
||
if as_html: | ||
# TODO - pass the markdown to the HTML renderer | ||
pass | ||
else: | ||
# TODO - pass the markdown to the plain text renderer | ||
pass | ||
|
||
raise NotImplementedError | ||
|
||
|
||
# TODO - The signature and return type might change after #213, during integration with notifcation-api. | ||
def render_email( | ||
html_content: str | None = None, | ||
plain_text_content: str | None = None, | ||
subject_personalization: dict = {} | ||
) -> tuple[str | None, str | None]: | ||
""" | ||
In addition to the content body, e-mail notifications might have personalization values in the | ||
subject line, and the content body might be plugged into a Jinja2 template. | ||
The two "content" parameters generally are the output of render_notify_markdown (above). | ||
returns: A 2-tuple in which the first value is the full HTML e-mail; the second, the plain text e-mail. | ||
""" | ||
|
||
if html_content is None and plain_text_content is None: | ||
raise ValueError('You must supply one of these parameters.') | ||
|
||
# TODO - Perform substitutions in the subject. Raise ValueError for missing fields. | ||
# TODO - Jinja2 template substitution | ||
|
||
raise NotImplementedError |
4 changes: 4 additions & 0 deletions
4
tests/test_files/html/placeholders/action_links_placeholders_simple.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<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> | ||
<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> | ||
<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 changes: 4 additions & 0 deletions
4
tests/test_files/html/placeholders/action_links_placeholders_spaces.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<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> | ||
<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> | ||
<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> | ||
|
10 changes: 10 additions & 0 deletions
10
tests/test_files/html/placeholders/block_quotes_placeholders_lists.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<h1>Block Quotes With Placeholders</h1> | ||
<h2>Github markdown syntax</h2> | ||
<blockquote>Your claims: <ul><li>one</li><li>two</li><li>three</li></ul></blockquote> | ||
<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> | ||
<h2>Notify markdown syntax</h2> | ||
<h1>Block Quotes With Placeholders</h1> | ||
<h2>Github markdown syntax</h2> | ||
<blockquote>Your claims: <ul><li>one</li><li>two</li><li>three</li></ul></blockquote> | ||
<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 changes: 10 additions & 0 deletions
10
tests/test_files/html/placeholders/block_quotes_placeholders_simple.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<h1>Block Quotes With Placeholders</h1> | ||
<h2>Github markdown syntax</h2> | ||
<blockquote>Your claims: one, two, three</blockquote> | ||
<blockquote>A<blockquote>B</blockquote>C</blockquote> | ||
<h2>Notify markdown syntax</h2> | ||
<h1>Block Quotes With Placeholders</h1> | ||
<h2>Github markdown syntax</h2> | ||
<blockquote>Your claims: one, two, three</blockquote> | ||
<blockquote>A<blockquote>B</blockquote>C</blockquote> | ||
|
14 changes: 14 additions & 0 deletions
14
tests/test_files/html/placeholders/links_placeholders_simple.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<h1>Links With Placeholders</h1> | ||
<h2>Links that are the entire line</h2> | ||
<p><a href='https://www.youtube.com/watch?v=dQw4w9WgXcQ'>here</a></p> | ||
<p><a href='https://www.youtube.com/watch?v=dQw4w9WgXcQ'>click</a></p> | ||
<p><a href='https://www.youtube.com/watch?v=dQw4w9WgXcQ'>click</a></p> | ||
<p><a href='https://www.youtube.com/watch?v=dQw4w9WgXcQ'>YouTube link</a></p> | ||
<h2>Links with other text</h2> | ||
<p>right <a href='https://www.youtube.com/watch?v=dQw4w9WgXcQ'>here</a> right now</p> | ||
<p>cat <a href='https://www.youtube.com/watch?v=dQw4w9WgXcQ'>click</a> dog</p> | ||
<p>peanut butter <a href='https://www.youtube.com/watch?v=dQw4w9WgXcQ'>click</a> jelly</p> | ||
<p>Behold! <a href='https://www.youtube.com/watch?v=dQw4w9WgXcQ'>this</a> is a YouTube link</p> | ||
<h2>Substitution in the middle of a link</h2> | ||
<p><a href='https://www.theonion.com'>here</a></p> | ||
|
14 changes: 14 additions & 0 deletions
14
tests/test_files/html/placeholders/links_placeholders_spaces.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<h1>Links With Placeholders</h1> | ||
<h2>Links that are the entire line</h2> | ||
<p><a href='https%3A%2F%2Fwww.example.com%3Ft%3Dabc%20def'>here</a></p> | ||
<p><a href='https://www.youtube.com/watch?v=dQw4w9WgXcQ'>click this</a></p> | ||
<p><a href='https%3A%2F%2Fwww.example.com%3Ft%3Dabc%20def'>click this</a></p> | ||
<p><a href='https://www.youtube.com/watch?v=dQw4w%20%20%209WgXcQ'>YouTube link</a></p> | ||
<h2>Links with other text</h2> | ||
<p>right <a href='https%3A%2F%2Fwww.example.com%3Ft%3Dabc%20def'>here</a> right now</p> | ||
<p>cat <a href='https://www.youtube.com/watch?v=dQw4w9WgXcQ'>click this</a> dog</p> | ||
<p>peanut butter <a href='https%3A%2F%2Fwww.example.com%3Ft%3Dabc%20def'>click this</a> jelly</p> | ||
<p>Behold! <a href='https://www.youtube.com/watch?v=dQw4w%20%20%209WgXcQ'>this</a> is a YouTube link</p> | ||
<h2>Substitution in the middle of a link</h2> | ||
<p><a href='https://www.the%20onion.com'>here</a></p> | ||
|
5 changes: 5 additions & 0 deletions
5
tests/test_files/markdown/placeholders/action_links_placeholders.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
>>[((url_text))](https://www.youtube.com/watch?v=((yt_video_id))) | ||
>>[action link](((url))) | ||
>>[((url_text))](((url))) |
17 changes: 17 additions & 0 deletions
17
tests/test_files/markdown/placeholders/block_quotes_placeholders.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Block Quotes With Placeholders | ||
|
||
## Github markdown syntax | ||
|
||
> Your claims: ((claims)) | ||
> ((top)) | ||
> > ((nested)) | ||
> ((bottom)) | ||
## Notify markdown syntax | ||
|
||
^ Your claims: ((claims)) | ||
|
||
^ ((top)) | ||
^ ^ ((nested)) | ||
^ ((bottom)) |
25 changes: 25 additions & 0 deletions
25
tests/test_files/markdown/placeholders/links_placeholders.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Links With Placeholders | ||
|
||
## Links that are the entire line | ||
|
||
[here](((url))) | ||
|
||
[((url_text))](https://www.youtube.com/watch?v=dQw4w9WgXcQ) | ||
|
||
[((url_text))](((url))) | ||
|
||
[YouTube link](https://www.youtube.com/watch?v=((yt_video_id))) | ||
|
||
## Links with other text | ||
|
||
right [here](((url))) right now | ||
|
||
cat [((url_text))](https://www.youtube.com/watch?v=dQw4w9WgXcQ) dog | ||
|
||
peanut butter [((url_text))](((url))) jelly | ||
|
||
Behold! [This](https://www.youtube.com/watch?v=((yt_video_id))) is a YouTube link. | ||
|
||
## Substitution in the middle of a link | ||
|
||
[here](https://www.((url_fragment)).com) |
6 changes: 6 additions & 0 deletions
6
tests/test_files/plain_text/placeholders/action_links_placeholders_simple.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
click: https://www.youtube.com/watch?v=dQw4w9WgXcQ | ||
|
||
action link: https://www.youtube.com/watch?v=dQw4w9WgXcQ | ||
|
||
click: https://www.youtube.com/watch?v=dQw4w9WgXcQ | ||
|
6 changes: 6 additions & 0 deletions
6
tests/test_files/plain_text/placeholders/action_links_placeholders_spaces.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
click this: https://www.youtube.com/watch?v=dQw4w%20%20%209WgXcQ | ||
|
||
action link: https%3A%2F%2Fwww.example.com%3Ft%3Dabc%20def | ||
|
||
click this: https%3A%2F%2Fwww.example.com%3Ft%3Dabc%20def | ||
|
56 changes: 56 additions & 0 deletions
56
tests/test_files/plain_text/placeholders/block_quotes_placeholders_lists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
|
||
|
||
|
||
Block Quotes With Placeholders | ||
----------------------------------------------------------------- | ||
|
||
|
||
Github markdown syntax | ||
----------------------------------------------------------------- | ||
|
||
|
||
Your claims: | ||
• one | ||
• two | ||
• three | ||
|
||
|
||
• A | ||
• B | ||
• C | ||
|
||
|
||
• D | ||
• E | ||
• F | ||
|
||
|
||
• G | ||
• H | ||
• I | ||
|
||
|
||
Notify markdown syntax | ||
----------------------------------------------------------------- | ||
|
||
|
||
Your claims: | ||
• one | ||
• two | ||
• three | ||
|
||
|
||
• A | ||
• B | ||
• C | ||
|
||
|
||
• D | ||
• E | ||
• F | ||
|
||
|
||
• G | ||
• H | ||
• I | ||
|
38 changes: 38 additions & 0 deletions
38
tests/test_files/plain_text/placeholders/block_quotes_placeholders_simple.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
|
||
|
||
Block Quotes With Placeholders | ||
----------------------------------------------------------------- | ||
|
||
|
||
Github markdown syntax | ||
----------------------------------------------------------------- | ||
|
||
|
||
Your claims: one, two, three | ||
|
||
|
||
A | ||
|
||
|
||
B | ||
|
||
|
||
C | ||
|
||
|
||
Notify markdown syntax | ||
----------------------------------------------------------------- | ||
|
||
|
||
Your claims: one, two, three | ||
|
||
|
||
A | ||
|
||
|
||
B | ||
|
||
|
||
C | ||
|
33 changes: 33 additions & 0 deletions
33
tests/test_files/plain_text/placeholders/links_placeholders_simple.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
|
||
|
||
Links With Placeholders | ||
----------------------------------------------------------------- | ||
|
||
|
||
Links that are the entire line | ||
----------------------------------------------------------------- | ||
here: https://www.youtube.com/watch?v=dQw4w9WgXcQ | ||
|
||
click: https://www.youtube.com/watch?v=dQw4w9WgXcQ | ||
|
||
click: https://www.youtube.com/watch?v=dQw4w9WgXcQ | ||
|
||
YouTube link: https://www.youtube.com/watch?v=dQw4w9WgXcQ | ||
|
||
|
||
Links with other text | ||
----------------------------------------------------------------- | ||
right here: https://www.youtube.com/watch?v=dQw4w9WgXcQ right now | ||
|
||
cat click: https://www.youtube.com/watch?v=dQw4w9WgXcQ dog | ||
|
||
peanut butter click: https://www.youtube.com/watch?v=dQw4w9WgXcQ jelly | ||
|
||
Behold! This: https://www.youtube.com/watch?v=dQw4w9WgXcQ is a YouTube link. | ||
|
||
|
||
Substitution in the middle of a link | ||
----------------------------------------------------------------- | ||
here: https://www.theonion.com | ||
|
33 changes: 33 additions & 0 deletions
33
tests/test_files/plain_text/placeholders/links_placeholders_spaces.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
|
||
|
||
Links With Placeholders | ||
----------------------------------------------------------------- | ||
|
||
|
||
Links that are the entire line | ||
----------------------------------------------------------------- | ||
here: https%3A%2F%2Fwww.example.com%3Ft%3Dabc%20def | ||
|
||
click this: https://www.youtube.com/watch?v=dQw4w9WgXcQ | ||
|
||
click this: https%3A%2F%2Fwww.example.com%3Ft%3Dabc%20def | ||
|
||
YouTube link: https://www.youtube.com/watch?v=dQw4w%20%20%209WgXcQ | ||
|
||
|
||
Links with other text | ||
----------------------------------------------------------------- | ||
right here: https%3A%2F%2Fwww.example.com%3Ft%3Dabc%20def right now | ||
|
||
cat click this: https://www.youtube.com/watch?v=dQw4w9WgXcQ dog | ||
|
||
peanut butter click this: https%3A%2F%2Fwww.example.com%3Ft%3Dabc%20def jelly | ||
|
||
Behold! This: https://www.youtube.com/watch?v=dQw4w%20%20%209WgXcQ is a YouTube link. | ||
|
||
|
||
Substitution in the middle of a link | ||
----------------------------------------------------------------- | ||
here: https://www.the%20onion.com | ||
|
Oops, something went wrong.