namespace \webfiori\ui
class HTMLNode
Class Attributes Summary
Class Methods Summary
Class Attributes Details
- tab-spaces: Number of spaces in a tab. The value is 4.
- initial-tab: Initial number of tabs. The value is 0.
- with-colors: A boolean. The value is true.
- use-pre: Use 'pre' or 'span' to add colors. The value is true.
- colors: A sub-associative array of colors. The array has the following indices and values:
- bg-color: Background color of code block. The value is 'rgb(21, 18, 33)'
- text-color: Color of any text that appears inside any node. The value is 'gray'.
- attribute-color: The color of attribute name. The value is 'rgb(0,124,0)'.
- attribute-value-color: The color of attribute value. The value is 'rgb(170,85,137)'.
- node-name-color: Color of HTML node name. The value is 'rgb(204,225,70)'.
- lt-gt-color: The color of '<' and '>' signs (around node name). The value is 'rgb(204,225,70)'.
- comment-color: The color of any HTML comment. The value is 'rgb(0,189,36)'.
- operator-color: The color of equal operator for attribute value. The value is 'gray'.
- br
- hr
- meta
- img
- input
- wbr
- embed
- base
- col
- link
- param
- source
- track
- area
Class Methods Details
Parameters:
- string $name The name of the node (such as 'div'). If the developer would like to create a comment node, the name should be '#comment'. If the developer would like to create a text node, the name should be '#text'. If this parameter is not given, default value will be used which is 'div'. A valid node name must follow the following rules:
- Must not be an empty string.
- Must not start with a number.
- Must not start with '-', '.' or ':'.
- Can only have the following characters in its name: [A-Z], [a-z], [0-9], ':', '.' and '-'.
- $attrs An optional array that contains node attributes.
Parameters:
- HTMLNode|string $node The node that will be added. It can be an instance of the class 'HTMLNode' or a string that represents the name of the node that will be added. The node can have child nodes only if 4 conditions are met:
- If the node is not a text node.
- The node is not a comment node.
- The node is not a void node.
- The node is not it self. (making a node as a child of it self)
- array|boolean $attrsOrChain An optional array of attributes which will be set in the newly added child. Applicable only if the newly added node is not a text or a comment node. Also, this can be used as boolean value to act as last method parameter (the $chainOnParent)
- boolean $chainOnParent If this parameter is set to true, the method will return the same instance at which the child node is added to. If set to false, the method will return the child which have been added. This can be useful if the developer would like to add a chain of elements to the body of the parent or child. Default value is false. It means the chaining will happen at child level.
$chainOnParent
is set to true, the method will return the '$this' instance. If set to false, it will return the newly added child.Parameters:
- string $text The text that will be in the node.
Parameters:
Parameters:
- string|HTMLNode $body The body of the tag. This can be a simple text or an object of type 'HTMLNode'. Note that if text is given and the text contains HTML code, the method will not replace the code by HTML entities.
- array $attributes An optional array that contains the attributes which will be set for the created node.
Parameters:
Parameters:
- array $formattingOptions An associative array which contains an options for formatting the code. The available options are:
- tab-spaces: The number of spaces in a tab. Usually 4.
- with-colors: A boolean value. If set to true, the code will be highlighted with colors.
- initial-tab: Number of initial tabs
- colors: An associative array of highlight colors.
- bg-color: The 'pre' block background color.
- attribute-color: HTML attribute name color.
- attribute-value-color: HTML attribute value color.
- text-color: Normal text color.
- comment-color: Comment color.
- operator-color: Assignment operator color.
- lt-gt-color: Less than and greater than color.
- node-name-color: Node name color.
Parameters:
- array $arrOfChildren The array can hold objects of type HTMLNode or can hold sub associative arrays. each array will hold one child information. Each array can have the following options:
- name: The name of the child such as 'div'.
- attributes: A sub associative array that holds the attributes of the child.
- is-void: A boolean which can be set to true if the child represents a void node.
- text: This index is used if node type is #TEXT or #COMMENT. It represents the text that will appear in the body of the node
- children: An array that holds arrays that represents the children of the child. The arrays can have same structure.
Parameters:
- string|HTMLNode $cellBody The text of cell body. It can have HTML. Also, it can be an object of type 'HTMLNode'.
- string $cellType The type of the cell. This attribute can have only one of two values, 'td' or 'th'. 'td' If the cell is in the body of the table and 'th' if the cell is in the header. If none of the two is given, 'td' will be used by default.
- array $attributes An optional array of attributes to set for the cell.
Parameters:
- string $title The title of the code snippit such as 'PHP Code'.
- string $code The code that will be displayed by the snippit. It is recommended that the code enclosed between double quotation marks.
- array $attributes An optional array of attributes to set for the parent element in the object. Note that if the array has the attribute 'class' or the attribute 'style', they will be ignored.
Parameters:
- string $txt The text that will be in the node.
Parameters:
- string $path The location of the file that will have the HTML component.
- array $slotsVals An array that contains slots values. A slot in the component is a string which is enclosed between two curly braces (such as {{name}}). This array must be associative. The indices of the array are slots names and values of the indices are slots values. The values of the slots can be also sub-array that contains more values. For example, if we have a slot with the name {{ user-name }}, then the array can have the index 'user-name' with the value of the slot.
Parameters:
- string $text The text that will be inserted in the body of the comment.
Parameters:
Parameters:
- array $attributes An optional array of attributes that will be set in the div element.
Parameters:
- array $attributes An optional array of attributes that will be set in the form element.
Parameters:
Parameters:
- string $attrName The name of the attribute. Upper case name and lower case name is treated same way. Which means 'ID' is like 'id'.
Parameters:
- string $attrName The name of the attribute. It can be in upper or lower case.
Parameters:
- int $index The position of the child node. This must be an integer value starting from 0.
Parameters:
Parameters:
- string $val The ID of the child.
Parameters:
- string $val The name of the tag (such as 'div' or 'a').
Parameters:
- string $attrName The name of the attribute. It can be in upper case or lower case.
Parameters:
- HTMLNode $node The node that will be checked.
Parameters:
- string $text HTML code.
<html><head></head><body></body></html>Then the output will be as follows:
Array ( [0] => Array ( [tag-name] => html [is-void-tag] => [attributes] => Array ( ) [children] => Array ( [0] => Array ( [tag-name] => head [is-void-tag] => [attributes] => Array ( ) [children] => Array ( ) ) [1] => Array ( [tag-name] => body [is-void-tag] => [attributes] => Array ( ) [children] => Array ( ) ) ) ) )
Parameters:
- array $attributes An optional array of attributes that will be set in the image element.
Parameters:
Parameters:
- HTMLNode $el The new element that will be inserted. It is possible to insert child elements to the element if the following conditions are met:
- If the node is not a text node.
- The node is not a comment node.
- The note is not a void node.
- The note is not it self. (making a node as a child of it self)
- int $position The position at which the element will be added. it must be a value between 0 and
HTMLNode::childrenCount()
inclusive.
Parameters:
Parameters:
Parameters:
- string $htmlTemplatePath The location of the file that will have the component. It can be of any type (HTML, XML, ...).
- array $slotsValsArr An array that contains slots values. A slot in the component is a string which is enclosed between two curly braces (such as {{name}}). This array must be associative. The indices of the array are slots names and values of the indices are slots values. For example, if we have a slot with the name {{ user-name }}, then the array can have the index 'user-name' with the value of the slot.
Parameters:
- array $items An array that contains list items. They can be a simple text, objects of type 'ListItem' or object of type 'HTMLNode'. Note that if the list item is a text, the item will be added without placing HTML entities in the text if the text has HTMLCode.
- array $attributes An optional array of attributes to set for the list.
Parameters:
- string|HTMLNode $body An optional text to add to the body of the paragraph. This also can be an object of type 'HTMLNode'. Note that if HTMLNode object is given, its name must be part of the array PNode::ALLOWED_CHILDS or the method will not add it.
- type $attributes
- boolean $escEntities If set to true, the method will replace the characters '<', '>' and '&' with the following HTML entities: '<', '>' and '&' in the given text. Default is true.
Parameters:
- string $name The name of the attribute.
Parameters:
Parameters:
Parameters:
- string|HTMLNode $title The title that will be set in the heading tag. This also can be an object of type 'HTMLNode'.
- int $headingLvl Heading level. It can be a value between 1 and 6 inclusive. Default value is 1.
- array $attributes An optional array of attributes that will be set in the section element.
Parameters:
- string $name The name of the attribute. If the attribute does not exist, it will be created. If already exists, its value will be updated. Note that if the node type is text node, the attribute will never be created.
- string|null $val The value of the attribute. Default is null. Note that if the value has any extra spaces, they will be trimmed. Also, if the given value is null, the attribute will be set with no value.
Parameters:
- array $attrsArr An associative array that has attributes names and values. The indices will represents attributes names and the value of each index represents the values of the attributes. If the given array has elements without keys, they will be added without values.
Parameters:
Parameters:
- string $idVal The value to set.
Parameters:
- boolean $bool true to make the document that will be generated from the node user-readable. false to make it compact.
Parameters:
- boolean $bool True to make the node render quoted attributes. False to not.
Parameters:
- boolean $bool If the developer would like to make the node a void node, then he must pass true.
Parameters:
- string $val The value to set.
Parameters:
- string $name The new name.
Parameters:
Parameters:
- int $val The value to set. From MDN: An integer attribute indicating if the element can take input focus. It can takes several values:
- A negative value means that the element should be focusable, but should not be reachable via sequential keyboard navigation.
- 0 means that the element should be focusable and reachable via sequential keyboard navigation, but its relative order is defined by the platform convention
- A positive value means that the element should be focusable and reachable via sequential keyboard navigation; the order in which the elements are focused is the increasing value of the tabindex. If several elements share the same tabindex, their relative order follows their relative positions in the document.
Parameters:
- string $text The text to set. If the node is not a text node or a comment node, the value will never be set.
- boolean $escHtmlEntities If set to true, the method will replace the characters '<', '>' and '&' with the following HTML entities: '<', '>' and '&' in the given text. Default is true. Ignored in case the node type is comment.
Parameters:
- string $val The value to set. From MDN: Contains a text representing advisory information related to the element it belongs to. Such information can typically, but not necessarily, be presented to the user as a tooltip.
Parameters:
- boolean $boolean True or false.
Parameters:
- string $val The value to set. It can be 'ltr' or 'rtl'.
Parameters:
- array $attributes An optional array of attributes to set on the child.
Parameters:
Parameters:
- boolean $formatted Set to true to return a well formatted HTML document (has new lines and indentations). Note that the size of generated node will increase if this one is set to true. Default is false.
- int $initTab Initial tab count (indentation). Used in case of the document is well formatted. This number represents the size of code indentation.
Parameters:
- array $data An array that holds the data that will be added to the row. This array can hold strings or objects of type 'HTMLNode'.
- array $attributes An optional array of attributes to set for the row.
- boolean $headerRow If set to true, the method will add the data in a 'th' cell instead of 'td' cell. Default is false.
Parameters:
- array $items An array that contains list items. They can be a simple text, objects of type 'ListItem' or object of type 'HTMLNode'. Note that if the list item is a text, the item will be added without placing HTML entities in the text if the text has HTMLCode.
- array $attributes An optional array of attributes to set for the list.