Documentation

Html

Common Html functions

Tags
SuppressWarnings

(PHPMD.UnusedPrivateMethod) For readWPNode

Table of Contents

$listIndex  : mixed
$options  : mixed
$xpath  : mixed
addHtml()  : mixed
Add HTML parts.
filterOutNonInheritedStyles()  : mixed
Removes non-inherited styles from array
getListStyle()  : array<string|int, mixed>
mapAlign()  : string|null
Transforms a HTML/CSS alignment into a \PhpOffice\PhpWord\SimpleType\Jc
mapAlignVertical()  : string|null
Transforms a HTML/CSS vertical alignment
mapBorderColor()  : mixed
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()  : mixed
Parse child nodes.
parseHeading()  : TextRun
Parse heading node
parseHorizRule()  : mixed
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()  : mixed
Parse input node
parseLineBreak()  : mixed
Parse line break
parseLink()  : mixed
Parse link node
parseList()  : mixed
Parse list node
parseListItem()  : mixed
Parse list item node
parseNode()  : mixed
Parse a node and add a corresponding element to the parent element.
parseParagraph()  : TextRun
Parse paragraph node
parseProperty()  : mixed
Parse property node
parseRow()  : Row
Parse a table row
parseSpan()  : mixed
Parse span node
parseStyle()  : array<string|int, mixed>
Parse style
parseTable()  : Table
Parse table node
parseText()  : mixed
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

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 ]) : mixed

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
Return values
mixed

filterOutNonInheritedStyles()

Removes non-inherited styles from array

protected static filterOutNonInheritedStyles(array<string|int, mixed> $styles) : mixed
Parameters
$styles : array<string|int, mixed>
Return values
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) : string|null
Parameters
$cssAlignment : string
Return values
string|null

mapAlignVertical()

Transforms a HTML/CSS vertical alignment

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

mapBorderColor()

protected static mapBorderColor(mixed &$styles, mixed $cssBorderColor) : mixed
Parameters
$styles : mixed
$cssBorderColor : mixed
Return values
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
Return values
mixed

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 $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>
Return values
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) : mixed
Parameters
$node : DOMNode
$element : AbstractContainer
Return values
mixed

parseInlineStyle()

parse Inline style of a node

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

Node to check on attributes and to compile a style array

$styles : array<string|int, mixed> = array()

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) : mixed
Parameters
$node : DOMNode
$element : AbstractContainer
$styles : array<string|int, mixed>
Return values
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>
Return values
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>
Return values
mixed

parseListItem()

Parse list item node

protected static parseListItem(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>
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

Return values
mixed

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() ][, array<string|int, mixed> $data = array() ]) : mixed
Parameters
$node : DOMNode

node to parse

$element : AbstractContainer

object to add an element corresponding with the node

$styles : array<string|int, mixed> = array()

Array with all styles

$data : array<string|int, mixed> = array()

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

Return values
mixed

parseParagraph()

Parse paragraph node

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

parseProperty()

Parse property node

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

Style name

$argument2 : string

Style value

Return values
mixed

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) : mixed
Parameters
$node : DOMNode
$styles : array<string|int, mixed>
Return values
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>

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) : mixed
Parameters
$node : DOMNode
$element : AbstractContainer
$styles : array<string|int, mixed>
Return values
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>
Return values
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

Search results