The :code
filter wraps a content with the <code>
tag and a custom class name.
Enable filter
Defaults, the filter is disabled. If this filter is used, it must be enabled in webpack.config.js
.
{
test: /.pug$/,
loader: '@webdiscus/pug-loader',
options: {
// enable embedded filters
embedFilters: {
// enable the :code filter
code: {
className: 'language-', // class name of `<code>` tag, needed for `prismjs` theme
},
},
},
},
The filter options:
className {string}
This string will be added to class name of the<code class="CLASS_NAME">
tag. For example, theprismjs
use thelanguage-*
as class name in<code>
tag for styling this tag.
The usage of inline filter #[:code ...]
is equivalent to inline tag #[code.language- ...]
,
but using the #[:code]
filter a class name can be defined at initialisation and the filter can be used in combination with other as nested filter.
Inline syntax
Pug: #[:code function() { return true }]
Result: function() { return true }
:code:escape ...
to encode reserved HTML chars.See the usage of :escape filter.
Pug: #[:code:escape <div>]
is equivalent to <code class="language-">#{'<div>'}</code>
Result: <div>
:code:highlight(lang) ...
.
When used :highlight
filter for HTML code then the :escape
filter is not needed.See the usage of :highlight filter.
Pug: #[:code:highlight(html) <div class="container">content</div>]
Result: <div class="container">content</div>