html/dom
WHATWG HTML parsing into a dom-core Document, via lexbor.
Since: 0.1.0
HtmlOpts
(defstruct HtmlOpts :copy [max-depth : int max-bytes : int])
caps for one HTML parse.
default-html-opts
(default-html-opts :)
depth 512 (Blink's limit), 64 MiB of input.
HtmlOpts
(html-parse-opts src (default-html-opts))
Since: 0.1.0
html-backend-version
(html-backend-version :)
the linked lexbor's version string.
cstr -- static, e.g. "3.0.1".
(println (html-backend-version))
Since: 0.1.0
html-parse
(html-parse [src : cstr] :)
parse a whole HTML document. Never fails.
| src | the document (UTF-8) |
Document -- always; release it with `dom-free`.
(let [d (html-parse "<p>one<p>two")]
(tlength (find-all (dom-node d) "p")) ; => 2
(dom-free d))
Since: 0.1.0
html-parse-opts
(html-parse-opts [src : cstr opts : HtmlOpts] :)
parse a whole HTML document with explicit caps.
| src | the document | |
| opts | depth and byte caps |
(Result Document ParseError) -- err (kind Limit) only when the input is longer than max-bytes.
(html-parse-opts src (with (default-html-opts) [max-depth 32]))
Since: 0.1.0
html-parse-fragment
(html-parse-fragment [context : cstr src : cstr] :)
parse markup as the contents of an element.
| context | the context element's tag name ("body", "tr", "select", ...) | |
| src | the markup |
Document -- always; release it with `dom-free`.
(node-child-count (dom-node (html-parse-fragment "tr" "<td>a<td>b"))) ; => 2
Since: 0.1.0
html-parse-fragment-opts
(html-parse-fragment-opts [context : cstr src : cstr opts : HtmlOpts])
`html-parse-fragment` with explicit caps.
| context | the context element's tag name | |
| src | the markup | |
| opts | depth and byte caps |
(Result Document ParseError)
(html-parse-fragment-opts "div" src (default-html-opts))
Since: 0.1.0
html-parse-file-opts
(html-parse-file-opts [path : cstr opts : HtmlOpts])
parse an HTML file with explicit caps.
| path | the file (UTF-8) | |
| opts | depth and byte caps |
(Result Document ParseError) -- Io when the file cannot be read, Limit when it is longer than max-bytes.
(html-parse-file-opts "page.html" (with (default-html-opts) [max-bytes 0]))
Since: 0.1.0
html-parse-file
(html-parse-file [path : cstr] :)
parse an HTML file with the default caps.
| path | the file |
(Result Document ParseError)
(html-parse-file "index.html")
Since: 0.1.0
Internal definitions
__null?-- internal.__parse-raw-- internal: a turdom_doc, or NULL with the error recorded.__fragment-raw-- internal: a turdom_doc for a fragment, or NULL.__file-raw-- internal: a turdom_doc for a file, or NULL.__must-- internal: a never-fails parse result; only OOM yields NULL.__err-kind-- internal.__err-msg-- internal.__error-- internal: the recorded error (msg copied).__wrap-- internal: a nullable tree as a Result.