Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

markdown: Auto-link obsidian:// URLs.

Nithyaraj Mudhaliyara481806e821c
diff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.py
index 6acb6450e8e..714a8004ef5 100644
--- a/zerver/lib/markdown/__init__.py
+++ b/zerver/lib/markdown/__init__.py
@@ -84,6 +84,7 @@ html_safelisted_schemes = (
"magnet",
"mailto",
"matrix",
+ "obsidian",
"mms",
"news",
"nntp",
@@ -98,6 +99,7 @@ html_safelisted_schemes = (
"wtai",
"xmpp",
)
+auto_linked_schemes = ["https?", "obsidian"]
allowed_schemes = ("http", "https", "ftp", "file", "mid", *html_safelisted_schemes)
@@ -229,6 +231,7 @@ def get_web_link_regex() -> Pattern[str]:
# caching the value is super important here.
tlds = r"|".join(list_of_tlds())
+ schemes_regex = r"|".join(auto_linked_schemes)
# A link starts at a word boundary, and ends at space, punctuation, or end-of-input.
#
@@ -257,7 +260,7 @@ def get_web_link_regex() -> Pattern[str]:
# (Double-negative lookbehind to allow start-of-string)
(?P<url> # Main group
(?:(?: # Domain part
- https?://[\w.:@-]+? # If it has a protocol, anything goes.
+ (?:{schemes_regex})://[\w.:@-]+? # If it has a protocol, anything goes.
|(?: # Or, if not, be more strict to avoid false-positives
(?:[\w-]+\.)+ # One or more domain components, separated by dots
(?:{tlds}) # TLDs
diff --git a/zerver/tests/fixtures/markdown_test_cases.json b/zerver/tests/fixtures/markdown_test_cases.json
index 8b350929c1c..6f74ce947ff 100644
--- a/zerver/tests/fixtures/markdown_test_cases.json
+++ b/zerver/tests/fixtures/markdown_test_cases.json
@@ -1467,6 +1467,11 @@
"New logic with trailing dot: Go to https://podcasts.google.com?feed=abc.",
"<p>New logic with trailing dot: Go to <a href=\"https://podcasts.google.com?feed=abc\">https://podcasts.google.com?feed=abc</a>.</p>",
"Go to https://podcasts.google.com?feed=abc."
+ ],
+ [
+ "obsidian://open?vault=MyVault",
+ "<p>%s</p>",
+ "obsidian://open?vault=MyVault"
]
]
}
diff --git a/zerver/tests/test_markdown.py b/zerver/tests/test_markdown.py
index b29c5bd9688..d007d2b6fc4 100644
--- a/zerver/tests/test_markdown.py
+++ b/zerver/tests/test_markdown.py
@@ -640,6 +640,8 @@ class MarkdownFixtureTest(ZulipTestCase):
def replaced(payload: str, url: str, phrase: str = "") -> str:
if url[:4] == "http":
href = url
+ elif "://" in url:
+ href = url
elif "@" in url:
href = "mailto:" + url
else: