0 branches
Tree Top files
Code
Clone with HTTPS:
56 years ago
..
parser.v all: super_batch6 fixes last Apr 17 9.69 KB

net/html is an HTML Parser written in pure V.

Usage

import net.html

fn main() {
    doc := html.parse('</body></html>')
    tag := doc.get_tags(name: 'h1')[0] // <h1>Hello world!</h1>
    println(tag.name) // h1
    println(tag.content) // Hello world!
    println(tag.attributes) // {'class':'title'}
    println(tag.str()) // <h1 >Hello world!</h1>
}

For tags with nested markup, tag.content preserves the inner HTML:

import net.html

fn main() {
    doc := html.parse('<p>before <span>in between</span> after</p>')
    tag := doc.get_tags(name: 'p')[0]
    println(tag.content) // before <span>in between</span> after
    println(tag.text()) // before in between after
}

More examples found on parser_test.v and html_test.v