Skip to content

Commit

Permalink
199 Markdown specification (part 2 of 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
kalbfled committed Mar 7, 2025
1 parent cee8549 commit f3bad31
Show file tree
Hide file tree
Showing 17 changed files with 552 additions and 0 deletions.
39 changes: 39 additions & 0 deletions notifications_utils/template2.py
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
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>

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>

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>

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 tests/test_files/html/placeholders/links_placeholders_simple.html
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 tests/test_files/html/placeholders/links_placeholders_spaces.html
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>

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)))
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 tests/test_files/markdown/placeholders/links_placeholders.md
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)
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

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

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

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

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

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

Loading

0 comments on commit f3bad31

Please sign in to comment.