editor: cleanup nn:// links when pasted

Ensure that we remove any styles added to deep links. This is done especially for iOS where pasted link html get's wrapped into custom div with some hard coded styles making the link not match style with the rest of content.
This commit is contained in:
Ammar Ahmed
2026-06-25 09:45:50 +05:00
committed by Abdullah Atta
parent aca36b60b7
commit d376e00a1e

View File

@@ -44,6 +44,7 @@ export class ClipboardDOMParser extends ProsemirrorDOMParser {
convertBrToSingleSpacedParagraphs(dom);
removeRestrictedFeatures(dom);
removeBlockId(dom);
cleanupPastedNNLinkHtml(dom);
}
return super.parseSlice(dom, options);
}
@@ -55,6 +56,7 @@ export class ClipboardDOMParser extends ProsemirrorDOMParser {
convertBrToSingleSpacedParagraphs(dom);
removeRestrictedFeatures(dom);
removeBlockId(dom);
cleanupPastedNNLinkHtml(dom);
}
return super.parse(dom, options);
}
@@ -66,6 +68,15 @@ export function removeBlockId(dom: HTMLElement | Document) {
}
}
export function cleanupPastedNNLinkHtml(dom: HTMLElement | Document) {
const isNNLink = dom.querySelectorAll(`[href^="nn://"]`).length === 1;
if (isNNLink) {
for (const element of dom.querySelectorAll("[style]")) {
element.removeAttribute("style");
}
}
}
export function formatCodeblocks(dom: HTMLElement | Document) {
for (const pre of dom.querySelectorAll("pre")) {
pre.innerHTML = pre.innerHTML?.replaceAll(/<br.*?>/g, "\n");