MediaWiki
master
|
Parser for Vue single file components (.vue files). More...
Public Member Functions | |
parse (string $html, array $options=[]) | |
Parse a Vue single file component, and extract the script, template and style parts. More... | |
Private Member Functions | |
findUniqueTags (DOMNode $rootNode, array $tagNames) | |
Find occurrences of specified tags in a DOM node, expecting at most one occurrence of each. More... | |
getStyleAndLang (DOMElement $styleNode) | |
Get the contents and language of the <style> tag. More... | |
getTemplateHtml ( $html, $minify) | |
Get the HTML contents of the <template> tag, optionally minifed. More... | |
newFilteringDispatcher (TreeBuilder $treeBuilder, $nodeName) | |
Custom Dispatcher subclass that only dispatches tree events inside a tag with a certain name. More... | |
newTemplateFormatter ( $minify) | |
Custom HtmlFormatter subclass that optionally removes comments and strips whitespace. More... | |
parseHTML ( $html) | |
Parse HTML to DOM using RemexHtml. More... | |
validateAttributes (DOMNode $node, array $allowedAttributes) | |
Verify that a given node only has a given set of attributes, and no others. More... | |
validateTemplateTag (DOMNode $templateNode) | |
Check that the <template> tag has exactly one element child. More... | |
Parser for Vue single file components (.vue files).
See parse() for usage.
Definition at line 39 of file VueComponentParser.php.
|
private |
Find occurrences of specified tags in a DOM node, expecting at most one occurrence of each.
This method only looks at the top-level children of $rootNode, it doesn't descend into them.
DOMNode | $rootNode | Node whose children to look at |
string[] | $tagNames | Tag names to look for (must be all lowercase) |
Definition at line 113 of file VueComponentParser.php.
Referenced by parse().
|
private |
Get the contents and language of the <style> tag.
The language can be 'css' or 'less'.
DOMElement | $styleNode | The <style> tag. |
Exception | If an invalid language is used, or if the 'scoped' attribute is set. |
Definition at line 188 of file VueComponentParser.php.
Referenced by parse().
|
private |
Get the HTML contents of the <template> tag, optionally minifed.
To work around a bug in PHP's DOMDocument where attributes like @click get mangled, we re-parse the entire file using a Remex parse+serialize pipeline, with a custom dispatcher to zoom in on just the contents of the <template> tag, and a custom formatter for minification. Keeping everything in Remex and never converting it to DOM avoids the attribute mangling issue.
string | $html | HTML that contains a <template> tag somewhere |
bool | $minify | Whether to minify the output (remove comments, strip whitespace) |
Definition at line 214 of file VueComponentParser.php.
References newFilteringDispatcher(), and newTemplateFormatter().
Referenced by parse().
|
private |
Custom Dispatcher subclass that only dispatches tree events inside a tag with a certain name.
This effectively filters the tree to only the contents of that tag.
TreeBuilder | $treeBuilder | |
string | $nodeName | Tag name to filter for |
Definition at line 297 of file VueComponentParser.php.
Referenced by getTemplateHtml().
|
private |
Custom HtmlFormatter subclass that optionally removes comments and strips whitespace.
If $minify=false, this formatter falls through to HtmlFormatter for everything (except that it strips the <!doctype html> tag).
bool | $minify | If true, remove comments and strip whitespace |
Definition at line 235 of file VueComponentParser.php.
Referenced by getTemplateHtml().
VueComponentParser::parse | ( | string | $html, |
array | $options = [] |
||
) |
Parse a Vue single file component, and extract the script, template and style parts.
Returns an associative array with the following keys:
The following options can be passed in the $options parameter:
string | $html | HTML with <script>, <template> and <style> tags at the top level |
array | $options | Associative array of options |
Exception | If the input is invalid |
Definition at line 58 of file VueComponentParser.php.
References findUniqueTags(), getStyleAndLang(), getTemplateHtml(), parseHTML(), validateAttributes(), and validateTemplateTag().
|
private |
Parse HTML to DOM using RemexHtml.
string | $html |
Definition at line 97 of file VueComponentParser.php.
Referenced by parse().
|
private |
Verify that a given node only has a given set of attributes, and no others.
DOMNode | $node | Node to check |
array | $allowedAttributes | Attributes the node is allowed to have |
Exception | If the node has an attribute it's not allowed to have |
Definition at line 133 of file VueComponentParser.php.
Referenced by parse().
|
private |
Check that the <template> tag has exactly one element child.
If the <template> tag has multiple children, or is empty, or contains (non-whitespace) text, an exception is thrown.
DOMNode | $templateNode | The <template> node |
Exception | If the contents of the <template> node are invalid |
Definition at line 155 of file VueComponentParser.php.
Referenced by parse().