mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-07-09 11:59:24 +02:00
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:
committed by
Abdullah Atta
parent
aca36b60b7
commit
d376e00a1e
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user