Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
Classes | Functions
myst_parser.parsers.parse_html Namespace Reference

Classes

class  Attribute
 
class  Char
 
class  Comment
 
class  Data
 
class  Declaration
 
class  Element
 
class  Entity
 
class  HtmlToAst
 
class  Pi
 
class  Root
 
class  Tag
 
class  TerminalElement
 
class  Tree
 
class  VoidTag
 
class  XTag
 

Functions

Root tokenize_html (str text, str name="", bool convert_charrefs=False)
 

Detailed Description

A simple but complete HTML to Abstract Syntax Tree (AST) parser.

The AST can also reproduce the HTML text.

Example::

    >> text = '<div class="note"><p>text</p></div>'
    >> ast = tokenize_html(text)
    >> list(ast.walk(include_self=True))
    [Root(''), Tag('div', {'class': 'note'}), Tag('p'), Data('text')]
    >> str(ast)
    '<div class="note"><p>text</p></div>'
    >> str(ast[0][0])
    '<p>text</p>'

Note: optional tags are not accounted for
(see https://html.spec.whatwg.org/multipage/syntax.html#optional-tags)