diff options
author | Arturs Artamonovs <dos21h@gmail.com> | 2023-01-29 10:30:54 +0000 |
---|---|---|
committer | Arturs Artamonovs <dos21h@gmail.com> | 2023-01-29 10:30:54 +0000 |
commit | 66fa71a8f11b6ce5e8471b533f67cc3a1fdb85a8 (patch) | |
tree | 7aed7f385826a3bd88c76a373e28c6cfae4f396e /src/mistune/plugins/url.py | |
parent | 129c1201ea5c4418f0f89ad932633c7cea2439b7 (diff) | |
download | md-site-66fa71a8f11b6ce5e8471b533f67cc3a1fdb85a8.tar.gz md-site-66fa71a8f11b6ce5e8471b533f67cc3a1fdb85a8.zip |
Update to new mistune, removed old mistune, rewrite to python3
Diffstat (limited to 'src/mistune/plugins/url.py')
-rw-r--r-- | src/mistune/plugins/url.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/mistune/plugins/url.py b/src/mistune/plugins/url.py new file mode 100644 index 0000000..d6f2251 --- /dev/null +++ b/src/mistune/plugins/url.py @@ -0,0 +1,23 @@ +from ..util import escape_url + +__all__ = ['url'] + +URL_LINK_PATTERN = r'''https?:\/\/[^\s<]+[^<.,:;"')\]\s]''' + + +def parse_url_link(inline, m, state): + text = m.group(0) + pos = m.end() + if state.in_link: + inline.process_text(text, state) + return pos + state.append_token({ + 'type': 'link', + 'children': [{'type': 'text', 'raw': text}], + 'attrs': {'url': escape_url(text)}, + }) + return pos + + +def url(md): + md.inline.register('url_link', URL_LINK_PATTERN, parse_url_link) |