Content deleted Content added
pass more unit tests (publish.php) |
pass more unit tests (publish.php) |
||
Line 271:
// convert inline external links to references
inlineExternalLinksToRefs(wikicode) {
let
let regExString = '== ?(?:';
for ( let sectionToSkip of sectionsToSkip ) {
regExString += sectionToSkip + '|';
}▼
regExString = regExString.slice(0, -1) + ')';
let hasSectionToSkip = wikicode.match(new RegExp(regExString, 'i'));
let sf = new StringFilter();
let regExToSplitArticle = new RegExp('((' + regExString + ').*$)', 'is');
let topHalf = wikicode.replace(
let bottomHalf = wikicode.match(
let buffer = sf.surgicalReplaceOutsideTags(/(?<!>|> )\[(http[^ \]]+) ?(.*?)\](?!<\/ref>| <\/ref>)/gm, '$2<ref>$1</ref>', topHalf, ['<ref', '{{'], ['</ref>', '/>', '}}']);
wikicode = buffer + bottomHalf;
} else {
wikicode = sf.surgicalReplaceOutsideTags(/(?<!>|> )\[(http[^ \]]+) ?(.*?)\](?!<\/ref>| <\/ref>)/gm, '$2<ref>$1</ref>', wikicode, ['<ref', '{{'], ['</ref>', '/>', '}}']);
}
return wikicode;
Line 324 ⟶ 328:
// WARNING: this is buggy sometimes
boldArticleTitle(wikicode, titleWithNamespaceAndSpaces) {
let titleToLookFor = titleWithNamespaceAndSpaces;
▲ if ( ! boldInArticle ) {
▲ titleToLookFor = titleToLookFor.replace(/ \(.*?\)$/, '');
▲ // Be pretty strict, to avoid adding ''' to image paths and infoboxes, which messes up the image.
▲ wikicode = wikicode.replace(regEx, "$1'''$2'''$3");
▲ }
return wikicode;
}
Line 340 ⟶ 341:
// Careful of this string in URLs.
capitalizeCOVID19(wikicode) {
let sf = new StringFilter();
wikicode =
wikicode = sf.surgicalReplaceOutsideTags(/\ncovid-19/gmi, "\nCOVID-19", wikicode, ['{{', '[['], ['}}', ']]']);
return wikicode;
}
Line 421 ⟶ 423:
// convert smart quotes to regular quotes
convertSmartQuotesToRegularQuotes(wikicode) {
let sf = new StringFilter();
wikicode =
wikicode =
wikicode =
wikicode =
wikicode = sf.surgicalReplaceOutsideTags(/…/g, '...', wikicode, ['[[File:'], [']]']);
return wikicode;
}
Line 502 ⟶ 505:
for ( let line of lines ) {
i++;
// scan for first heading.
// empty lines, lines with templates, or lines with images do not count. if ( line.startsWith('{') || line.length === 0 || line.startsWith('[[File:') ) {
output += line;
Line 657 ⟶ 661:
deleteEmptySections(wikicode) {
return wikicode.replace(/\n*== ?(?:See also|External links) ?==\n*$/, '');
}
|