utilsWikitext

Wikitext parsing and processing utilities.

Source:

Methods

(static) brsToNewlines(code, replacement) → {string}

Source:

Replace <br>s with \n, except in list elements and <pre>'s created by a space starting a line.

Parameters:
Name Type Description
code string
replacement string
Returns:
Type
string
Source:

Encode text to put it in a [[wikilink]]. This is meant for section links as the characters that this function encodes are forbidden in page titles anyway, so page titles containing them are not valid titles.

Parameters:
Name Type Description
link string
Returns:
Type
string

(static) endWithTwoNewlines(code) → {string}

Source:

Modify a string or leave it unchanged so that is has two newlines at the end of it. (Meant for section wikitext.)

Parameters:
Name Type Description
code string
Returns:
Type
string
Source:

Mask links that have |, replace | with {{!}}, unmask links. If maskedTexts is not provided, sensitive code will be masked as well.

Also masks bare { and } that weren't identified as part of other markup (e.g. try quoting the sentence "Или держал в голове то, что практика использования {{doc/begin}} ... делали

вместо шаблона." in https://ru.wikipedia.org/wiki/User_talk:Jack_who_built_the_house#c-Jack_who_built_the_house-2020-03-22T12:18:00.000Z-DonRumata-2020-03-22T11:05:00.000Z

  • "
" screws everything up.)
Parameters:
Name Type Attributes Description
code string
maskedTexts Array.<string> <optional>
Returns:
Type
string

(static) extractArabicNumeral(s, digitsopt) → {number}

Source:

Extract a number from a string using a set of digits.

Parameters:
Name Type Attributes Default Description
s string
digits string <optional>
'0123456789'
Returns:
Type
number

(static) extractSignatures(code) → {Array.<object>}

Source:

Extract signatures from wikitext.

Only basic signature parsing is performed here; more precise signature text identification is performed in CommentSource#adjustSignature. See also CommentSource#adjust.

Parameters:
Name Type Description
code string

Code to extract signatures from.

Returns:
Type
Array.<object>

(static) findFirstTimestamp(code) → (nullable) {string}

Source:

Find the first timestamp related to a comment in the code.

Parameters:
Name Type Description
code string
Returns:
Type
string

(static) generateTagsRegexp(tags) → {RegExp}

Source:

Generate a regular expression that searches for specified tags in the text (opening, closing, and content between them).

Parameters:
Name Type Description
tags Array.<string>
Returns:
Type
RegExp

(static) maskDistractingCode(code) → {string}

Source:

Replace HTML comments (<!-- -->), <nowiki>, <syntaxhighlight>, <source>, and <pre> tags content, left-to-right and right-to-left marks, and also newlines inside some tags (<br\n>) in the code with spaces.

This is used to ignore comment contents (there could be section code examples for novices there that could confuse search results) but get right positions and code in the result.

Parameters:
Name Type Description
code string
Returns:
Type
string

(static) normalizeCode(text) → {string}

Source:

Replace HTML entities with corresponding characters. Also replace different kinds of spaces, including multiple, with one normal space.

Parameters:
Name Type Description
text string
Returns:
Type
string

(static) removeWikiMarkup(code) → {string}

Source:

Remove certain kinds of wiki markup from code, such as formatting, links, tags, and comments. Also replace multiple spaces with one and trim the input. The product of this function is usually not for display (for example, it just removes template names making the resulting code look silly), but for comparing purposes.

Parameters:
Name Type Description
code string
Returns:
Type
string