Class: MWParserEnvironment

config/MWParserEnvironment~MWParserEnvironment(parsoidConfig, optionsopt)

new MWParserEnvironment(parsoidConfig, optionsopt)

Holds configuration data that isn't modified at runtime, debugging objects, a page object that represents the page we're parsing, and more.

Holds configuration data that isn't modified at runtime, debugging objects, a page object that represents the page we're parsing, and more. The title of the page is held in this.page.name and is stored as a "true" url-decoded title, ie without any url-encoding which might be necessary if the title were referenced in wikitext.

Should probably be constructed with .getParserEnv.

Parameters:
Name Type Attributes Description
parsoidConfig ParsoidConfig
options Object <optional>
Source:

Members

availableVersions

The content versions Parsoid knows how to produce.

The content versions Parsoid knows how to produce. Ordered by desirability.

Properties:
Name Type Description
availableVersions Array
Source:

A passed-in cookie, if any

.

A passed-in cookie, if any

Source:

htmlVariantLanguage

If non-null, the language variant used for Parsoid HTML; we convert to this if wt2html, or from this (if html2wt).

If non-null, the language variant used for Parsoid HTML; we convert to this if wt2html, or from this (if html2wt).

Source:

inputContentVersion

The default content version that Parsoid assumes it's serializing or updating in the pb2pb endpoints

.

The default content version that Parsoid assumes it's serializing or updating in the pb2pb endpoints

Properties:
Name Type Description
inputContentVersion string
Source:

nativeGallery

Enable editing galleries via HTML, instead of extsrc.

Enable editing galleries via HTML, instead of extsrc.

Source:

outputContentVersion

The default content version that Parsoid will generate.

The default content version that Parsoid will generate.

Properties:
Name Type Description
outputContentVersion string
Source:

pageBundle

Sets ids on nodes and stores data-* attributes in a JSON blob

.

Sets ids on nodes and stores data-* attributes in a JSON blob

Source:

reqId

A passed-in request id, if any

.

A passed-in request id, if any

Source:

scrubWikitext

Apply extra normalizations before serializing DOM.

Apply extra normalizations before serializing DOM.

Source:

userAgent

A passed-in user agent, if any

.

A passed-in user agent, if any

Source:

wikitextVersion

...
Properties:
Name Type Description
wikitextVersion string
Source:

wrapSections

Whether Parsoid should add HTML section wrappers around logical sections.

Whether Parsoid should add HTML section wrappers around logical sections. Defaults to true.

Properties:
Name Type Description
wrapSections string
Source:

wtVariantLanguage

If non-null, the language variant to be used for wikitext.

If non-null, the language variant to be used for wikitext. If null, heuristics will be used to identify the original wikitext variant in wt2html mode, and in html2wt mode new or edited HTML will be left unconverted.

Source:

Methods

(static) getParserEnv(parsoidConfig, optionsopt) → {Promise.<MWParserEnvironment>}

Alternate constructor for MWParserEnvironments

.

Alternate constructor for MWParserEnvironments

Parameters:
Name Type Attributes Description
parsoidConfig ParsoidConfig
options Object <optional>

Environment options.

Properties
Name Type Attributes Description
pageName string <optional>

the true url-decoded title of the page

Source:
Returns:

The finished environment object

Type
Promise.<MWParserEnvironment>

cacheReusableExpansions(obj)

See if we can reuse transclusion or extension expansions.

See if we can reuse transclusion or extension expansions.

Parameters:
Name Type Description
obj Object
Properties
Name Type Description
html string
updates Object

Update mode.

Source:

getContentHandler(forceContentModelopt) → {Object}

Get an appropriate content handler, given a contentmodel.

Get an appropriate content handler, given a contentmodel.

Parameters:
Name Type Attributes Description
forceContentModel string <optional>

An optional content model which will override whatever the source specifies.

Source:
Returns:

An appropriate content handler with toHTML and fromHTML methods.

Type
Object

htmlContentLanguage()

Determine an appropriate content-language for the HTML form of this page.

Determine an appropriate content-language for the HTML form of this page.

Source:

htmlVary()

Determine appropriate vary headers for the HTML form of this page.

Determine appropriate vary headers for the HTML form of this page.

Source:

initializeForPageName(pageName)

Initialize the environment for the page.

Initialize the environment for the page.

Parameters:
Name Type Description
pageName string

The "true" url-decoded pagename (see above).

Source:

langConverterEnabled() → {boolean}

Determine if LanguageConverter markup should be parsed on this page, based on the wiki configuration and the current page language.

Determine if LanguageConverter markup should be parsed on this page, based on the wiki configuration and the current page language.

Source:
Returns:
Type
boolean

normalizedTitleKey(urlDecodedStropt, noExceptionsopt, ignoreFragmentopt) → {string|null}

Get normalized title key for a title string.

Get normalized title key for a title string.

Parameters:
Name Type Attributes Description
urlDecodedStr string <optional>

Should be in url-decoded format.

noExceptions boolean <optional>

Return null instead of throwing exceptions.

ignoreFragment boolean <optional>

Ignore the fragment, if any.

Source:
Returns:

Normalized title key for a title string (or null for invalid titles).

Type
string | null

resolveContentVersion(v) → {string|null}

See if any content version Parsoid knows how to produce satisfies the the supplied version, when interpreted with semver caret semantics.

See if any content version Parsoid knows how to produce satisfies the the supplied version, when interpreted with semver caret semantics. This will allow us to make backwards compatible changes, without the need for clients to bump the version in their headers all the time.

Parameters:
Name Type Description
v string
Source:
Returns:
Type
string | null

resolveTitle()

TODO: Handle namespaces relative links like [[User:../../]] correctly, they shouldn't be treated like links at all.

TODO: Handle namespaces relative links like [[User:../../]] correctly, they shouldn't be treated like links at all.

This function handles strings that are page-fragments or subpage references and resolves those w.r.t the current page name so that title-handling code elsewhere only deal with non-relative title strings.

Source:

setOutputContentVersion(v)

...
Parameters:
Name Type Description
v string
Source:

setPageSrcInfo(srcOrMetadata)

Set the src and optionally meta information for the page we're parsing.

Set the src and optionally meta information for the page we're parsing.

If the argument is a simple string, will clear metadata and just set this.page.src. Otherwise, the provided metadata object should have fields corresponding to the JSON output given by action=query&prop=revisions on the MW API. That is:

    metadata = {
      title: // normalized title (ie, spaces not underscores)
      ns:    // namespace
      id:    // page id
      revision: {
        revid:    // revision id
        parentid: // revision parent
        timestamp:
        user:     // contributor username
        userid:   // contributor user id
        sha1:
        size:     // in bytes
        comment:
        slots: {
          main: {
            contentmodel:
            contentformat:
            "*   ":     // actual source text --> copied to this.page.src
          }
        }
      }
    }
Parameters:
Name Type Description
srcOrMetadata string | Object

page source or metadata

Source:

switchToConfig(prefix, noCache) → {Promise}

Function that switches to a different configuration for a different wiki.

Function that switches to a different configuration for a different wiki. Caches all configs so we only need to get each one once (if we do it right)

Parameters:
Name Type Description
prefix string

The interwiki prefix that corresponds to the wiki we should use

noCache boolean

Don't use cached configs; mainly for testing.

Source:
Returns:
Type
Promise