-
Notifications
You must be signed in to change notification settings - Fork 8
FAQs
tsutsu3 edited this page Nov 3, 2024
·
1 revision
Is there any way to change the default protocol used?
For example: "google.com" -> "http://google.com/"
Just overriding the default function of linkify.normalize
:
from markdown_it import MarkdownIt
md = MarkdownIt("commonmark", {"breaks": True, "html": True, "linkify": True}).enable(
["linkify"]
)
a = "link to somewhere.com"
print(md.render(a))
# <p>link to <a href="http://somewhere.com">somewhere.com</a></p>
def normalize(match):
"""Override default normalize"""
if not match.schema:
match.url = "https://" + match.url
if match.schema == "mailto:" and not re.search(
"^mailto:", match.url, flags=re.IGNORECASE
):
match.url = "mailto:" + match.url
md.linkify.normalize = normalize
print(md.render(a))
# <p>link to <a href="https://somewhere.com">somewhere.com</a></p>