diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml index 6915d35..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: loopwerk/tag-changelog@v1 + 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 19fc525..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: loopwerk/tag-changelog@v1 + uses: dragonish/tag-changelog@v1 with: token: ${{ secrets.GITHUB_TOKEN }} config_file: .github/scripts/tag-changelog-config.cjs 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/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)); } 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 () {