Parsoid
A bidirectional parser between wikitext and HTML5
Loading...
Searching...
No Matches
Wikimedia\Parsoid\Ext\Utils Class Reference

This class provides sundry helpers needed by extensions. More...

Static Public Member Functions

static escapeWtEntities (string $text)
 Entity-escape anything that would decode to a valid wikitext entity.
 
static decodeWtEntities (string $text)
 Decode HTML5 entities in wikitext.
 
static parseMediaDimensions (SiteConfig $siteConfig, string $str, bool $onlyOne=false, bool $localized=false)
 Parse media dimensions.
 
static entityEncodeAll (string $s)
 Encode all characters as entity references.
 
static validateMediaParam (?int $num)
 Validate media parameters More generally, this is defined by the media handler in core.
 

Detailed Description

This class provides sundry helpers needed by extensions.

Member Function Documentation

◆ decodeWtEntities()

static Wikimedia\Parsoid\Ext\Utils::decodeWtEntities ( string $text)
static

Decode HTML5 entities in wikitext.

NOTE that wikitext only allows semicolon-terminated entities, while HTML allows a number of "legacy" entities to be decoded without a terminating semicolon. This function deliberately does not decode these HTML-only entity forms.

Parameters
string$text
Returns
string

◆ entityEncodeAll()

static Wikimedia\Parsoid\Ext\Utils::entityEncodeAll ( string $s)
static

Encode all characters as entity references.

This is done to make characters safe for wikitext (regardless of whether they are HTML-safe). Typically only called with single-codepoint strings.

Parameters
string$s
Returns
string

◆ escapeWtEntities()

static Wikimedia\Parsoid\Ext\Utils::escapeWtEntities ( string $text)
static

Entity-escape anything that would decode to a valid wikitext entity.

Note that HTML5 allows certain "semicolon-less" entities, like ¶ these aren't allowed in wikitext and won't be escaped by this function.

Parameters
string$text
Returns
string

◆ parseMediaDimensions()

static Wikimedia\Parsoid\Ext\Utils::parseMediaDimensions ( SiteConfig $siteConfig,
string $str,
bool $onlyOne = false,
bool $localized = false )
static

Parse media dimensions.

Parameters
SiteConfig$siteConfig
string$strmedia dimension string to parse
bool$onlyOneIf set, returns null if multiple dimenstions are present
bool$localizedDefaults to false; set to true if the $str has already been matched against img_width to localize the px suffix.
Returns
array{x:int,y?:int}|null

◆ validateMediaParam()

static Wikimedia\Parsoid\Ext\Utils::validateMediaParam ( ?int $num)
static

Validate media parameters More generally, this is defined by the media handler in core.

Parameters
?int$num
Returns
bool

The documentation for this class was generated from the following file: