Moving from Lexbor
If you have code on Lexbor’s C API, this page gives you the Parsec call for each thing you do, in C and in Rust. It covers what bindings use most: parsing a document or a fragment, finding elements with selectors, reading text, serializing, getting and setting attributes, and inserting and removing nodes. The C API page is the full reference for the C side.
There’s no drop-in lxb_* layer, on purpose. Lexbor’s API hands out pointers to its structs, and copying it would copy its node lifetimes too, which is where its use-after-free bugs come from. So you change the calls; the table below maps each one, and the C programs further down do the same job both ways.
The Lexbor function names are from its headers at commit 145872a, and each links to its declaration file. The C examples were compiled against Lexbor v3.0.0 (commit 2ae88a1, the one bench/ builds), and the Lexbor and Parsec versions of each print the same thing.
Not sure where to start? Find what your code does in Lexbor today, and follow it to the page you need:
Each box is a page in the sidebar: Parsing, Selectors, The document tree, Editing, Serialization, Tokenizer, Thread safety and memory safety, C API. This page has the calls side by side for all of them.
What changes in how you think about it
Section titled “What changes in how you think about it”- Fewer things to create and destroy. In C there’s a document (
parsec_parse,parsec_document_free) and a compiled selector (parsec_selector_compile,parsec_selector_free), and that’s all: no CSS parser object, no selectors engine object, no memory pools. In Rust there’s nothing to destroy at all; aDocumentfrees everything when it’s dropped. - Nodes are numbers, not pointers. A node is a
parsec_node(uint32_t) in C and aNodeId(u32) in Rust, an index into its document, and you read and change it through the document:parsec_text(doc, node, &len), notnode->.... A number can’t dangle. A removed node stays in the document until the document goes, so using it later is never a use-after-free, and every C call checks the number before using it. Better than that, it reads as nothing: onceparsec_removehas taken a node out, a number you kept for it gives no parent, no children, no text and no markup, where a Lexbor pointer would read freed memory, or the old node if nobody destroyed it (lexbor#132).parsec_node_is_removedtells you which. It also means memory for removed nodes isn’t given back early. - Errors are values, and there are few of them. Parsing doesn’t fail on bad markup, only on input over 512 MiB or a budget running out. Edits that would break the tree are refused:
PARSEC_ERR_CYCLEand friends in C,EditErrorin Rust. Lexbor’s edit calls returnvoidand do what you asked, cycles included. NULL is safe everywhere in the C API. - Strings have lengths, and an owner. In C, strings you pass in are a pointer and a length, as in Lexbor. Strings Parsec gives back are either borrowed from the document (
const char *, no NUL, valid until the next change) or copies you free withparsec_string_free(char *, NUL-terminated). In Rust they’re&strandString. - Input is text or bytes.
parsec::parsetakes UTF-8 as&str;parsec_encoding::parse_bytestakes bytes and sniffs the encoding, aslxb_html_encoding_determineplus a decode would. See Encoding. - Documents can be shared. Many threads can read and query one Parsec document at once, and one compiled selector can be used on any number of threads. Lexbor’s
lxb_selectors_tkeeps state per search, so it can’t be.
The calls side by side
Section titled “The calls side by side”Every Lexbor call on this page, with its Parsec equivalents
| You do this in Lexbor | In Parsec’s C API | In Rust | Notes |
|---|---|---|---|
lxb_html_document_create, lxb_html_document_parse(doc, html, len) (document.h) |
parsec_parse(html, len, 0, &doc) |
parsec::parse(html, scripting) |
One call; returns the document. parsec_parse_with and parse_with add a budget and a depth limit. |
lxb_html_document_destroy(doc) |
parsec_document_free(doc) |
drop the Document |
|
lxb_html_parser_scripting_set (parser.h) |
the PARSEC_SCRIPTING flag |
the scripting argument, or Options::scripting |
|
lxb_html_document_parse_chunk_begin and friends |
not yet | not yet | #6 |
lxb_html_document_parse_fragment(doc, element, html, len) |
parsec_parse_fragment(html, len, PARSEC_NS_HTML, "div", 3, 0, &frag) |
parsec::parse_fragment(html, Ns::Html, "div", scripting) |
Takes the context’s namespace and name, not an element, and returns a separate document. See Fragments. |
lxb_css_parser_create, lxb_css_parser_init, lxb_css_selectors_parse(parser, s, len) (css/selectors/selectors.h) |
parsec_selector_compile(s, len, &sel, &message) |
SelectorList::parse(s) |
One call, no parser object. The error comes back with a message saying what’s wrong. |
lxb_css_selector_list_destroy_memory(list), lxb_css_parser_destroy |
parsec_selector_free(sel) |
drop the SelectorList |
|
lxb_selectors_create, lxb_selectors_init, lxb_selectors_find(sel, root, list, cb, ctx) (selectors/selectors.h) |
parsec_select(doc, sel, root, cb, ctx) |
list.select(&doc, root), or select_iter |
No engine object. The callback gets a node number and your ctx, and returns nonzero to stop. root itself is never included. |
LXB_SELECTORS_OPT_MATCH_FIRST |
parsec_select_first(doc, sel, root) |
list.select_first(&doc, root) |
Returns the node, or PARSEC_NO_NODE. |
lxb_selectors_match_node(sel, node, list, cb, ctx) |
parsec_matches(doc, sel, node) |
list.matches(&doc, node, None) |
Returns bool. |
lxb_dom_node_text_content(node, &len) (node.h), then lxb_dom_document_destroy_text |
parsec_text(doc, node, &len), then parsec_string_free |
doc.text(node) |
A copy, NUL-terminated in C. |
lxb_dom_node_text_content_set(node, text, len) |
remove the children, then parsec_create_text and parsec_append |
the same, with create_text and append |
See Setting text. |
lxb_html_serialize_tree_str(node, &str) (serialize.h), then lexbor_str_destroy |
parsec_outer_html(doc, node, &len), then parsec_string_free |
doc.outer_html(node) |
|
lxb_html_serialize_deep_str(node, &str) |
parsec_inner_html(doc, node, &len) |
doc.inner_html(node) |
|
lxb_html_serialize_pretty_tree_str |
not yet | not yet | #9 |
lxb_dom_element_get_attribute(el, name, len, &vlen) (element.h) |
parsec_attr_get(doc, el, name, len, &vlen) |
doc.attrs(el).find(|a| a.1 == name).map(|a| a.2) |
Borrowed, NULL if there’s none. |
lxb_dom_element_has_attribute |
parsec_attr_get(...) != NULL |
doc.attrs(el).any(|a| a.1 == name) |
|
lxb_dom_element_set_attribute(el, name, len, value, vlen) |
parsec_attr_set(doc, el, name, len, value, vlen) |
doc.set_attr(el, name, value) |
Lowercases the name on HTML elements; replaces or adds. |
lxb_dom_element_remove_attribute(el, name, len) |
parsec_attr_remove(doc, el, name, len, &removed) |
doc.remove_attr(el, name) |
Says whether there was one. |
lxb_dom_element_first_attribute, lxb_dom_element_next_attribute |
parsec_attr_count and parsec_attr_at(doc, el, i, ...) |
doc.attrs(el) |
In source order. |
lxb_dom_element_local_name(el, &len) |
parsec_node_name(doc, el, &len) |
doc.lower_name(el), or doc.kind(el) |
Parsec’s C call gives SVG’s case (foreignObject), as kind does. |
node->type (LXB_DOM_NODE_TYPE_*) |
parsec_node_type(doc, node) (PARSEC_NODE_*) |
doc.kind(node) |
The same numbers: 1 for an element, 3 for text, 8 for a comment, 9 for the document. |
lxb_dom_node_first_child, lxb_dom_node_next, lxb_dom_node_parent |
parsec_first_child, parsec_next_sibling, parsec_parent |
doc.first_child(n), doc.next_sibling(n), doc.parent(n) |
PARSEC_NO_NODE in C and None in Rust where Lexbor gives NULL. Also last_child and prev_sibling, and children(n) in Rust. |
lxb_dom_document_create_element(doc, name, len, NULL) (document.h) |
parsec_create_element(doc, PARSEC_NS_HTML, name, len) |
doc.create_element(Ns::Html, name) |
Give the namespace. |
lxb_dom_document_create_text_node(doc, text, len) |
parsec_create_text(doc, text, len) |
doc.create_text(text) |
|
lxb_dom_node_insert_child(to, node) |
parsec_append(doc, to, node) |
doc.append(to, node) |
Refuses cycles. |
lxb_dom_node_insert_before(to, node) |
parsec_insert_before(doc, parent_of_to, node, to) |
doc.insert_before(parent_of_to, node, Some(to)) |
Lexbor’s to is the sibling; Parsec takes the parent and the sibling. |
lxb_dom_node_insert_after(to, node) |
parsec_insert_before(doc, parent_of_to, node, parsec_next_sibling(doc, to)) |
doc.insert_before(parent_of_to, node, doc.next_sibling(to)) |
PARSEC_NO_NODE as the sibling puts it last. |
lxb_dom_node_remove(node) |
parsec_detach(doc, node) |
doc.detach(node) |
Out of the tree and still usable, to insert again. |
lxb_dom_node_destroy, lxb_dom_node_destroy_deep |
parsec_remove(doc, node) |
doc.remove(node) |
Takes it out for good, with everything in it. Nothing to free: the memory goes with the document, and the node reads as nothing until then. lxb_dom_node_destroy leaves the children; to keep them, move them out first. |
In C, side by side
Section titled “In C, side by side”The same program, both ways. It parses a list, finds the items with a class, prints their text and the first one’s markup, changes attributes, adds and removes items, and parses a fragment. Both print:
match: onematch: threeouter: <li class="hit">one</li>class: hitinner: <li>zero</li><li title="First">one</li><li class="hit">three</li>fragment: <tr><td>1</td><td>2</td></tr>Lexbor’s version includes lexbor/html/html.h, lexbor/css/css.h and lexbor/selectors/selectors.h, and builds with -DLEXBOR_STATIC against liblexbor_static.a. Parsec’s includes parsec.h and links libparsec (Linking). The blocks follow on from each other, as one program, so a variable from one is used in the next. The return values a real program would check are left out of both, except for the parse and the selector.
Parsing and selecting
Section titled “Parsing and selecting”Lexbor:
static lxb_status_t on_match(lxb_dom_node_t *node, lxb_css_selector_specificity_t spec, void *ctx) { (void) spec; lxb_dom_node_t **first = ctx; if (*first == NULL) *first = node; size_t len; lxb_char_t *text = lxb_dom_node_text_content(node, &len); printf("match: %.*s\n", (int) len, (const char *) text); lxb_dom_document_destroy_text(node->owner_document, text); return LXB_STATUS_OK;}
int main(void) { static const lxb_char_t html[] = "<ul><li class=hit>one<li>two<li class=hit>three</ul>"; lxb_html_document_t *doc = lxb_html_document_create(); if (lxb_html_document_parse(doc, html, sizeof(html) - 1) != LXB_STATUS_OK) return 1;
lxb_css_parser_t *parser = lxb_css_parser_create(); lxb_css_parser_init(parser, NULL); lxb_selectors_t *selectors = lxb_selectors_create(); lxb_selectors_init(selectors); lxb_css_selector_list_t *list = lxb_css_selectors_parse(parser, (const lxb_char_t *) "li.hit", 6); if (parser->status != LXB_STATUS_OK) return 1;
lxb_dom_node_t *first = NULL; lxb_selectors_find(selectors, lxb_dom_interface_node(doc), list, on_match, &first);
lexbor_str_t str = {0}; lxb_html_serialize_tree_str(first, &str); printf("outer: %.*s\n", (int) str.length, (const char *) str.data); lexbor_str_destroy(&str, first->owner_document->text, false);Parsec:
static int on_match(parsec_node node, void *ctx) { const parsec_document *doc = ctx; size_t len; char *text = parsec_text(doc, node, &len); printf("match: %.*s\n", (int) len, text); parsec_string_free(text); return 0; /* nonzero stops */}
int main(void) { static const char html[] = "<ul><li class=hit>one<li>two<li class=hit>three</ul>"; parsec_document *doc; if (parsec_parse(html, sizeof(html) - 1, 0, &doc) != PARSEC_OK) return 1;
parsec_selector *sel; char *why; if (parsec_selector_compile("li.hit", 6, &sel, &why) != PARSEC_OK) { fprintf(stderr, "bad selector: %s\n", why); parsec_string_free(why); return 1; }
parsec_select(doc, sel, parsec_root(), on_match, doc); parsec_node first = parsec_select_first(doc, sel, parsec_root());
size_t len; char *outer = parsec_outer_html(doc, first, &len); printf("outer: %.*s\n", (int) len, outer); parsec_string_free(outer);Where Lexbor needs a CSS parser and a selectors engine, each created, initialised and destroyed, Parsec compiles the selector into one value you can keep. Lexbor’s callback gets the specificity too; Parsec’s gets the node and your ctx, and returns nonzero to stop where Lexbor’s returns a status.
Reading and changing attributes
Section titled “Reading and changing attributes”Lexbor:
lxb_dom_element_t *li = lxb_dom_interface_element(first); size_t vlen; const lxb_char_t *cls = lxb_dom_element_get_attribute(li, (const lxb_char_t *) "class", 5, &vlen); printf("class: %.*s\n", (int) vlen, (const char *) cls); lxb_dom_element_set_attribute(li, (const lxb_char_t *) "title", 5, (const lxb_char_t *) "First", 5); lxb_dom_element_remove_attribute(li, (const lxb_char_t *) "class", 5);Parsec:
size_t vlen; const char *cls = parsec_attr_get(doc, first, "class", 5, &vlen); printf("class: %.*s\n", (int) vlen, cls); parsec_attr_set(doc, first, "title", 5, "First", 5); parsec_attr_remove(doc, first, "class", 5, NULL);Adding and removing nodes
Section titled “Adding and removing nodes”Lexbor:
lxb_dom_document_t *dom = lxb_dom_interface_document(doc); lxb_dom_element_t *zero = lxb_dom_document_create_element(dom, (const lxb_char_t *) "li", 2, NULL); lxb_dom_text_t *t = lxb_dom_document_create_text_node(dom, (const lxb_char_t *) "zero", 4); lxb_dom_node_insert_child(lxb_dom_interface_node(zero), lxb_dom_interface_node(t)); /* zero goes before first. */ lxb_dom_node_insert_before(first, lxb_dom_interface_node(zero)); /* The second li goes. */ lxb_dom_node_t *two = lxb_dom_node_next(first); lxb_dom_node_remove(two); lxb_dom_node_destroy_deep(two);
lxb_dom_node_t *ul = lxb_dom_node_parent(first); lexbor_str_t inner = {0}; lxb_html_serialize_deep_str(ul, &inner); printf("inner: %.*s\n", (int) inner.length, (const char *) inner.data); lexbor_str_destroy(&inner, dom->text, false);Parsec:
parsec_node zero = parsec_create_element(doc, PARSEC_NS_HTML, "li", 2); parsec_append(doc, zero, parsec_create_text(doc, "zero", 4)); /* zero goes before first: Parsec takes the parent too. */ parsec_node ul = parsec_parent(doc, first); parsec_insert_before(doc, ul, zero, first); /* The second li goes for good: two reads as nothing from here on, and * its memory goes with the document. */ parsec_node two = parsec_next_sibling(doc, first); parsec_remove(doc, two);
char *inner = parsec_inner_html(doc, ul, &len); printf("inner: %.*s\n", (int) len, inner); parsec_string_free(inner);A fragment
Section titled “A fragment”Lexbor:
lxb_dom_element_t *tbody = lxb_dom_document_create_element(dom, (const lxb_char_t *) "tbody", 5, NULL); static const lxb_char_t rows[] = "<tr><td>1<td>2"; lxb_dom_node_t *frag = lxb_html_document_parse_fragment(doc, tbody, rows, sizeof(rows) - 1); lexbor_str_t f = {0}; lxb_html_serialize_deep_str(frag, &f); printf("fragment: %.*s\n", (int) f.length, (const char *) f.data); lexbor_str_destroy(&f, dom->text, false);Parsec:
static const char rows[] = "<tr><td>1<td>2"; parsec_document *frag; parsec_parse_fragment(rows, sizeof(rows) - 1, PARSEC_NS_HTML, "tbody", 5, 0, &frag); char *f = parsec_inner_html(frag, parsec_root(), &len); printf("fragment: %.*s\n", (int) len, f); parsec_string_free(f); parsec_document_free(frag);Lexbor parses the fragment into the document you pass, under a context element you made, and returns an html element holding the result. Parsec gives you a document of its own, whose root is a fragment node.
Cleaning up
Section titled “Cleaning up”/* Lexbor */lxb_selectors_destroy(selectors, true);lxb_css_parser_destroy(parser, true);lxb_css_selector_list_destroy_memory(list);lxb_html_document_destroy(doc);
/* Parsec */parsec_selector_free(sel);parsec_document_free(doc);In Rust
Section titled “In Rust”The same calls from Rust, where there’s nothing to free and node ids are NodeIds.
Parsing a document
Section titled “Parsing a document”use parsec::css::SelectorList;
// lxb_html_document_create + lxb_html_document_parselet doc = parsec::parse("<div><p class=a>one</p><p>two</p></div>", false);
// lxb_css_parser_create + lxb_css_selectors_parse + lxb_selectors_findlet list = SelectorList::parse("p.a").unwrap();for p in list.select(&doc, doc.root()) { // lxb_dom_node_text_content assert_eq!(doc.text(p), "one"); // lxb_html_serialize_tree_str assert_eq!(doc.outer_html(p), r#"<p class="a">one</p>"#);}// lxb_html_document_destroy: nothing, doc is dropped here.Attributes
Section titled “Attributes”use parsec::css::SelectorList;
let mut doc = parsec::parse(r#"<a href="/old" target=_blank>link</a>"#, false);let a = SelectorList::parse("a").unwrap().select(&doc, doc.root())[0];
// lxb_dom_element_get_attributelet href = doc.attrs(a).find(|a| a.1 == "href").map(|a| a.2.to_string());assert_eq!(href.as_deref(), Some("/old"));
// lxb_dom_element_has_attributeassert!(doc.attrs(a).any(|a| a.1 == "target"));
// lxb_dom_element_set_attributedoc.set_attr(a, "href", "/new").unwrap();// lxb_dom_element_remove_attributeassert!(doc.remove_attr(a, "target"));
assert_eq!(doc.outer_html(a), r#"<a href="/new">link</a>"#);Inserting and removing nodes
Section titled “Inserting and removing nodes”Lexbor’s insert_before(to, node) puts node before the sibling to. Parsec’s insert_before(parent, node, before) takes the parent too, so you look it up:
use parsec::css::SelectorList;use parsec::Ns;
let mut doc = parsec::parse("<ul><li id=b>b</li></ul>", false);let b = SelectorList::parse("#b").unwrap().select(&doc, doc.root())[0];let ul = doc.parent(b).unwrap();
let new_li = |doc: &mut parsec::Document, text: &str| { let li = doc.create_element(Ns::Html, "li").unwrap(); let t = doc.create_text(text); doc.append(li, t).unwrap(); li};
// lxb_dom_node_insert_before(b, a): a goes before b.let a = new_li(&mut doc, "a");doc.insert_before(ul, a, Some(b)).unwrap();
// lxb_dom_node_insert_after(b, c): c goes after b.let c = new_li(&mut doc, "c");doc.insert_before(ul, c, doc.next_sibling(b)).unwrap();
// lxb_dom_node_insert_child(ul, d): d goes last.let d = new_li(&mut doc, "d");doc.append(ul, d).unwrap();
// lxb_dom_node_destroy_deep(b). For lxb_dom_node_remove(b) alone, to// put b somewhere else, it's doc.detach(b).doc.remove(b);
assert_eq!(doc.inner_html(ul), "<li>a</li><li>c</li><li>d</li>");Setting text
Section titled “Setting text”There’s no textContent setter. Remove the children and add one text node:
use parsec::css::SelectorList;use parsec::{Document, NodeId};
fn set_text(doc: &mut Document, el: NodeId, text: &str) { let kids: Vec<NodeId> = doc.children(el).collect(); for kid in kids { doc.remove(kid); } let t = doc.create_text(text); doc.append(el, t).unwrap();}
let mut doc = parsec::parse("<p>old <b>bold</b></p>", false);let p = SelectorList::parse("p").unwrap().select(&doc, doc.root())[0];set_text(&mut doc, p, "new & improved");assert_eq!(doc.outer_html(p), "<p>new & improved</p>");Fragments
Section titled “Fragments”lxb_html_document_parse_fragment parses into the document you give it, under a context element you made. Parsec’s parse_fragment takes the context’s namespace and name and returns a document of its own, whose root is a Fragment node holding the result:
use parsec::Ns;
// As if setting innerHTML on a <tbody>.let frag = parsec::parse_fragment("<tr><td>1<td>2", Ns::Html, "tbody", false);assert_eq!(frag.inner_html(frag.root()), "<tr><td>1</td><td>2</td></tr>");There’s no function to move nodes from one document into another yet. If you need the equivalent of setting innerHTML on an element of an existing document, copy the fragment’s nodes across. This helper does it for elements, text, comments and processing instructions, which is everything a fragment parse produces; it recurses once per level, so it’s for fragments of ordinary depth.
The import and set_inner_html helpers, about 70 lines
use parsec::css::SelectorList;use parsec::{AttrNs, Document, Kind, NodeId};
/// Copies `node` and everything under it from `src` into `dst`, detached,/// and returns the copy.fn import(dst: &mut Document, src: &Document, node: NodeId) -> Option<NodeId> { let copy = match src.kind(node) { Kind::Element { ns, name } => { let el = dst.create_element_as_parsed(ns, name); // The stored name for plain attributes, the written one (with // its prefix) for namespaced ones: what the parser would store. let attrs: Vec<(AttrNs, String, String)> = src .attrs(node) .zip(src.attrs_written(node)) .map(|((ns, stored, value), (_, written, _))| { let name = if ns == AttrNs::None { stored } else { written }; (ns, name.to_string(), value.to_string()) }) .collect(); // As parsed: a page can have names set_attr would refuse. for (ns, name, value) in &attrs { dst.add_attr_as_parsed(el, *ns, name, value); } if let (Some(from), Some(to)) = (src.template_contents(node), dst.template_contents(el)) { for child in src.children(from).collect::<Vec<_>>() { if let Some(c) = import(dst, src, child) { dst.append(to, c).unwrap(); } } } el } Kind::Text(t) => dst.create_text(t), Kind::Comment(c) => dst.create_comment(c), Kind::ProcessingInstruction { target, data } => dst.create_processing_instruction(target, data), Kind::Cdata(t) => dst.create_cdata(t), Kind::Document | Kind::Fragment | Kind::ShadowRoot(_) | Kind::Doctype { .. } => return None, }; for child in src.children(node).collect::<Vec<_>>() { if let Some(c) = import(dst, src, child) { dst.append(copy, c).unwrap(); } } Some(copy)}
/// Replaces `el`'s children with `html`, parsed in `el`'s context.fn set_inner_html(doc: &mut Document, el: NodeId, html: &str) { let (ns, name) = match doc.kind(el) { Kind::Element { ns, name } => (ns, name.to_string()), _ => return, }; let frag = parsec::parse_fragment(html, ns, &name, false); for kid in doc.children(el).collect::<Vec<_>>() { doc.remove(kid); } for kid in frag.children(frag.root()).collect::<Vec<_>>() { if let Some(copy) = import(doc, &frag, kid) { doc.append(el, copy).unwrap(); } }}
fn main() { let mut doc = parsec::parse("<table><tbody><tr><td>old</td></tr></tbody></table>", false); let tbody = SelectorList::parse("tbody").unwrap().select(&doc, doc.root())[0]; set_inner_html(&mut doc, tbody, "<tr><td>a<td>b</tr>"); assert_eq!(doc.inner_html(tbody), "<tr><td>a</td><td>b</td></tr>"); assert_eq!(SelectorList::parse("td").unwrap().select(&doc, doc.root()).len(), 2);}Selectors that behave differently
Section titled “Selectors that behave differently”Most selectors match the same in both. The differences you’re likely to meet, all listed on Selectors:
:scopematches the element you query from in Parsec. Lexbor parses it and never matches it (lexbor#257).:hover,:activeand:focusnever match in Parsec. Lexbor matches them on elements that have an attribute of the same name (selectors.c).:lang()and:dir()match in Parsec, fromlang,xml:langanddirin the markup. Lexbor parses them and never matches them.:targetand:local-linkmatch in Parsec once you give the page’s URL:select_with(&doc, scope, &MatchOptions { url: Some(url), ..Default::default() })in Rust. Without one they match nothing, as in Lexbor; the C API has no way to pass the URL yet, so from C they match nothing.:default,:indeterminate,:valid,:invalid,:in-rangeand:out-of-rangematch in Parsec, from the form’s markup. Lexbor parses them and never matches them.- Selectors Lexbor parses but never matches and Parsec doesn’t support yet, such as
:blankand pseudo-elements, are errors in Parsec, so a query can’t quietly find nothing. :lexbor-contains()is Lexbor’s own and Parsec refuses it. Filter ondoc.text(id), orparsec_textin C, instead.[href]means anhrefin no namespace, as in a browser; use[*|href]to include SVG’sxlink:href.selectnever includes the node you run it on. If you used Lexbor’s option to match the root too, test the root withmatchesas well.
What isn’t there yet
Section titled “What isn’t there yet”Each has an issue: chunked parsing (#6), parse errors (#7), pretty serialization (#9), the CSS parser and CSSOM (#28), URL parsing (#26), and the C API itself (#20). Not tracked by any issue today: cloning nodes, importing between documents, and DOM mutation callbacks.
The C API also has no call yet for a few things the Rust API does, listed on C API.
If something you rely on in Lexbor isn’t on this page, tell us in Discussions, and it goes on the list.
See also
Section titled “See also”- C API, the C reference.
- Comparison with Lexbor, for what each library has, module by module.
- Selectors, for the full list of what matches.
- FAQ, for the questions people ask first.