html
In Filters
HTML-related filters for Eleventy.
cleanForRSSrequiresposthtmlas a peer dependency.renderMarkdownrequiresmarkdown-itas a peer dependency or a user-provided renderer instance.- Both are async & do not work in Handlebars; see each filter for why.
import {
stripTags,
nl2br,
cleanForRSS,
renderMarkdown,
} from '@allons-y/dashly/filters/html';
stripTags(value)
Strip every HTML tag from a string, leaving only text content. Zero-dep
regex pass — for opinionated tag-aware stripping (RSS feeds, custom
elements, permalinks), use cleanForRSS instead.
Internal whitespace is collapsed and the result is trimmed.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
string |
Returns
string
Examples
// 'Hello world'
stripTags('<p>Hello <strong>world</strong></p>');
{{ post.content | stripTags | excerpt(40) }}
nl2br(value)
Replace newline characters with <br> tags. Handles \r\n, \r, and \n.
Useful for rendering plain-text strings (form responses, YAML data) as HTML
while preserving line breaks. Preserves the trailing newline so the HTML
source stays readable.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
string |
Returns
string
Examples
// 'one<br>\ntwo<br>\nthree'
nl2br('one\ntwo\nthree');
{{ user.bio | nl2br | safe }}
cleanForRSS(html, options?)
Strip tags and elements that are unsafe or undesirable in RSS/Atom feeds.
By default this removes script/style/embed/etc. tags and header-anchor
permalink <a> elements inserted by markdown-it-anchor. Pass customTags
to strip additional tags (e.g. web components like lite-youtube).
Async, so it does not work in Handlebars. The filter returns a Promise
because it loads posthtml with a dynamic import() on first use.
Nunjucks, Liquid, & 11ty.js await it. Handlebars helpers are synchronous &
cannot await, so {{cleanForRSS html}} renders [object Promise]. Compute
the value in a data file, eleventyComputed, or a JS template instead, &
pass the resulting string to the Handlebars template.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
html
|
string |
||
options
(optional)
|
object |
||
options.unsafeTags
(optional)
|
string[] |
Override the default unsafe-tag list. | |
options.customTags
(optional)
|
string[] |
[] |
Additional tag names to strip (e.g. custom elements). |
options.stripPermalinks
(optional)
|
boolean |
true |
Remove <a class="header-anchor"> nodes. |
Returns
Promise<string>
renderMarkdown(value, options?)
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
string |
||
options
(optional)
|
object |
||
options.renderer
(optional)
|
import('markdown-it').default |
A pre-configured markdown-it instance. |
|
options.splitParagraphs
(optional)
|
boolean |
true |
Returns
Promise<string>