Documentation

Html
in package

Common Html functions.

Tags
SuppressWarnings

(PHPMD.UnusedPrivateMethod) For readWPNode

Table of Contents

Constants

RGB_REGEXP  = '/^\s*rgb\s*[(]\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*[)]\s*$/'

Properties

$css  : Css
$listIndex  : mixed
$options  : mixed
$xpath  : mixed

Methods

addHtml()  : void
Add HTML parts.
filterOutNonInheritedStyles()  : mixed
Removes non-inherited styles from array.
getListStyle()  : array<string|int, mixed>
mapAlign()  : null|string
Transforms a HTML/CSS alignment into a \PhpOffice\PhpWord\SimpleType\Jc.
mapAlignVertical()  : null|string
Transforms a HTML/CSS vertical alignment.
mapBorderColor()  : void
mapBorderStyle()  : null|string
Transforms a CSS border style into a word border style.
mapListType()  : mixed
Map list style for ordered list.
parseCell()  : Cell|TextRun
Parse table cell.
parseChildNodes()  : void
Parse child nodes.
parseHeading()  : TextRun
Parse heading node.
parseHorizRule()  : void
Render horizontal rule Note: Word rule is not the same as HTML's <hr> since it does not support width and thus neither alignment.
parseImage()  : Image
Parse image node.
parseInlineStyle()  : array<string|int, mixed>
parse Inline style of a node.
parseInput()  : void
Parse input node.
parseLineBreak()  : void
Parse line break.
parseLink()  : mixed
Parse link node.
parseList()  : mixed
Parse list node.
parseListItem()  : void
Parse list item node.
parseNode()  : void
Parse a node and add a corresponding element to the parent element.
parseParagraph()  : PageBreak|TextRun
Parse paragraph node.
parseProperty()  : void
Parse property node.
parseRow()  : Row
Parse a table row.
parseSpan()  : void
Parse span node.
parseStyle()  : array<string|int, mixed>
Parse style.
parseStyleDeclarations()  : mixed
parseTable()  : Table
Parse table node.
parseText()  : void
Parse text node.
recursiveParseStylesInHierarchy()  : mixed
Recursively parses styles on parent nodes TODO if too slow, add caching of parent nodes, !! everything is static here so watch out for concurrency !!
shouldAddTextRun()  : bool
Checks if $node contains an HTML element that cannot be added to TextRun.
convertRgb()  : string

Constants

RGB_REGEXP

private mixed RGB_REGEXP = '/^\s*rgb\s*[(]\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*[)]\s*$/'

Properties

$listIndex

protected static mixed $listIndex = 0

$options

protected static mixed $options

$xpath

protected static mixed $xpath

Methods

addHtml()

Add HTML parts.

public static addHtml(AbstractContainer $element, string $html[, bool $fullHTML = false ][, bool $preserveWhiteSpace = true ][, mixed $options = null ]) : void

Note: $stylesheet parameter is removed to avoid PHPMD error for unused parameter Warning: Do not pass user-generated HTML here, as that would allow an attacker to read arbitrary files or perform server-side request forgery by passing local file paths or URLs in .

Parameters
$element : AbstractContainer

Where the parts need to be added

$html : string

The code to parse

$fullHTML : bool = false

If it's a full HTML, no need to add 'body' tag

$preserveWhiteSpace : bool = true

If false, the whitespaces between nodes will be removed

$options : mixed = null

filterOutNonInheritedStyles()

Removes non-inherited styles from array.

protected static filterOutNonInheritedStyles(array<string|int, mixed> $styles) : mixed
Parameters
$styles : array<string|int, mixed>

getListStyle()

protected static getListStyle(bool $isOrderedList) : array<string|int, mixed>
Parameters
$isOrderedList : bool
Return values
array<string|int, mixed>

mapAlign()

Transforms a HTML/CSS alignment into a \PhpOffice\PhpWord\SimpleType\Jc.

protected static mapAlign(string $cssAlignment, bool $bidi) : null|string
Parameters
$cssAlignment : string
$bidi : bool
Return values
null|string

mapAlignVertical()

Transforms a HTML/CSS vertical alignment.

protected static mapAlignVertical(string $alignment) : null|string
Parameters
$alignment : string
Return values
null|string

mapBorderColor()

protected static mapBorderColor(mixed &$styles, mixed $cssBorderColor) : void
Parameters
$styles : mixed
$cssBorderColor : mixed

mapBorderStyle()

Transforms a CSS border style into a word border style.

protected static mapBorderStyle(string $cssBorderStyle) : null|string
Parameters
$cssBorderStyle : string
Return values
null|string

mapListType()

Map list style for ordered list.

protected static mapListType(string $cssListType) : mixed
Parameters
$cssListType : string

parseCell()

Parse table cell.

protected static parseCell(DOMNode $node, Table $element, array<string|int, mixed> &$styles) : Cell|TextRun
Parameters
$node : DOMNode
$element : Table
$styles : array<string|int, mixed>
Return values
Cell|TextRun

$element

parseChildNodes()

Parse child nodes.

protected static parseChildNodes(DOMNode $node, AbstractContainer|Row|Table $element, array<string|int, mixed> $styles, array<string|int, mixed> $data) : void
Parameters
$node : DOMNode
$element : AbstractContainer|Row|Table
$styles : array<string|int, mixed>
$data : array<string|int, mixed>

parseHeading()

