Language guide · 03
Filters
Filters transform values before Knap writes them. Browse the complete library, then open any filter for tested input, template, and output examples.
Use filters
Add a filter after a pipe. Parameters follow the filter name after a colon, and chains run from left to right.
1{{ title | trim | upper }}2{{ published | date:"YYYY-MM-DD" }}3{{ tags | unique | join:", " }}Filter directory
Open search from the header or press ⌘K to find a filter by name, alias, category, or behavior. Every page includes at least one copyable example.
Dates and time
Parse, adjust, and format dates or durations.
Text
Normalize case, spacing, file names, and encoded text.
camelConvert text to camelCase.
camelcapitalizeUppercase the first character and lowercase the rest.
capitalizedecode_uriDecode percent-encoded URI text.
decode_urikebabConvert text to kebab-case.
kebablowerConvert text to lowercase.
lowerpascalConvert text to PascalCase.
pascalreplaceReplace one or more strings or regular expressions.
replace:"old":"new"safe_nameRemove characters that are unsafe in file names.
safe_namesnakeConvert text to snake_case.
snaketitleConvert text to Title Case.
titletrimRemove whitespace from both ends of a value.
trimuncamelConvert camelCase or PascalCase to spaced lowercase text.
uncamelunescapeTurn escaped quotes and newlines into literal characters.
unescapeupperConvert text to uppercase.
upperMarkdown
Create links, callouts, lists, tables, and other Markdown structures.
blockquotePrefix every line as a Markdown blockquote.
blockquotecalloutCreate an Obsidian callout.
calloutfootnoteConvert an array or object to Markdown footnote definitions.
footnotefragment_linkAdd a source URL with a text-fragment anchor to highlights.
fragment_link:"https://example.com"imageCreate Markdown image syntax from a URL, array, or object.
imagelinkCreate Markdown links from a URL, array, or object.
linklistConvert a value or array to a Markdown list.
listtableConvert arrays or objects to a Markdown table.
tablewikilinkCreate an Obsidian wikilink.
wikilinkyamlQuote a value safely for a YAML scalar.
yamlNumbers
Calculate, round, and format numeric values.
Collections
Select, reshape, combine, and render arrays and objects.
firstReturn the first item in an array.
firstjoinJoin array items with an optional separator.
joinlastReturn the last item in an array.
lastlengthCount string characters, array items, or object keys.
lengthmapMap array items with a small arrow-function expression.
map:item => item.namemergeAppend one or more values to an array.
merge:"value"nthSelect positions from an array with nth-pattern syntax.
nth:3objectConvert an object to keys, values, or key-value pairs.
object:keysreverseReverse a string or array.
reversesliceExtract part of a string or array.
slice:1splitSplit a string into a JSON array.
splittemplateRender each array item with a small ${property} template.
template:"${name}"uniqueRemove duplicate array items.
uniqueHTML cleanup
Clean markup while preserving the pieces a Markdown workflow needs.
remove_attrRemove selected attributes from HTML tags.
remove_attr:"class"remove_tagsRemove selected HTML tags but keep their content.
remove_tags:"b"replace_tagsRename selected HTML tags while preserving content.
replace_tags:"strong":"h2"strip_attrRemove every HTML attribute except an optional allowlist.
strip_attrstrip_mdalias: stripmdRemove Markdown formatting while keeping readable text.
strip_mdstrip_tagsRemove all HTML tags except an optional allowlist.
strip_tagsHTML preset
DOM-dependent filters exported separately from knap/html.
Opt into the HTML preset
html_to_json and remove_html require browser-compatible DOM globals, so they are exported separately from knap/html.
1import { createEngine, standardFilters } from 'knap';2import { htmlFilters } from 'knap/html';34const engine = createEngine({5 filters: { ...standardFilters, ...htmlFilters },6});Register a custom filter
Custom filters may be synchronous or asynchronous. Attach metadata when the editor should validate parameters before rendering.
1import { createEngine, standardFilters, type TemplateFilter } from 'knap';23const surround: TemplateFilter = (value, param = '') => {4 const marker = param.replace(/^(['"])(.*)\1$/s, '$2');5 return marker + value + marker;6};78surround.metadata = { example: 'surround:"**"' };910const engine = createEngine({11 filters: { ...standardFilters, surround },12});A filter can call context.reportWarning() when it preserves a fallback value but wants the host to surface a non-fatal diagnostic.