User:Novem Linguae/Scripts/DraftCleaner.js: Difference between revisions

Content deleted Content added
don't disable certain categories (publish.php)
fixPipedWikilinksWithIdenticalParameters() (publish.php)
Line 222:
wikicode = this.deleteBlankLinesBetweenBullets(wikicode);
wikicode = this.removeUnderscoresFromWikilinks(wikicode);
wikicode = this.fixPipedWikilinksWithIdenticalParameters(wikicode);
wikicode = this.removeBorderFromImagesInInfoboxes(wikicode);
wikicode = this.removeExtraAFCSubmissionTemplates(wikicode);
Line 259 ⟶ 260:
wikicode = this.deleteMoreThanTwoEntersInARow(wikicode);
return wikicode;
}
 
_escapeRegEx(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}
 
Line 707 ⟶ 704:
let sf = new StringFilter();
wikicode = sf.surgicalReplaceInsideTags(/_/g, ' ', wikicode, ['[['], [']]']);
return wikicode;
}
 
fixPipedWikilinksWithIdenticalParameters(wikicode) {
let matches = wikicode.matchAll(/\[\[([^|\]]+)\|([^\]]+)\]\]/g);
for ( let match of matches ) {
if ( match[1] === match[2] ) {
wikicode = this._replaceAll(wikicode, `[[${match[1]}|${match[1]}]]`, `[[${match[1]}]]`);
}
}
return wikicode;
}
Line 754 ⟶ 761:
_toSentenceCase(string) {
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
}
 
_replaceAll(haystack, needle, replacement) {
let regex = new RegExp(this._escapeRegEx(needle), 'g');
haystack = haystack.replace(regex, replacement);
return haystack;
}
 
_escapeRegEx(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}
}