Liking cljdoc? Tell your friends :D

io.github.papachan.montalivet

A Clojure library for parsing, sanitising and escaping HTML, built on jsoup.

A Clojure library for parsing, sanitising and escaping HTML, built on jsoup.
raw docstring

attrclj

(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.
sourceraw docstring

attrsclj

(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.
sourceraw docstring

body-htmlclj

(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.
sourceraw docstring

cleanclj

(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.
sourceraw docstring

escape-htmlclj

(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).
sourceraw docstring

jsoup-versionclj

(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.
sourceraw docstring

outer-htmlclj

(outer-html el)

Returns the markup of el itself, including its own tag.

Returns the markup of `el` itself, including its own tag.
sourceraw docstring

parseclj

(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.
sourceraw docstring

parse-fragmentclj

(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`.
sourceraw docstring

selectclj

(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.
sourceraw docstring

select-oneclj

(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.
sourceraw docstring

textclj

(text el)

Returns the combined, whitespace-normalised text of el and its children.

Returns the combined, whitespace-normalised text of `el` and its children.
sourceraw docstring

versionclj

(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".
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close