Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

core: fix orphan search highlight closing tags in saved notes (#10516)

Abdullah Atta4c395a6de934
diff --git a/packages/core/src/content-types/__tests__/tiptap.test.js b/packages/core/src/content-types/__tests__/tiptap.test.js
index 19ab83a0c..2b6923f18 100644
--- a/packages/core/src/content-types/__tests__/tiptap.test.js
+++ b/packages/core/src/content-types/__tests__/tiptap.test.js
@@ -57,6 +57,14 @@ test("remove attachments with particular hash", async () => {
expect(result).not.toContain(`d3eab72e94e3cd35`);
});
+test("search result tags are removed along with their closing tags", async () => {
+ const tiptap = new Tiptap(
+ `<p>hello <nn-search-result>wor</nn-search-result>ld</p><p><nn-search-result><b>bold</b></nn-search-result></p>`
+ );
+ const result = await tiptap.postProcess(async () => undefined);
+ expect(result.data).toBe(`<p>hello world</p><p><b>bold</b></p>`);
+});
+
const HTMLS = {
tables: `<table style="border-collapse: collapse; width: 811px;" border="1"><tbody><tr><td style="width: 81.375px;">Goal</td><td style="width: 708.625px;">To introduce various features of the app to the user and to convert a user on trial or basic plan to upgrade.</td></tr><tr><td style="width: 81.375px;">Frequency</td><td style="width: 708.625px;">1/week or 2/week</td></tr><tr><td style="width: 81.375px;">Types</td><td style="width: 708.625px;">Feature intro, upgrade promo, one time emails</td></tr><tr><td style="width: 81.375px;"></td><td style="width: 708.625px;"></td></tr></tbody></table><h2>Emails</h2><h3>Feature intro</h3><p>Features:</p><ol style="list-style-type: decimal;"><li>Web clipper on mobile</li><li>Pin any note to notification</li><li>Take notes from notifications</li><li>App lock</li><li>Importer</li><li>Encrypted attachments</li><li>Session history &amp; automatic backups</li><li>Note publishing</li><li>Note exports</li><li>Collapsible headers</li></ol><h3>Promos</h3><ol style="list-style-type: decimal;"><li>Trial about to end</li><li>Trial ending (with option to request an extension)</li><li>Try free for 14 days</li></ol><h3>One time</h3><ol style="list-style-type: decimal;"><li>End-of-month progress report</li><li>What's coming/roadmap</li><li>What we are working on</li><li>Join the community</li></ol>`,
tables2: `<h1>Note 8/6/22, 10:48 AM</h1>
diff --git a/packages/core/src/utils/html-rewriter.ts b/packages/core/src/utils/html-rewriter.ts
index d65c42077..cfea11976 100644
--- a/packages/core/src/utils/html-rewriter.ts
+++ b/packages/core/src/utils/html-rewriter.ts
@@ -34,6 +34,7 @@ export class HTMLRewriter {
private transformed = "";
private currentTag: string | null = null;
private ignoreIndex: number | null = null;
+ private skippedTags: boolean[] = [];
private parser: Parser;
constructor(
@@ -50,6 +51,7 @@ export class HTMLRewriter {
{
onreset: () => {
this.transformed = "";
+ this.skippedTags = [];
},
oncomment: () => this.write("<!--"),
oncommentend: () => this.write("-->"),
@@ -70,13 +72,16 @@ export class HTMLRewriter {
if (result === false) {
this.ignoreIndex = 0;
return;
- } else if (result === null) return;
- else if (result) {
+ } else if (result === null) {
+ this.skippedTags.push(true);
+ return;
+ } else if (result) {
name = result.name;
attr = result.attr;
}
}
+ this.skippedTags.push(false);
this.write(`<${name}`);
if (attr) {
for (const key in attr) {
@@ -97,6 +102,8 @@ export class HTMLRewriter {
return;
}
+ if (this.skippedTags.pop()) return;
+
if (!isImplied) this.closeTag();
this.write(isImplied ? "/>" : `</${name}>`);