Parse heading node.

protected static parseHeading(AbstractContainer $element, array<string|int, mixed> &$styles, string $argument1) : TextRun
Parameters
$element : AbstractContainer
$styles : array<string|int, mixed>
$argument1 : string

Name of heading style

Tags
todo

Think of a clever way of defining header styles, now it is only based on the assumption, that Heading1 - Heading6 are already defined somewhere

Return values
TextRun

parseHorizRule()

Render horizontal rule Note: Word rule is not the same as HTML's <hr> since it does not support width and thus neither alignment.

protected static parseHorizRule(DOMNode $node, AbstractContainer $element) : void
Parameters
$node : DOMNode
$element : AbstractContainer

parseInlineStyle()

parse Inline style of a node.

protected static parseInlineStyle(DOMNode $node[, array<string, mixed> $styles = [] ]) : array<string|int, mixed>
Parameters
$node : DOMNode

Node to check on attributes and to compile a style array

$styles : array<string, mixed> = []

is supplied, the inline style attributes are added to the already existing style

Return values
array<string|int, mixed>

parseInput()

Parse input node.

protected static parseInput(DOMNode $node, AbstractContainer $element, array<string|int, mixed> &$styles) : void
Parameters
$node : DOMNode
$element : AbstractContainer
$styles : array<string|int, mixed>

Parse link node.

protected static parseLink(DOMNode $node, AbstractContainer $element, array<string|int, mixed> &$styles) : mixed
Parameters
$node : DOMNode
$element : AbstractContainer
$styles : array<string|int, mixed>

parseList()

Parse list node.

protected static parseList(DOMNode $node, AbstractContainer $element, array<string|int, mixed> &$styles, array<string|int, mixed> &$data) : mixed
Parameters
$node : DOMNode
$element : AbstractContainer
$styles : array<string|int, mixed>
$data : array<string|int, mixed>

parseListItem()

Parse list item node.

protected static parseListItem(DOMNode $node, AbstractContainer $element, array<string|int, mixed> &$styles, array<string|int, mixed> $data) : void
Parameters
$node : DOMNode
$element : AbstractContainer
$styles : array<string|int, mixed>
$data : array<string|int, mixed>
Tags
todo

This function is almost the same like parseChildNodes. Merged?

todo

As soon as ListItem inherits from AbstractContainer or TextRun delete parsing part of childNodes

parseNode()

Parse a node and add a corresponding element to the parent element.

protected static parseNode(DOMNode $node, AbstractContainer $element[, array<string|int, mixed> $styles = [] ][, array<string|int, mixed> $data = [] ]) : void
Parameters
$node : DOMNode

node to parse

$element : AbstractContainer

object to add an element corresponding with the node

$styles : array<string|int, mixed> = []

Array with all styles

$data : array<string|int, mixed> = []

Array to transport data to a next level in the DOM tree, for example level of listitems

parseProperty()

Parse property node.

protected static parseProperty(array<string|int, mixed> &$styles, string $argument1, string $argument2) : void
Parameters
$styles : array<string|int, mixed>
$argument1 : string

Style name

$argument2 : string

Style value

parseRow()

Parse a table row.

protected static parseRow(DOMNode $node, Table $element, array<string|int, mixed> &$styles) : Row
Parameters
$node : DOMNode
$element : Table
$styles : array<string|int, mixed>
Return values
Row

$element

parseSpan()

Parse span node.

protected static parseSpan(DOMNode $node, array<string|int, mixed> &$styles) : void
Parameters
$node : DOMNode
$styles : array<string|int, mixed>

parseStyle()

Parse style.

protected static parseStyle(DOMAttr $attribute, array<string|int, mixed> $styles) : array<string|int, mixed>
Parameters
$attribute : DOMAttr
$styles : array<string|int, mixed>
Return values
array<string|int, mixed>

parseStyleDeclarations()

protected static parseStyleDeclarations(array<string|int, mixed> $selectors, array<string|int, mixed> $styles) : mixed
Parameters
$selectors : array<string|int, mixed>
$styles : array<string|int, mixed>

parseTable()

Parse table node.

protected static parseTable(DOMNode $node, AbstractContainer $element, array<string|int, mixed> &$styles) : Table
Parameters
$node : DOMNode
$element : AbstractContainer
$styles : array<string|int, mixed>
Tags
todo

As soon as TableItem, RowItem and CellItem support relative width and height

Return values
Table

$element

parseText()

Parse text node.

protected static parseText(DOMNode $node, AbstractContainer $element, array<string|int, mixed> &$styles) : void
Parameters
$node : DOMNode
$element : AbstractContainer
$styles : array<string|int, mixed>

recursiveParseStylesInHierarchy()

Recursively parses styles on parent nodes TODO if too slow, add caching of parent nodes, !! everything is static here so watch out for concurrency !!

protected static recursiveParseStylesInHierarchy(DOMNode $node, array<string|int, mixed> $style) : mixed
Parameters
$node : DOMNode
$style : array<string|int, mixed>

shouldAddTextRun()

Checks if $node contains an HTML element that cannot be added to TextRun.

protected static shouldAddTextRun(DOMNode $node) : bool
Parameters
$node : DOMNode
Return values
bool

Returns true if the node contains an HTML element that cannot be added to TextRun

convertRgb()

private static convertRgb(string $rgb) : string
Parameters
$rgb : string
Return values
string

        
On this page

Search results