Skip to content

Commit 6fef2a3

Browse files
author
Al Manning
committed
guard against multiple transforms
1 parent 6ae9e83 commit 6fef2a3

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/publish/confluence/confluence-helper.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,13 @@ export const findAttachments = (
749749
export const footnoteTransform = (bodyValue: string): string => {
750750
const BACK_ANCHOR_FINDER: RegExp = /<a href="#fn(\d)"/g;
751751
const ANCHOR_FINDER: RegExp = /<a href="#fnref(\d)"/g;
752+
const CONFLUENCE_ANCHOR_FINDER: RegExp =
753+
/ac:macro-id="d2cb5be1217ae6e086bc60005e9d27b7"><ac:parameter ac:name="">fn/g;
754+
755+
if (bodyValue.search(CONFLUENCE_ANCHOR_FINDER) !== -1) {
756+
//the footnote transform has already happened
757+
return bodyValue;
758+
}
752759

753760
const buildConfluenceAnchor = (id: string) =>
754761
`<ac:structured-macro ac:name="anchor" ac:schema-version="1" ac:local-id="a6aa6f25-0bee-4a7f-929b-71fcb7eba592" ac:macro-id="d2cb5be1217ae6e086bc60005e9d27b7"><ac:parameter ac:name="">${id}</ac:parameter></ac:structured-macro>`;

tests/unit/confluence.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4171,6 +4171,19 @@ const runFootnoteTransform = () => {
41714171
assertEquals(expected, footnoteTransform(value));
41724172
});
41734173

4174+
otest(suiteLabel("ignore_existing"), async () => {
4175+
const value =
4176+
'<ac:structured-macro ac:name="anchor" ac:schema-version="1" ac:local-id="a6aa6f25-0bee-4a7f-929b-71fcb7eba592" ac:macro-id="d2cb5be1217ae6e086bc60005e9d27b7"><ac:parameter ac:name="">fnref1</ac:parameter></ac:structured-macro><a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a></p>' +
4177+
'<section id="footnotes" class="footnotes footnotes-end-of-document" role="doc-endnotes">' +
4178+
"<hr />" +
4179+
"<ol>" +
4180+
'<li id="fn1"><p>Here is the footnote.<ac:structured-macro ac:name="anchor" ac:schema-version="1" ac:local-id="a6aa6f25-0bee-4a7f-929b-71fcb7eba592" ac:macro-id="d2cb5be1217ae6e086bc60005e9d27b7"><ac:parameter ac:name="">fn1</ac:parameter></ac:structured-macro><a href="#fnref1" class="footnote-back" role="doc-backlink">↩︎</a></p></li>' +
4181+
"</ol>" +
4182+
"</section>";
4183+
const actual = footnoteTransform(value);
4184+
assertEquals(value, footnoteTransform(value));
4185+
});
4186+
41744187
test(suiteLabel("one_note_forward_back"), async () => {
41754188
const value =
41764189
'<a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a></p>\n' +

0 commit comments

Comments
 (0)