From ef26e6eec96796f33ef417314565f87983a13f3e Mon Sep 17 00:00:00 2001 From: dragonish Date: Fri, 18 Apr 2025 13:33:03 +0800 Subject: [PATCH 1/6] perf(dom): reduce unnecessary conversions --- common/dom.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/dom.ts b/common/dom.ts index 0737728..2142a69 100644 --- a/common/dom.ts +++ b/common/dom.ts @@ -176,10 +176,10 @@ export function decorateOutlineElement( /** * Compare heading text. * - * @param l The left heading text. - * @param r The right heading text. + * @param source The source heading text. + * @param outline The outline heading text. * @returns true if the two headings are equal, false otherwise. */ -export function compareHeadingText(l: string, r: string): boolean { - return compareMarkdownText(htmlToMarkdown(l), htmlToMarkdown(r)); +export function compareHeadingText(source: string, outline: string): boolean { + return compareMarkdownText(htmlToMarkdown(source), outline); } From 58e05c4bfb7ea31aaa8c9f1ea14c417f381a9843 Mon Sep 17 00:00:00 2001 From: dragonish Date: Fri, 18 Apr 2025 13:36:05 +0800 Subject: [PATCH 2/6] fix(outline): fix exceptions when the heading contains links Fixed: #9 --- common/data.ts | 40 ++++++++++++++++++++++++++++++++-------- test/common/data.spec.ts | 24 +++++++++++++++--------- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/common/data.ts b/common/data.ts index e575468..bf5522b 100644 --- a/common/data.ts +++ b/common/data.ts @@ -220,17 +220,41 @@ export function diffLevel(current: number, last: number): boolean { /** * Compare Markdown text. * - * @param l left Markdown text. - * @param r right Markdown text. + * @param source The source heading text. + * @param outline The outline heading text. * @returns boolean. if left Markdown text is equal to right Markdown text, return true. otherwise, return false. */ -export function compareMarkdownText(l: string, r: string): boolean { - if (l === r) { - return true; - } else if ( - l.replaceAll(/[`=_~*\\\s]/g, "") === r.replaceAll(/[`=_~*\\\s]/g, "") - ) { +export function compareMarkdownText(source: string, outline: string): boolean { + if (source === outline) { return true; + } else { + source = source.replaceAll(/\[(.+)\]\(.*\)/g, "$1"); + + if (source === outline) { + return true; + } + + source = source.replaceAll(/\[\[.+\|(.+)\]\]/g, "$1"); + if (source === outline) { + return true; + } + + source = source.replaceAll(/\[\[(.+)#(.+)\]\]/g, "$1 > $2"); + if (source === outline) { + return true; + } + + source = source.replaceAll(/\[\[#?(.+)\]\]/g, "$1"); + if (source === outline) { + return true; + } + + if ( + source.replaceAll(/[`=_~*\\\s]/g, "") === + outline.replaceAll(/[`=_~*\\\s]/g, "") + ) { + return true; + } } return false; diff --git a/test/common/data.spec.ts b/test/common/data.spec.ts index 0be154c..b524ae4 100644 --- a/test/common/data.spec.ts +++ b/test/common/data.spec.ts @@ -28,16 +28,22 @@ describe("common/data", function () { expect(compareMarkdownText("", "")).to.be.true; expect(compareMarkdownText("h1", "h1")).to.be.true; expect(compareMarkdownText("h1", "h2")).to.be.false; - expect(compareMarkdownText("h1", "`h1`")).to.be.true; - expect(compareMarkdownText("h1 h2", "`h1` h2")).to.be.true; - expect(compareMarkdownText("h1 `", "h1 `` ` ``")).to.be.true; - expect(compareMarkdownText("h1", "*h1*")).to.be.true; - expect(compareMarkdownText("h1", "**h1**")).to.be.true; - expect(compareMarkdownText("h1", "_h1_")).to.be.true; - expect(compareMarkdownText("h1", "__h1__")).to.be.true; - expect(compareMarkdownText("h1", "==h1==")).to.be.true; - expect(compareMarkdownText("h1", "~~h1~~")).to.be.true; + expect(compareMarkdownText("`h1`", "h1")).to.be.true; + expect(compareMarkdownText("`h1` h2", "h1 h2")).to.be.true; + expect(compareMarkdownText("h1 `` ` ``", "h1 `")).to.be.true; + expect(compareMarkdownText("*h1*", "h1")).to.be.true; + expect(compareMarkdownText("**h1**", "h1")).to.be.true; + expect(compareMarkdownText("_h1_", "h1")).to.be.true; + expect(compareMarkdownText("__h1__", "h1")).to.be.true; + expect(compareMarkdownText("==h1==", "h1")).to.be.true; + expect(compareMarkdownText("~~h1~~", "h1")).to.be.true; expect(compareMarkdownText("h1 \\", "h1 ")).to.be.true; + expect(compareMarkdownText("[h1](/h1)", "h1")).to.be.true; + expect(compareMarkdownText("[h1](/h1) content", "h1 content")).to.be.true; + expect(compareMarkdownText("[[h1]]", "h1")).to.be.true; + expect(compareMarkdownText("[[h2|h1]]", "h1")).to.be.true; + expect(compareMarkdownText("[[h1#h2]]", "h1 > h2")).to.be.true; + expect(compareMarkdownText("[[#h2]]", "h2")).to.be.true; }); it("getBoolean", function () { From f5ee7f1bc36e2b0688c83918e9821de10a97aa04 Mon Sep 17 00:00:00 2001 From: dragonish Date: Fri, 18 Apr 2025 13:45:25 +0800 Subject: [PATCH 3/6] revert: "perf(dom): reduce unnecessary conversions" This reverts commit ef26e6eec96796f33ef417314565f87983a13f3e. --- common/dom.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/dom.ts b/common/dom.ts index 2142a69..0737728 100644 --- a/common/dom.ts +++ b/common/dom.ts @@ -176,10 +176,10 @@ export function decorateOutlineElement( /** * Compare heading text. * - * @param source The source heading text. - * @param outline The outline heading text. + * @param l The left heading text. + * @param r The right heading text. * @returns true if the two headings are equal, false otherwise. */ -export function compareHeadingText(source: string, outline: string): boolean { - return compareMarkdownText(htmlToMarkdown(source), outline); +export function compareHeadingText(l: string, r: string): boolean { + return compareMarkdownText(htmlToMarkdown(l), htmlToMarkdown(r)); } From 63395f12bfb41f664315a06a26a4ce06df3bd1f6 Mon Sep 17 00:00:00 2001 From: dragonish Date: Fri, 18 Apr 2025 13:51:34 +0800 Subject: [PATCH 4/6] refactor(dom): change variable name Refs: 58e05c4bfb7ea31aaa8c9f1ea14c417f381a9843 --- common/dom.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/dom.ts b/common/dom.ts index 0737728..ae4c6a6 100644 --- a/common/dom.ts +++ b/common/dom.ts @@ -176,10 +176,10 @@ export function decorateOutlineElement( /** * Compare heading text. * - * @param l The left heading text. - * @param r The right heading text. + * @param source The source heading text. + * @param outline The outline heading text. * @returns true if the two headings are equal, false otherwise. */ -export function compareHeadingText(l: string, r: string): boolean { - return compareMarkdownText(htmlToMarkdown(l), htmlToMarkdown(r)); +export function compareHeadingText(source: string, outline: string): boolean { + return compareMarkdownText(htmlToMarkdown(source), htmlToMarkdown(outline)); } From 7a85faaf93bea2c520e146af7ac39ca621db1986 Mon Sep 17 00:00:00 2001 From: dragonish Date: Fri, 18 Apr 2025 20:53:36 +0800 Subject: [PATCH 5/6] ci(changelog): change the action --- .gitea/workflows/release.yaml | 2 +- .github/workflows/release.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml index 6915d35..ccbc2e4 100644 --- a/.gitea/workflows/release.yaml +++ b/.gitea/workflows/release.yaml @@ -46,7 +46,7 @@ jobs: zip "./release/${plugin_name}_v${{ steps.git_tags.outputs.current }}.zip" "main.js" "styles.css" "manifest.json" - name: Create changelog text id: changelog_text - uses: loopwerk/tag-changelog@v1 + uses: dragonish/tag-changelog@1618165956d646a3381e914cd4441b227c3ba6d4 with: token: ${{ secrets.ACCESS_TOKEN }} config_file: ../.gitea/scripts/tag-changelog-config.cjs diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 19fc525..5f50640 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -29,7 +29,7 @@ jobs: pnpm run build - name: Create changelog text id: changelog_text - uses: loopwerk/tag-changelog@v1 + uses: dragonish/tag-changelog@1618165956d646a3381e914cd4441b227c3ba6d4 with: token: ${{ secrets.GITHUB_TOKEN }} config_file: .github/scripts/tag-changelog-config.cjs From f88c7e07a4aed320bddbb6c8b077e10038f43350 Mon Sep 17 00:00:00 2001 From: dragonish Date: Fri, 18 Apr 2025 21:05:32 +0800 Subject: [PATCH 6/6] ci(changelog): change the action --- .gitea/workflows/release.yaml | 2 +- .github/workflows/release.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml index ccbc2e4..5f80fef 100644 --- a/.gitea/workflows/release.yaml +++ b/.gitea/workflows/release.yaml @@ -46,7 +46,7 @@ jobs: zip "./release/${plugin_name}_v${{ steps.git_tags.outputs.current }}.zip" "main.js" "styles.css" "manifest.json" - name: Create changelog text id: changelog_text - uses: dragonish/tag-changelog@1618165956d646a3381e914cd4441b227c3ba6d4 + uses: dragonish/tag-changelog@v1 with: token: ${{ secrets.ACCESS_TOKEN }} config_file: ../.gitea/scripts/tag-changelog-config.cjs diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 5f50640..1324f8d 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -29,7 +29,7 @@ jobs: pnpm run build - name: Create changelog text id: changelog_text - uses: dragonish/tag-changelog@1618165956d646a3381e914cd4441b227c3ba6d4 + uses: dragonish/tag-changelog@v1 with: token: ${{ secrets.GITHUB_TOKEN }} config_file: .github/scripts/tag-changelog-config.cjs