cl-html5-parser is a HTML5 parser for Common Lisp with the following features:
-
It is a port of the Python library html5lib.
-
It passes all relevant tests from html5lib.
-
It is not tied to a specific DOM implementation.
-
SBCL or ECL.
-
CL-PPCRE and FLEXI-STREAMS.
Might work with CLISP, ABCL and Clozure CL, but many of the tests don’t pass there.
Parsing functions are in the package HTML5-PARSER.
f parse-html5 source &key encoding strictp ⇒ document, errors
Parse an HTML document from source. Source can be a string, a pathname or a stream. When parsing from a stream encoding detection is not supported, encoding must be supplied via the encoding keyword parameter.
When strictp is true, parsing stops on first error.
Returns two values. The primary value is the document node. The secondary value is a list of errors found during parsing. The format of this list is subject to change.
f parse-html5-fragment source &key container encoding strictp as-xmls ⇒ document-fragment, errors
Parses a fragment of HTML. Container sets the context, defaults to
"div". Returns a document-fragment node. For the other parameters see
PARSE-HTML5
.
(html5-parser:node-to-xmls (html5-parser:parse-html5-fragment "Parse <i>some</i> HTML")) ==> ("Parse " ("i" NIL "some") " HTML")
Parsing HTML5 is not possible without a DOM. cl-html5-parser defines a minimal DOM implementation for this task. Functions for traversing documents are exported by the HTML5-PARSER package.
f html5-parser:node-to-xmls node &optional include-namespace-p ⇒ list
Converts a node into a simple XMLS-like list structure. If node is a document fragement a list of XMLS nodes a returned. In all other cases a single XMLS node is returned.
This library is available under the GNU Lesser General Public License v3.0.