# html/text
Extract readable plain text from HTML: script/style/head/template
content is dropped, block tags and `<br>` become line breaks, list items
get a `- ` prefix, table cells join with ` | `, and whitespace collapses
the way a browser renders it. Entities are decoded by the parser.
## Syntax
[html/text $src|$doc ?opts]
## Parameters
- `$src` — HTML source text (string) or a `%HtmlDocument` handle from
`html/open`
- `$opts` — optional map:
- `:links true` — append ` (href)` after anchor text
- `:images true` — render `[image: alt]` for `<img>` elements
- `:selector "css"` — extract text from the matching subtrees only
- `:encoding string|:auto`, `:fragment true` — parse options, when
`$src` is a string (same as `html/parse`)
## Examples
[html/text "<h1>T</h1><p>Hello <b>world</b>!</p><ul><li>a<li>b</ul>"] # => "T\n\nHello world!\n\n- a\n- b" [html/text "see <a href='https://deft-lang.org'>docs</a> now" %{ :links true }] # => "see docs (https://deft-lang.org) now" # Only the matched region [html/text "<div class=main>wanted</div><div>noise</div>" %{ :selector "div.main" }] # => "wanted" # Script bodies never leak through [html/text "<p>keep</p><script>evil()</script><style>.a{}</style>"] # => "keep"
## Returns
A string, trimmed, with runs of blank lines collapsed to one blank line.
Block semantics: paragraph-level tags (`p`, `h1`–`h6`, lists, tables,
`blockquote`, `pre`, …) separate with a blank line; line-level tags
(`div`, `li`, `tr`, …) with a single newline. `<pre>` keeps its text
verbatim; ` ` survives as U+00A0 (not an ASCII space), so use
`width`/`cells` when laying the result out.
Failures return `%Err{ :message "..." }`.
## See Also
`html/parse`, `html/open`, `html/select`, `html/decode-entities`