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.
- Loading branch information
Showing
4 changed files
with
69 additions
and
36 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,33 @@ | ||
""" | ||
A Mistune plugin to parse "action links" in markdown. An action link is specified like this: | ||
>>[action](https://example.com/foo?a=b) | ||
""" | ||
|
||
from re import Match | ||
|
||
from mistune.block_parser import BlockParser | ||
from mistune.core import BlockState | ||
from mistune.markdown import Markdown | ||
from mistune.util import escape_url | ||
|
||
|
||
ACTION_LINK_PATTERN = r'''>>\[(?P<text>[\w ]+)\]\((?P<url>\S+)\)''' | ||
# ACTION_LINK_PATTERN = r'''\[action''' | ||
|
||
|
||
def parse_action_link(block: BlockParser, m: Match[str], state: BlockState) -> int: | ||
# print("PARSE ACTION LINK", m) # TODO - delete | ||
text = m.group('text') | ||
url = m.group('url') | ||
state.append_token({ | ||
'type': 'action_link', | ||
'attrs': { | ||
'text': text, | ||
'url': escape_url(url), | ||
}, | ||
}) | ||
return m.end() | ||
|
||
|
||
def action_link(md: Markdown): | ||
md.block.register("block_action_link", ACTION_LINK_PATTERN, parse_action_link, before='block_text') |
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
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
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