Skip to content

Commit

Permalink
swapRefCommaWithCommaRef()
Browse files Browse the repository at this point in the history
  • Loading branch information
NovemLinguae committed Oct 30, 2023
1 parent a7b546c commit 365f129
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
11 changes: 9 additions & 2 deletions DraftCleaner/modules/DraftCleaner.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ export class DraftCleaner {
wikicode = this.deleteSpacesInFrontOfRefs(wikicode);
wikicode = this.deleteNewLinesBetweenRefs(wikicode);
wikicode = this.swapRefPeriodWithPeriodRef(wikicode);

wikicode = this.swapRefCommaWithCommaRef(wikicode);

// stuff we want to run at the end
wikicode = this.fixDoublePeriod(wikicode); // need test cases. I've seen this one not work.
wikicode = this.boldArticleTitle(wikicode, titleWithNamespaceAndSpaces);
Expand Down Expand Up @@ -214,12 +215,18 @@ export class DraftCleaner {
return wikicode.replace(/^== ?Reference ?==$/gmi, '== References ==');
}

// TOOL - swap ref period with period ref
// TOOL - swap ref period with period ref
swapRefPeriodWithPeriodRef(wikicode) {
wikicode = wikicode.replace(/((?:<ref[^>]*?>[^>]*?<\/ref>){1,})\. /gm, '.$1 ');
wikicode = wikicode.replace(/((?:<ref[^>]*?>[^>]*?<\/ref>){1,})\.\n/gm, ".$1\n");
return wikicode;
}

swapRefCommaWithCommaRef(wikicode) {
wikicode = wikicode.replace(/((?:<ref[^>]*?>[^>]*?<\/ref>){1,})\, /gm, ',$1 ');
wikicode = wikicode.replace(/((?:<ref[^>]*?>[^>]*?<\/ref>){1,})\,\n/gm, ",$1\n");
return wikicode;
}

// fix errant spaces at beginning of lines, which makes a blockquote looking thing (AFCH does it)
trimEveryLine(wikicode) {
Expand Down
21 changes: 21 additions & 0 deletions DraftCleaner/tests/DraftCleaner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,27 @@ describe(`swapRefPeriodWithPeriodRef(wikicode2)`, () => {
});
});


describe(`swapRefCommaWithCommaRef(wikicode2)`, () => {
test(`Single`, () => {
let wikicode2 = `[[WMO]]<ref>{{Cite web |date=2018-06-06 |title=Public-Private Engagement (PPE) |url=https://public.wmo.int/en/our-mandate/how-we-do-it/public-private-engagement-ppe |access-date=2022-03-29 |website=public.wmo.int |language=en}}</ref>,\n`;
let output = '[[WMO]],<ref>{{Cite web |date=2018-06-06 |title=Public-Private Engagement (PPE) |url=https://public.wmo.int/en/our-mandate/how-we-do-it/public-private-engagement-ppe |access-date=2022-03-29 |website=public.wmo.int |language=en}}</ref>\n';
expect(dc.swapRefCommaWithCommaRef(wikicode2)).toBe(output);
});

test(`Double`, () => {
let wikicode2 = `[[WMO]]<ref>Test</ref><ref>Test2</ref>,\n`;
let output = '[[WMO]],<ref>Test</ref><ref>Test2</ref>\n';
expect(dc.swapRefCommaWithCommaRef(wikicode2)).toBe(output);
});

test.skip(`<ref name="test" /> style refs`, () => {
let wikicode2 = `[[WMO]]<ref name=":0" /><ref>{{Cite web |date=2018-06-06 |title=Public-Private Engagement (PPE) |url=https://public.wmo.int/en/our-mandate/how-we-do-it/public-private-engagement-ppe |access-date=2022-03-29 |website=public.wmo.int |language=en}}</ref>,\n`;
let output = '[[WMO]],<ref name=":0" /><ref>{{Cite web |date=2018-06-06 |title=Public-Private Engagement (PPE) |url=https://public.wmo.int/en/our-mandate/how-we-do-it/public-private-engagement-ppe |access-date=2022-03-29 |website=public.wmo.int |language=en}}</ref>\n';
expect(dc.swapRefCommaWithCommaRef(wikicode2)).toBe(output);
});
});

describe(`removeBorderFromImagesInInfoboxes(wikicode2)`, () => {
test(`Don't change`, () => {
let wikicode2 =
Expand Down

0 comments on commit 365f129

Please sign in to comment.