A Clojure library for parsing, sanitising and escaping HTML, built on jsoup.
A Clojure library for parsing, sanitising and escaping HTML, built on jsoup.
(attr el k)Returns the value of attribute k of el, or nil when it is absent.
k can be a string or a keyword.
Returns the value of attribute `k` of `el`, or nil when it is absent. `k` can be a string or a keyword.
(attrs el)Returns the attributes of el as a map of keyword to string.
Returns the attributes of `el` as a map of keyword to string.
(body-html doc)Returns the inner HTML of the document body as a string.
Returns the inner HTML of the document body as a string.
(clean html)(clean html opts)Removes everything from the html string that is not allowed by a
safelist, so that untrusted markup can be embedded safely. Returns a
string.
Options:
:safelist one of :none, :simple-text, :basic (default),
:basic-with-images, :relaxed.:add-tags tags to allow in addition to the safelist, e.g. [:section].:remove-tags tags to disallow.:add-attributes map of tag to attributes to allow,
e.g. {:a [:target] :all [:class]}.:remove-attributes same shape, to disallow attributes.:base-uri base used to resolve relative links, default "". Without
it, relative links cannot be resolved and are removed.:preserve-relative-links keep relative URLs as they are instead of
making them absolute. Still requires :base-uri.:pretty-print boolean, default false.:escape-mode one of :base, :xhtml, :extended.Removes everything from the `html` string that is not allowed by a
safelist, so that untrusted markup can be embedded safely. Returns a
string.
Options:
- `:safelist` one of :none, :simple-text, :basic (default),
:basic-with-images, :relaxed.
- `:add-tags` tags to allow in addition to the safelist, e.g. [:section].
- `:remove-tags` tags to disallow.
- `:add-attributes` map of tag to attributes to allow,
e.g. {:a [:target] :all [:class]}.
- `:remove-attributes` same shape, to disallow attributes.
- `:base-uri` base used to resolve relative links, default "". Without
it, relative links cannot be resolved and are removed.
- `:preserve-relative-links` keep relative URLs as they are instead of
making them absolute. Still requires `:base-uri`.
- `:pretty-print` boolean, default false.
- `:escape-mode` one of :base, :xhtml, :extended.(escape-html s)(escape-html s opts)Escapes s so it is safe to embed as HTML text.
Takes the same :escape-mode and :pretty-print options as parse
(default :base).
Escapes `s` so it is safe to embed as HTML text. Takes the same `:escape-mode` and `:pretty-print` options as `parse` (default :base).
(jsoup-version)Returns the version of the jsoup library found on the classpath, as a
string. It can differ from the version montalivet was built with when
another dependency brings its own jsoup. The output of clean and
escape-html can change between jsoup versions.
Returns the version of the jsoup library found on the classpath, as a string. It can differ from the version montalivet was built with when another dependency brings its own jsoup. The output of `clean` and `escape-html` can change between jsoup versions.
(outer-html el)Returns the markup of el itself, including its own tag.
Returns the markup of `el` itself, including its own tag.
(parse input)(parse input opts)Parses input as a full HTML document and returns a jsoup Document.
input can be a String of HTML, a java.io.File, a java.nio.file.Path or
a java.io.InputStream. Any other type throws an exception. A stream is
read to its end but not closed.
Options:
:pretty-print boolean, default true.:escape-mode one of :base, :xhtml, :extended.:base-uri base used to resolve relative links. Defaults to ""
for a String or an InputStream, and to the location of
the file for a File or a Path.:charset charset of a File, Path or InputStream, as a string
("ISO-8859-1") or a java.nio.charset.Charset. When
absent, it is detected from a byte-order mark or a
<meta> tag, with UTF-8 as the fallback. Ignored for
a String.Parses `input` as a full HTML document and returns a jsoup Document.
`input` can be a String of HTML, a java.io.File, a java.nio.file.Path or
a java.io.InputStream. Any other type throws an exception. A stream is
read to its end but not closed.
Options:
- `:pretty-print` boolean, default true.
- `:escape-mode` one of :base, :xhtml, :extended.
- `:base-uri` base used to resolve relative links. Defaults to ""
for a String or an InputStream, and to the location of
the file for a File or a Path.
- `:charset` charset of a File, Path or InputStream, as a string
("ISO-8859-1") or a java.nio.charset.Charset. When
absent, it is detected from a byte-order mark or a
`<meta>` tag, with UTF-8 as the fallback. Ignored for
a String.(parse-fragment html)(parse-fragment html opts)Parses the html string as a fragment of a document body, and returns
a jsoup Document whose body holds the fragment.
Unlike parse, every element stays in the body: parse moves elements
such as <title> or <meta> to the head.
Options: :pretty-print, :escape-mode and :base-uri, as in parse.
Parses the `html` string as a fragment of a document body, and returns a jsoup Document whose body holds the fragment. Unlike `parse`, every element stays in the body: `parse` moves elements such as `<title>` or `<meta>` to the head. Options: `:pretty-print`, `:escape-mode` and `:base-uri`, as in `parse`.
(select doc query)Returns a vector of the elements of doc that match the CSS selector
query, in document order. doc can be a Document or any element, in
which case only its descendants are searched. Returns an empty vector
when nothing matches.
See https://jsoup.org/cookbook/extracting-data/selector-syntax for the selector syntax. An empty or invalid selector throws an exception.
Returns a vector of the elements of `doc` that match the CSS selector `query`, in document order. `doc` can be a Document or any element, in which case only its descendants are searched. Returns an empty vector when nothing matches. See https://jsoup.org/cookbook/extracting-data/selector-syntax for the selector syntax. An empty or invalid selector throws an exception.
(select-one doc query)Returns the first element of doc that matches the CSS selector query,
or nil when nothing matches.
Returns the first element of `doc` that matches the CSS selector `query`, or nil when nothing matches.
(text el)Returns the combined, whitespace-normalised text of el and its children.
Returns the combined, whitespace-normalised text of `el` and its children.
(version)Returns the version of montalivet as a string, e.g. "0.1.3".
Returns the version of montalivet as a string, e.g. "0.1.3".
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |