v2 / vlib / net / html / html.v
22 lines · 19 sloc · 684 bytes · 9817dfc5ba33629b82942db69ce9d9d385661b1f
Raw
1module html
2
3import 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>.
8pub 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>.
17pub 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