| 1 | module html |
| 2 | |
| 3 | import os |
| 4 | |
| 5 | // parse parses and returns the DOM from the given text. |
| 6 | // Note: this function converts tags to lowercase. |
| 7 | // E.g. <MyTag>content</MyTag> is parsed as <mytag>content</mytag>. |
| 8 | pub fn parse(text string) DocumentObjectModel { |
| 9 | mut parser := Parser{} |
| 10 | parser.parse_html(text) |
| 11 | return parser.get_dom() |
| 12 | } |
| 13 | |
| 14 | // parse_file parses and returns the DOM from the contents of a file. |
| 15 | // Note: this function converts tags to lowercase. |
| 16 | // E.g. <MyTag>content</MyTag> is parsed as <mytag>content</mytag>. |
| 17 | pub fn parse_file(filename string) DocumentObjectModel { |
| 18 | content := os.read_file(filename) or { return DocumentObjectModel{ |
| 19 | root: &Tag{} |
| 20 | } } |
| 21 | return parse(content) |
| 22 | } |
| 23 | |