Skip to content

Commit

Permalink
Fix broken emoji with md pattern in shortcode (#1514)
Browse files Browse the repository at this point in the history
* fix broken emoji with md pattern in shortcode

* fix html regex when generating editor output
  • Loading branch information
ajbura committed Oct 29, 2023
1 parent 3cef074 commit a2cbe79
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/app/components/editor/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,25 @@ const elementToCustomHtml = (node: CustomElement, children: string): string => {
return `<ul>${children}</ul>`;

case BlockType.Mention:
return `<a href="https://matrix.to/#/${node.id}">${node.name}</a>`;
return `<a href="https://matrix.to/#/${encodeURIComponent(node.id)}">${sanitizeText(
node.name
)}</a>`;
case BlockType.Emoticon:
return node.key.startsWith('mxc://')
? `<img data-mx-emoticon src="${node.key}" alt="${node.shortcode}" title="${node.shortcode}" height="32">`
: node.key;
? `<img data-mx-emoticon src="${node.key}" alt="${sanitizeText(
node.shortcode
)}" title="${sanitizeText(node.shortcode)}" height="32" />`
: sanitizeText(node.key);
case BlockType.Link:
return `<a href="${node.href}">${node.children}</a>`;
return `<a href="${encodeURIComponent(node.href)}">${node.children}</a>`;
case BlockType.Command:
return `/${node.command}`;
return `/${sanitizeText(node.command)}`;
default:
return children;
}
};

const HTML_TAG_REG = /<([a-z]+)(?![^>]*\/>)[^<]*<\/\1>/;
const HTML_TAG_REG = /<([\w-]+)(?:[^/>]*)(?:(?:\/>)|(?:>.*?<\/\1>))/;
const ignoreHTMLParseInlineMD = (text: string): string => {
if (text === '') return text;
const match = text.match(HTML_TAG_REG);
Expand Down

0 comments on commit a2cbe79

Please sign in to comment.