Skip to content

Commit 218dccf

Browse files
committed
fix: inline hyperlinks
Now usable and stable!
1 parent 74dbf16 commit 218dccf

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/js/markdown.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,17 @@ function internalParseMarkdown(md, prevLinks) {
8484
}
8585
// Links:
8686
else if (token[10]) {
87-
out = out.replace('<a>', `<a href="${encodeAttr(token[11] || links[prev.toLowerCase()])}">`);
88-
chunk = flush() + '</a>';
87+
// Get the URL from either direct URL or reference
88+
const url = token[11] || links[prev.toLowerCase()];
89+
if (url) {
90+
// Only create a link if there's actually a URL
91+
out = out.replace('<a>', `<a href="${encodeAttr(url)}">`);
92+
chunk = flush() + '</a>';
93+
} else {
94+
// If no URL, replace the opening <a> tag with the original bracket text
95+
out = out.replace('<a>', '[');
96+
chunk = flush() + ']';
97+
}
8998
}
9099
else if (token[9]) {
91100
chunk = '<a>';

src/main.js

+6
Original file line numberDiff line numberDiff line change
@@ -2213,6 +2213,12 @@ document.addEventListener('click', (e) => {
22132213
// If we're clicking the emoji search, don't close it!
22142214
if (e.target === emojiSearch) return;
22152215

2216+
// If we're clicking an <a> link, handle it with our openUrl function
2217+
if (e.target.tagName === 'A' && e.target.href) {
2218+
e.preventDefault();
2219+
return openUrl(e.target.href);
2220+
}
2221+
22162222
// If we're clicking a Reply button, begin a reply
22172223
if (e.target.classList.contains("reply-btn")) return selectReplyingMessage(e);
22182224

0 commit comments

Comments
 (0)