mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-04-11 08:12:09 -04:00
notifications: handle URL encoding in markdown2html
This commit is contained in:
@@ -32,8 +32,15 @@ function markdownToHtml(text) {
|
||||
return `\x00INLINECODE${inlineIndex++}\x00`;
|
||||
});
|
||||
|
||||
// Now process everything else
|
||||
// Escape HTML entities (but not in code blocks)
|
||||
// Extract plain URLs before escaping so & in query strings is preserved
|
||||
const urls = [];
|
||||
let urlIndex = 0;
|
||||
html = html.replace(/(^|[\s])((?:https?|file):\/\/[^\s]+)/gm, (match, prefix, url) => {
|
||||
urls.push(url);
|
||||
return prefix + `\x00URL${urlIndex++}\x00`;
|
||||
});
|
||||
|
||||
// Escape HTML entities (but not in code blocks or URLs)
|
||||
html = html.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>');
|
||||
@@ -64,8 +71,12 @@ function markdownToHtml(text) {
|
||||
return '<ul>' + match + '</ul>';
|
||||
});
|
||||
|
||||
// Detect plain URLs and wrap them in anchor tags (but not inside existing <a> or markdown links)
|
||||
html = html.replace(/(^|[^"'>])((https?|file):\/\/[^\s<]+)/g, '$1<a href="$2">$2</a>');
|
||||
// Restore extracted URLs as anchor tags (preserves raw & in href)
|
||||
html = html.replace(/\x00URL(\d+)\x00/g, (_, index) => {
|
||||
const url = urls[parseInt(index)];
|
||||
const display = url.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
||||
return `<a href="${url}">${display}</a>`;
|
||||
});
|
||||
|
||||
// Restore code blocks and inline code BEFORE line break processing
|
||||
html = html.replace(/\x00CODEBLOCK(\d+)\x00/g, (match, index) => {
|
||||
|
||||
Reference in New Issue
Block a user