Content deleted Content added
detect and remove {{Draft topics}} (publish.php) |
fix linter errors (publish.php) |
||
Line 159:
class DraftCleaner {
cleanDraft( wikicode, namespaceNumber, titleWithNamespaceAndSpaces ) {
// run before other stuff
wikicode = this.deleteSomeHTMLTags( wikicode );
wikicode = this.deleteNonAFCDraftTags( wikicode );
wikicode = this.deleteAFCDraftTagsIfMainspace( wikicode, mw.config.get( 'wgNamespaceNumber' ) );
wikicode = this.fixWikilinksContainingURL( wikicode );
wikicode = this.fixExternalLinksToWikipediaArticles( wikicode );
wikicode = this.deleteWeirdUnicodeCharacters( wikicode );
wikicode = this.trimEveryLine( wikicode );
wikicode = this.convertH1ToH2( wikicode );
wikicode = this.convertVeryLongHeadingToParagraph( wikicode );
wikicode = this.deleteHeadingsWithTitle( wikicode, titleWithNamespaceAndSpaces );
wikicode = this.unlinkWikilinksToThisTitle( wikicode, titleWithNamespaceAndSpaces );
wikicode = this.capitalizeCOVID19( wikicode );
wikicode = this.removeBoldFromHeadings( wikicode );
wikicode = this.convertReferenceToReferences( wikicode );
wikicode = this.deleteMultipleReferenceTags( wikicode );
wikicode = this.addReferencesSectionIfMissing( wikicode );
wikicode = this.fixEmptyReferencesSection( wikicode );
wikicode = this.deleteWhitespaceAtEndOfLines( wikicode );
wikicode = this.convertSmartQuotesToRegularQuotes( wikicode );
// wikicode = this.fixWordEmphasizedWithSingleQuotes(wikicode); // most of these appear in citations as names of newspaper articles, arguably should keep these single quotes
wikicode = this.convertDoubleSpacesToSingleSpaces( wikicode );
wikicode = this.deleteBlankHeadings( wikicode );
wikicode = this.changeYearRangeDashToNDash( wikicode );
wikicode = this.disableCategoriesInDraftspace( wikicode, namespaceNumber );
// wikicode = this.deleteBRTagsOutsideInfoboxes(wikicode, namespaceNumber); // edge case in image captions, and probably other places
// wikicode = this.rightAlignImages(wikicode); // commenting out, too many false positives in featured articles
wikicode = this.correctCapitalizationOfEndMatterHeaders( wikicode );
wikicode = this.ifNoLeadSectionDeleteFirstHeading( wikicode );
wikicode = this.deleteCopyPastedEditAndEditSource( wikicode );
wikicode = this.replaceUnicodeBulletsWithAsterisks( wikicode );
wikicode = this.deleteEmptySections( wikicode );
wikicode = this.fixHeadingsInAllCaps( wikicode );
wikicode = this.deleteDuplicateReferencesSection( wikicode );
wikicode = this.deleteBlankLinesBetweenBullets( wikicode );
wikicode = this.removeUnderscoresFromWikilinks( wikicode );
wikicode = this.fixPipedWikilinksWithIdenticalParameters( wikicode );
wikicode = this.removeBorderFromImagesInInfoboxes( wikicode );
wikicode = this.removeExtraAFCSubmissionTemplates( wikicode );
wikicode = this.moveAFCSubmissionTemplatesToTop( wikicode );
// all ==sections== should start with a capital letter
Line 222:
// convert refs toward the end. we want deleteSomeHTMLTags() to run first, to get rid of tags around URLs
wikicode = this.bareURLToRef( wikicode );
wikicode = this.refShortLinkToLongLink( wikicode );
wikicode = this.inlineExternalLinksToRefs( wikicode );
wikicode = this.moveRefsOutsideOfItalics( wikicode );
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 );
wikicode = this.trimEmptyLines( wikicode );
wikicode = this.deleteMoreThanTwoEntersInARow( wikicode );
return wikicode;
}
Line 241:
// surround bare URL's with <ref></ref>
// Useful for seeing all URL's in the reflist section, and for CiteHighlighter ref quality highlighting
bareURLToRef( wikicode ) {
return wikicode.replace( /^(http[^\n ]*) {0,}$/gm,
}
// in refs, turn [short links] into long links, so you can see the ___domain
// also fixes <ref> link </ref> issues with extra spaces in the ref
refShortLinkToLongLink( wikicode ) {
// <ref>[https://test.com''Test'']</ref>
wikicode = wikicode.replace( /(<ref[^>]*>) {0,}\[ {0,}([^'\]]*)(''[^\]]*)\] {0,}(<\/ref>)/gm, '$1$2 $3$4' );
// <ref>[https://test.com Test]</ref>
wikicode = wikicode.replace( /(<ref[^>]*>) {0,}\[ {0,}([^\]]*) {0,}\] {0,}(<\/ref>)/gm, '$1$2$3' );
return wikicode;
}
// convert inline external links to references
inlineExternalLinksToRefs( wikicode ) {
let regExString = '== ?(?:';
for (
regExString += sectionToSkip + '|';
}
regExString = regExString.slice( 0, -1 ) + ')';
if ( hasSectionToSkip ) {
/(?<!>|> )\[(http[^ \]]+) ?(.*?)\](?!<\/ref>| <\/ref>)/gm,
'$2<ref>$1</ref>',
topHalf,
[ '<ref', '{{' ],
[ '
'/>',▼
);
wikicode = buffer + bottomHalf;
Line 287 ⟶ 284:
'$2<ref>$1</ref>',
wikicode,
[ '<ref', '{{' ],
[ '</ref>', '/>', '}}' ]
);
}
return wikicode;
}
Line 298 ⟶ 295:
* ''Test<ref></ref>'' => ''Test''<ref></ref>
*/
moveRefsOutsideOfItalics( wikicode ) {
wikicode = wikicode.replace( /''([^']+)(<ref>[^<]+<\/ref>)''/gm,
return wikicode;
}
// get rid of spaces in front of <refs>
deleteSpacesInFrontOfRefs( wikicode ) {
return wikicode.replace( /(?<!(?:\||=)) {1,}<ref/gm,
}
// get rid of any level 2 heading that contains the article's title
// this takes care of 2 common cases: heading at the bottom next to the {{AFC Submission}} template, and heading at the top above the lead
deleteHeadingsWithTitle( wikicode, titleWithNamespaceAndSpaces ) {
let headingNameToLookFor = titleWithNamespaceAndSpaces;
headingNameToLookFor = headingNameToLookFor.replace( /^Draft:/, '' );
headingNameToLookFor = this._escapeRegEx( headingNameToLookFor );
let regEx = new RegExp(
wikicode = wikicode.replace( regEx,
// now look for titles that contain Draft: at the beginning, too
headingNameToLookFor = titleWithNamespaceAndSpaces;
headingNameToLookFor = this._escapeRegEx( headingNameToLookFor );
regEx = new RegExp(
wikicode = wikicode.replace( regEx,
return wikicode;
}
// remove wikilinks to article name
// Example: if title is Draft:Menna Shahin, change [[Menna Shahin]] to Menna Shahin
unlinkWikilinksToThisTitle( wikicode, titleWithNamespaceAndSpaces ) {
let wikilinkToLookFor = titleWithNamespaceAndSpaces;
wikilinkToLookFor = wikilinkToLookFor.replace( /^Draft:/, '' );
wikilinkToLookFor = this._escapeRegEx( wikilinkToLookFor );
wikicode = wikicode.replace( regEx,
return wikicode;
}
// if located in the first paragraph, bold the article title
boldArticleTitle( wikicode, titleWithNamespaceAndSpaces ) {
let titleToLookFor = titleWithNamespaceAndSpaces;
titleToLookFor = titleToLookFor.replace( /^Draft:/, '' );
titleToLookFor = titleToLookFor.replace( / \(.*?\)$/, '' );
titleToLookFor = this._escapeRegEx( titleToLookFor );
// Don't bold the title if it's already bolded. Fixes a "bold twice" bug.
if ( hasBoldedTitle ) {
return wikicode; ▲ }
// Be pretty strict, to avoid adding ''' to image paths and infoboxes, which messes up the image. Also, only replace first match.
wikicode = wikicode.replace( regEx, "$1'''$2'''$3" );
return wikicode;
}
// /covid-19/i -> COVID-19
// Careful of this string in URLs.
capitalizeCOVID19( wikicode ) {
wikicode = sf.surgicalReplaceOutsideTags( / covid-19/gmi, ' COVID-19', wikicode, [ '{{', '[[' ], [ '}}', ']]' ] );
wikicode = sf.surgicalReplaceOutsideTags( /\ncovid-19/gmi,
return wikicode;
}
// remove bold from headings
removeBoldFromHeadings( wikicode ) {
return wikicode.replace( /^(=.*)'''(.*)'''(.*=)$/gm, '$1$2$3' );
}
// remove enter characters between <ref>s
deleteNewLinesBetweenRefs( wikicode ) {
return wikicode.replace( /<\/ref>\n{1,}<ref>/gm, '<
}
// convert ==Reference== to ==References==
convertReferenceToReferences( wikicode ) {
return wikicode.replace( /^== ?Reference ?==$/gmi, '== References ==' );
}
// 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,
return wikicode;
}
swapRefCommaWithCommaRef( wikicode ) {
wikicode = wikicode.replace( /((?:<ref[^>]*?>[^>]*?<\/ref>){1,})
wikicode = wikicode.replace( /((?:<ref[^>]*?>[^>]*?<\/ref>){1,})
return wikicode;
}
// fix errant spaces at beginning of lines, which makes a blockquote looking thing (AFCH does it)
trimEveryLine( wikicode ) {
let output = '';
let i = 0;
for (
i++;
if ( trimmed.startsWith( '|' ) || trimmed.startsWith( '}' ) ) { // don't trim lines that start with | or }. It is common in FAs to indent these a bit.
output += line;
} else {
Line 402 ⟶ 401:
}
if ( i !== lineCount ) {
output +=
}
}
return output;
}
// add references section if missing
addReferencesSectionIfMissing( wikicode ) {
if ( !
if ( hasBottomAFCTemplate ) {
wikicode = wikicode.replace( /(\n{{AfC submission[^}]*}}\s*)$/,
} else {
wikicode = wikicode.replace( /$/,
}
}
return wikicode;
}
// fix empty references section
fixEmptyReferencesSection( wikicode ) {
if ( !
wikicode = wikicode.replace( /(?<=== ?References ?==)/gmi,
}
return wikicode;
}
// delete whitespace at the end of lines
// (?!\|)(?!\}\}) is to stop this from deleting spaces after = in infoboxes
deleteWhitespaceAtEndOfLines( wikicode ) {
return wikicode.replace( /[ \t]+\n(?!\|)(?!\}\})/g,
}
// convert smart quotes to regular quotes
convertSmartQuotesToRegularQuotes( wikicode ) {
wikicode = sf.surgicalReplaceOutsideTags( /”/g, '"', wikicode, [ '[[File:' ], [ ']]' ] );
wikicode = sf.surgicalReplaceOutsideTags( /“/g, '"', wikicode, [ '[[File:' ], [ ']]' ] );
wikicode = sf.surgicalReplaceOutsideTags( /‘/g, "'", wikicode, [ '[[File:' ], [ ']]' ] );
wikicode = sf.surgicalReplaceOutsideTags( /’/g, "'", wikicode, [ '[[File:' ], [ ']]' ] );
wikicode = sf.surgicalReplaceOutsideTags( /…/g, '...', wikicode, [ '[[File:' ], [ ']]' ] );
return wikicode;
}
// convert double spaces to single spaces
convertDoubleSpacesToSingleSpaces( wikicode ) {
return wikicode.replace( /\. {2,}/g, '. ' );
}
// remove blank heading
deleteBlankHeadings( wikicode ) {
return wikicode.replace( /\n={2,} {0,}={2,}\n/g,
}
// Change year range dash to ndash. Skip text inside of [[File:
changeYearRangeDashToNDash( wikicode ) {
// (1111-1111)
wikicode = sf.surgicalReplaceOutsideTags( /(\(\d{4}) ?- ?(\d{4}\))/gm, '$1–$2', wikicode, [ '[[File:' ], [ ']]' ] );
// 1839 - 1926)
wikicode = sf.surgicalReplaceOutsideTags( /( \d{4}) ?- ?(\d{4}\))/gm, '$1–$2', wikicode, [ '[[File:' ], [ ']]' ] );
return wikicode;
}
// if in draftspace, and draft has categories, disable the categories
disableCategoriesInDraftspace( wikicode, namespace ) {
if ( draft ) {
wikicode = wikicode.replace( /:?(\[\[)(Category:[^\]]*\]\])/gm, '$1:$2' );
}
wikicode = wikicode.replace( /\[\[:Category:Created via preloaddraft\]\]/gi, '[[Category:Created via preloaddraft]]' );
return wikicode;
}
// delete <br> in drafts, these are usually poorly placed
deleteBRTagsOutsideInfoboxes( wikicode ) {
let output = '';
let i = 0;
for (
i++;
// Skip lines that start with { or |. This is the easiest way to detect infoboxes
if ( line.startsWith( '{' ) || line.startsWith( '|' ) ) {
output += line;
} else {
output += line.replace( /
}
if ( i !== lineCount ) {
output +=
}
}
return output;
}
// right align images
rightAlignImages( wikicode ) {
return wikicode.replace( /(\[\[File:[^\]]*\|)left(\|[^\]]*\]\])/gm, '$1right$2' );
}
// correct capitalization of see also, references, further reading, external links
correctCapitalizationOfEndMatterHeaders( wikicode ) {
wikicode = wikicode.replace( /^(== ?)References( ?==)$/gmi,
wikicode = wikicode.replace( /^(== ?)External links( ?==)$/gmi,
wikicode = wikicode.replace( /^(== ?)Further reading( ?==)$/gmi,
wikicode = wikicode.replace( /^(== ?)See also( ?==)$/gmi,
return wikicode;
}
// if article has headings but no lead, remove first heading
ifNoLeadSectionDeleteFirstHeading( wikicode ) {
let output = '';
let i = 0;
let textCount = 0;
for (
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;
} else if ( line.startsWith( '==' ) && !
continue; // delete this line by not putting it in the output string
} else {
Line 535 ⟶ 534:
}
if ( i !== lineCount ) {
output +=
}
}
return output;
}
// delete [edit], [edit source], and [editar] from headings
deleteCopyPastedEditAndEditSource( wikicode ) {
wikicode = wikicode.replace( /\[edit\]( ?={2,})$/gm, '$1' );
wikicode = wikicode.replace( /\[edit source\]( ?={2,})$/gm, '$1' );
wikicode = wikicode.replace( /\[editar\]( ?={2,})$/gm, '$1' );
return wikicode;
}
// at beginning of lines, replace unicode bullets with asterisks
replaceUnicodeBulletsWithAsterisks( wikicode ) {
return wikicode.replace( /^\s{0,}[·•●]\s{0,}/gm, '* ' );
}
// remove whitespace if that is the only character on a line
trimEmptyLines( wikicode ) {
return wikicode.replace( /^\s*$/gm, '' );
}
// no more than 2 newlines (1 blank line) in a row. except stubs, which get 3 newlines (2 blank lines)
// Note: AFCH does this too
deleteMoreThanTwoEntersInARow( wikicode ) {
wikicode = wikicode.replace( /\n{3,}/gm,
wikicode = wikicode.replace( /\n{2}(\{\{[^}]*stub\}\})/gi, '\n\n\n$1' );
return wikicode;
}
// convert =TitleHeading= to ==H2Heading==
convertH1ToH2( wikicode ) {
return wikicode.replace( /^= ?([^=]*?) ?=$/gm, '== $1 ==' );
}
convertVeryLongHeadingToParagraph( wikicode ) {
let output = '';
let i = 0;
for (
i++;
if ( line.length > 150 && line.match( /^==.*==$/gm ) && !
output += line.replace( /^={1,}\s*(.*?)\s*={1,}$/m, '$1' );
} else {
output += line;
}
if ( i !== lineCount ) {
output +=
}
}
Line 591 ⟶ 590:
}
fixWordEmphasizedWithSingleQuotes( wikicode ) {
return wikicode.replace( / '(\w+)' /g, ' "$1" ' );
}
fixDoublePeriod( wikicode ) {
return wikicode.replace( /(?<=[A-Za-z\]])\.\.(?=<ref| |\n)/g, '.' );
}
fixWikilinksContainingURL( wikicode ) {
// non-piped wikilink
wikicode = wikicode.replace( /\[\[https?:\/\/en\.(?:m\.)?wikipedia\.org\/wiki\/([^|]*)\]\]/g, '[[$1]]' );
// piped wikilink
wikicode = wikicode.replace( /\[\[https?:\/\/en\.(?:m\.)?wikipedia\.org\/wiki\/([^|]*)\|([^\]]*)\]\]/g, '[[$1|$2]]' );
// non-piped external link
wikicode = wikicode.replace( /\[\[(http[^|]*)\]\]/g, '[$1]' );
// piped external link
wikicode = wikicode.replace( /\[\[(http[^|]*)\|([^\]]*)\]\]/g, '[$1 $2]' );
return wikicode;
}
fixExternalLinksToWikipediaArticles( wikicode ) {
// [https://en.wikipedia.org/wiki/Article] and [https://en.wikipedia.org/wiki/Article Article name]
return wikicode.replace( /(?<!\[)\[https?:\/\/en\.wikipedia\.org\/wiki\/([^ \]]*)( [^\]]*)?\]/gs, function ( match, p1 ) {
p1 = decodeURIComponent( p1 );
p1 = p1.replace( /_/g, ' ' );
return `[[${ p1 }]]`;
} );
}
deleteBlankLinesBetweenBullets( wikicode ) {
for ( let i = 0; i < length; i++ ) {
if (
typeof previous !== 'undefined' &&
typeof next !== 'undefined' &&
previous.startsWith( '*' ) &&
current === '' &&
next.startsWith( '*' )
) {
continue;
}
buffer.push( current );
}
return buffer.join( '\n' );
}
deleteWeirdUnicodeCharacters( wikicode ) {
return wikicode.replace( /[]/g, '' );
}
deleteSomeHTMLTags( wikicode ) {
wikicode = wikicode.replace( /<\/?p( [^>]*)?\/?>/g, '' );
wikicode = wikicode.replace( /<\/?strong( [^>]*)?\/?>/g, '' );
wikicode = wikicode.replace( /<\/?em( [^>]*)?\/?>/g, '' );
wikicode = wikicode.replace( /<\/?nowiki( [^>]*)?\/?>/g, '' );
wikicode = wikicode.replace( /<\/?u( [^>]*)?\/?>/g, '' );
wikicode = wikicode.replace( /(?:<big>|<\/big>)/g, '' );
return wikicode;
}
deleteNonAFCDraftTags( wikicode ) {
wikicode = wikicode.replace( /{{Preloaddraft submit}}\n{0,2}/gi, '' );
wikicode = wikicode.replace( /<!-- When you move this draft into article space, please link it to the Wikidata entry and remove the QID in the infobox code\. -->\n{0,2}/gi, '' );
wikicode = wikicode.replace( /{{Draft}}\n{0,2}/gi, '' );
return wikicode;
}
deleteAFCDraftTagsIfMainspace( wikicode, namespaceNumber ) {
if ( isMainspace ) {
// {{AfC submission}}, {{AfC topic}}, {{AfC comment}}, etc.
wikicode = wikicode.replace( /{{AfC [^}]*}}\n?/g, '' );
wikicode = wikicode.replace( /{{Draft topics[^}]*}}\n?/g, '' );
}
return wikicode;
}
fixHeadingsInAllCaps( wikicode ) {
// create a concatenated string with the text from every heading
let headingString = '';
for (
headingString += match[ 1 ];
}
// if string only contains caps
if ( this._isUpperCase( headingString ) ) {
// convert all headings to sentence case
for (
let matchRegex = this._escapeRegEx( match[ 1 ].trim() );
matchRegex = new RegExp( '== {0,}' + matchRegex + ' {0,}==', 'g' );
wikicode = wikicode.replace( matchRegex, '== ' + sentenceCase + ' ==' );
}
}
Line 696 ⟶ 695:
}
deleteEmptySections( wikicode ) {
return wikicode.replace( /\n*== ?(?:See also|External links) ?==\n*$/, '' );
}
deleteDuplicateReferencesSection( wikicode ) {
if ( matches !== null && matches.length > 1 ) {
// run regexes that are likely to delete the extra section
`== References ==
<!-- Inline citations added to your article will automatically display here. See en.wikipedia.org/wiki/WP:REFB for instructions on how to add citations. -->
{{reflist}}`
, '' );
if ( matches2.length === 1 ) {
wikicode = attempt.trim();
wikicode = wikicode.replace( /==\s*References\s*==/gi, '== References ==' );
}
}
Line 718 ⟶ 717:
}
removeUnderscoresFromWikilinks( wikicode ) {
wikicode = sf.surgicalReplaceInsideTags( /_/g, ' ', wikicode, [ '[[' ], [ ']]' ] );
return wikicode;
}
fixPipedWikilinksWithIdenticalParameters( wikicode ) {
for (
if ( match[ 1 ] === match[ 2 ] ) {
wikicode = this._replaceAll( wikicode, `[[${ match[ 1 ] }|${ match[ 1 ] }]]`, `[[${ match[ 1 ] }]]` );
}
}
Line 734 ⟶ 733:
}
removeBorderFromImagesInInfoboxes( wikicode ) {
wikicode = wikicode.replace( /(\|\s*logo\s*=\s*)\[\[File:([^\]
wikicode = wikicode.replace( /(\|\s*cover\s*=\s*)\[\[File:([^\]
return wikicode;
}
/** These often hide towards the bottom of a draft. When the draft is submitted, unsubmitted templates (t) detect this and show up as blank, creating a weird extra line break. So this basically fixes the line break. */
removeExtraAFCSubmissionTemplates( wikicode ) {
if ( hasSubmittedTemplate && hasUnsubmittedTemplate ) {
wikicode = wikicode.replace( /{{AfC submission\|t\|[^
}
return wikicode;
}
moveAFCSubmissionTemplatesToTop( wikicode ) {
if ( hasTemplateAtBottom ) {
// delete all submission templates
wikicode = wikicode.replace( /{{AfC submission[^
// insert template at top
wikicode = hasTemplateAtBottom[ 1 ] +
}
return wikicode;
}
deleteMultipleReferenceTags( wikicode ) {
if ( hasReflist && hasReferencesTag ) {
// delete all references tags
wikicode = wikicode.replace( /<references ?\/>\n?/gi, '' );
}
return wikicode;
}
_isUpperCase( str ) {
return str === str.toUpperCase();
}
_toSentenceCase( string ) {
return string.charAt( 0 ).toUpperCase() + string.slice( 1 ).toLowerCase();
}
_replaceAll( haystack, needle, replacement ) {
haystack = haystack.replace( regex, replacement );
return haystack;
}
_escapeRegEx( string ) {
return string.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' ); // $& means the whole matched string
}
}
// === modules/StringFilter.js ======================================================
Line 800:
* Does a replace, but specifies areas of the file that should NOT be replaced. Those areas are specified by providing an openingTag and a closingTag, and those areas are marked as off limits.
*/
surgicalReplaceOutsideTags( regex, replacement, haystack, openingTags, closingTags ) {
for ( let part of parts ) {
let openingTagMatch = false;
for (
if ( part.startsWith( tag ) ) {
openingTagMatch = true;
break;
}
}
if ( !
part = part.replace( regex, replacement );
}
resultArray.push( part );
}
return resultArray.join( '' );
}
Line 823:
* Does a replace, but specifies areas of the file that SHOULD be replaced, then skips the rest of the file. The area that should be replaced is specified by providing an openingTag and a closingTag.
*/
surgicalReplaceInsideTags( regex, replacement, haystack, openingTags, closingTags ) {
for ( let part of parts ) {
for (
if ( part.startsWith( tag ) ) {
part = part.replace( regex, replacement );
}
}
resultArray.push( part );
}
return resultArray.join( '' );
}
/**
* Also keeps the pattern in the result, unlike string.prototype.split. Algorithm isn't perfect, will fail with this pattern: <ref>Test/>Test</ref>. But should be good enough for DraftCleaner stuff.
*
* @param {string} string
* @param {string[]} patterns
* @
*/
_splitStringUsingMultiplePatterns( string, patterns ) {
let positionOfLastMatch = 0;
for ( let i = 0; i < length; i++ ) {
let patternMatch = false;
for (
if ( lookAhead.startsWith( pattern ) ) {
patternMatch = true;
break;
Line 857 ⟶ 859:
}
if ( patternMatch ) {
continue;
result.push( chunk );
positionOfLastMatch = i;
}
}
// Don't forget the last chunk.
result.push( string.substring( positionOfLastMatch ) );
return result;
}
}
});
|