这是用户在 2025-6-26 11:10 为 https://help.obsidian.md/web-clipper/filters 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?
Obsidian Help

过滤器

Filters allow you to modify variables in Web Clipper templates. Filters are applied to variables using the syntax {{variable|filter}}. 

  • Filters work for any kind of variable including prompt, meta, selector, and schema variables. 
  • Filters can be chained, e.g. {{variable|filter1|filter2}}, and are applied in the order they are added. 

Dates 

转换和修改日期。

date

Converts a date to the specified format, see reference. 

  • {{date|date:"YYYY-MM-DD"}} converts the current date to "YYYY-MM-DD". 
  • Use date:("outputFormat", "inputFormat") to specify the input format, e.g. "12/01/2024"|date:("YYYY-MM-DD", "MM/DD/YYYY") parses "12/01/2024" and returns "2024-12-01". 

date_modify

Modifies a date by adding or subtracting a specified amount of time, see reference. 

  • "2024-12-01"|date_modify:"+1 year" returns "2025-12-01" 
  • "2024-12-01"|date_modify:"- 2 months" returns "2024-10-01" 

duration

Converts ISO 8601 duration strings or seconds into formatted time strings. Uses tokens: HH (padded hours), H (hours), mm (padded minutes), m (minutes), ss (padded seconds), s (seconds). 

  • "PT1H30M"|duration:"HH:mm:ss" returns "01:30:00". 
  • "3665"|duration:"H:mm:ss" returns "1:01:05". 
  • Setting duration without any parameters uses HH:mm:ss over 1 hour, mm:ss under 1 hour. 
  • 支持 ISO 8601 时间间隔字符串(例如:PT6702SPT1H30M)和单纯的秒数。

文本转换和大小写

将文本字符串从一种格式转换为另一种格式。

camel

Converts text to camelCase. 

capitalize

Capitalizes the first character of the value and converts the rest to lowercase, e.g. "hELLO wORLD"|capitalize returns "Hello world". 

kebab

Converts text to kebab-case. 

lower

Converts text to lowercase. 

pascal

将文本转换为 PascalCase

replace

替换指定文本的所有出现:

  • 简单替换:"hello!"|replace:",":"" 移除所有逗号。
  • 多次替换: "hello world"|replace:("e":"a","o":"0") 返回 "hall0 w0rld"
  • 替换将按照指定的顺序应用。
  • 要移除指定的文本,请将替换值设为 ""
  • Special characters including : | { } ( ) ' " should be escaped with a backslash when used in the search term, e.g. \: to search for a literal colon. 

支持使用 JavaScript 正则表达式语法:

  • Replace all vowels: "hello world"|replace:"/[aeiou]/g":"*""h*ll* w*rld". 
  • Case-insensitive: "HELLO world"|replace:"/hello/i":"hi""hi world". 
  • Multiple regex: "hello world"|replace:("/[aeiou]/g":"*","/\s+/":"-")"h*ll*-w*rld". 
  • Available flags: g (global), i (case-insensitive), m (multiline), s (dotAll), u (unicode), y (sticky). 

safe_name

将文本转换为安全的文件名。

  • By default, safe_name applies the most conservative sanitization rules. 
  • OS-specific rules can be applied with safe_name:os where os can be windows, mac, or linux to only apply the rules for that operating system. 

snake

将文本转换为 snake_case

title

将文本转换为标题格式 ,例如 "hello world"|title 返回 "Hello World"

trim

从字符串两端移除空白字符。

  • `" hello world "|trim` 返回 `"hello world"`。

uncamel

将驼峰命名法(camelCase)或帕斯卡命名法(PascalCase)转换为用空格分隔的单词,你可以使用其他过滤器(如 `title` 或 `capitalize`)进一步格式化。

  • `"camelCase"|uncamel` 返回 `hello case`。
  • "PascalCase"|uncamel 返回 .

upper

将一个值转换为大写,例如 "hello world"|upper 返回 "HELLO WORLD"

格式化文本

应用基本格式化语法和高级格式化语法对文本进行处理。

blockquote

为输入的每一行添加 Markdown 引用前缀(> )。

callout

创建一个可选参数的提示框: {{variable|callout:("type", "title", foldState)}}

  • type 是提示框类型,默认为 "info"
  • title 是提示框标题,默认为空
  • foldState 是一个布尔值,用于设置折叠状态(true 表示折叠,false 表示展开,null 表示不可折叠)

footnote

将数组或对象转换为 Markdown 脚注列表。

  • 对于数组: ["first item","second item"]|footnote 返回:[^1]: 第一项 等等。
  • 对于对象: {"First Note": "Content 1", "Second Note": "Content 2"}|footnote 返回:[^first-note]: Content 1 等等。

fragment_link

将字符串和数组转换为文本片段链接。默认情况下,链接文本为“link”。

  • `highlights|fragment_link` 返回 ` Highlight content [link](text-fragment-url) `
  • ` highlights|fragment_link:"custom title" ` 返回 ` Highlight content [custom title](text-fragment-url) `

image

将字符串、数组或对象转换为 Markdown 图片语法。

  • 对于字符串:`"image.jpg"|image:"alt text"` 返回 `![alt text](image.jpg)`。
  • 对于数组:` ["image1.jpg","image2.jpg"]|image:"alt text" ` 返回一个包含相同替代文本的 Markdown 图像字符串数组。
  • 对于对象: {"image1.jpg": "Alt 1", "image2.jpg": "Alt 2"}|image 返回带有对象键的替代文本的 Markdown 图像字符串。

link

将字符串、数组或对象转换为 Markdown 链接语法(请注意,这与 不同)。

  • 对于字符串:"url"|link:"author" 返回 [author](url)
  • 对于数组:["url1","url2"]|link:"author" 返回一个包含相同文本的 Markdown 链接数组。
  • 对于对象: {"url1": "Author 1", "url2": "Author 2"}|link 返回 Markdown 链接,链接文本为对象键匹配的内容。

list

将数组转换为 Markdown 列表。

  • list 用于转换为项目符号列表。
  • list:task 用于转换为任务列表。
  • list:numbered 用于转换为编号列表。
  • list:numbered-task 用于转换为带编号的任务列表。

table

将数组或数组对象转换为 Markdown 表格:[Tables](https://help.obsidian.md/advanced-syntax#Tables):

  • 对于一个对象数组,它将使用对象的键作为列头。
  • 对于嵌套数组,它会创建一个表格,其中每个嵌套数组作为一行。
  • 对于简单数组,它会生成一个单列表格,标题为“Value”。
  • 自定义列标题可以使用: table:("Column 1", "Column 2", "Column 3") 。当与简单数组一起使用时,它会根据指定的列数自动将数据拆分为行。

wikilink

将字符串、数组或对象转换为 Obsidian `wikilink` 语法。

  • 对于字符串:`"page"|wikilink` 返回 `[[page]]`。
  • 对于带有别名的字符串:`"page"|wikilink:"alias"` 返回 `[[page|alias]]`。
  • 对于数组:`["page1","page2"]|wikilink` 返回一个不带别名的 wikilink 数组。
  • 对于带有别名的数组: ["page1","page2"]|wikilink:"alias" 返回一个包含所有链接相同别名的 wikilink 数组。
  • 对于对象: {"page1": "alias1", "page2": "alias2"}|wikilink 返回以键作为页面名、值作为别名的 wikilinks。

数字

calc

执行基本的算术运算。

  • 支持运算符:+-*/**(或 ^)用于指数运算。
  • 示例:5|calc:"+10" 返回 15
  • 示例:2|calc:"**3" 返回 8(2 的立方)。
  • 如果输入不是数字,则返回原始字符串。

length

返回字符串、数组的长度或对象中的键的数量。

  • 对于字符串:`"hello"|length` 返回 `5`。
  • 对于数组:`["a","b","c"]|length` 返回 `3`。
  • 对于对象:`{"a":1,"b":2}|length` 返回 `2`。

round

将数字四舍五入到最接近的整数或指定的小数位数。

  • 不带参数:`3.7|round` 返回 `4`。
  • 指定了小数位:`3.14159|round:2` 返回 `3.14`。

HTML 处理

处理 HTML 内容并将其转换为 Markdown。请注意,您的输入 `variable` 必须包含 HTML 内容,例如使用 `{{fullHtml}}`、`{{contentHtml}}` 或 `{{selectorHtml:}}` 变量。

markdown

将字符串转换为 Obsidian 格式的 Markdown 字符串。

  • 当与返回 HTML 的变量(如 `{{contentHtml}}`、`{{fullHtml}}`)结合使用时,或与选择器变量(如 `{{selectorHtml:cssSelector}}`)结合使用时非常有用。

remove_attr

仅移除指定的 HTML 属性。

  • 示例: "<div class="test" id="example">Content</div>"|remove_attr:"class" 返回 <div id="example">Content</div>
  • 多个属性: {{fullHtml|remove_attr:("class,style,id")}}

remove_html

从字符串中移除指定的 HTML 元素及其内容。

  • 支持标签名、类名或 ID,例如 {{fullHtml|remove_html:("img,.class-name,#element-id")}}
  • 若仅移除 HTML 标签或属性而不移除内容,请使用 `strip_tags` 或 `strip_attr` 过滤器。

remove_tags

仅移除指定的 HTML 标签。保留标签内的内容。

  • 示例: "<p>Hello <b>world</b>!</p>"|remove_tags:"b" 返回 "

    Hello world!

    "
  • 多个标签: {{fullHtml|remove_tags:("a,em,strong")}}

replace_tags

替换 HTML 标签,同时保留标签的内容和属性。

  • {{fullHtml|replace_tags:"strong":"h2"}}  将所有 <strong> 标签替换为 <h2> 。

strip_attr

移除字符串中的所有 HTML 属性。

  • 使用 strip_attr:("class, id") 保留特定属性。
  • 示例: "<div class="test" id="example">Content</div>"|strip_attr:("class") 返回 <div id="example">Content</div>

strip_md

移除所有 Markdown 格式,返回一个纯文本字符串,例如将 **text** 转换为 text

  • 将格式化文本转换为未格式化的纯文本,包括粗体、斜体、高亮、标题、代码、块引用、表格、任务列表和维基链接。
  • 完全移除表格、脚注、图片和 HTML 元素。

strip_tags

从字符串中移除所有 HTML 标签。标签内的内容将保留。

  • 使用 strip_tags:("p,strong,em") 可以保留特定的标签。
  • 示例: "<p>Hello <b>world</b>!</p>"|strip_tags:("b") 返回 Hello <b>world</b>!

数组和对象

处理数组和对象。

first

将数组的第一个元素作为字符串返回。

  • ["a","b","c"]|first 返回 "a"
  • 如果输入不是数组,则返回输入不变。

join

将数组中的元素合并成一个字符串。

  • ["a","b","c"]|join 返回 "a,b,c"
  • 可以指定自定义分隔符:["a","b","c"]|join:" " 返回 "a b c"。使用 join:"\n" 可以用换行符分隔元素。
  • splitslice 之后可能会很有用: "a,b,c,d"|split:","|slice:1,3|join:" " 返回 "b c"

last

返回数组的最后一个元素作为字符串。

  • ["a","b","c"]|last 返回 "c"
  • 如果输入不是数组,则返回输入不变。

map

使用语法 map:item => item.propertymap:item => item.nested.property 对数组中的每个元素应用转换,适用于嵌套属性。

  • [{gem: "obsidian", color: "black"}, {gem: "amethyst", color: "purple"}]|map:item => item.gem 返回 ["obsidian", "amethyst"]
  • 使用括号对对象字面量和复杂表达式进行分组:map:item => ({key: value}),例如: [{gem: "obsidian", color: "black"}, {gem: "amethyst", color: "purple"}]|map:item => ({name: item.gem, color: item.color}) 返回 [{name: "obsidian", color: "black"}, {name: "amethyst", color: "purple"}]

字符串字面量受支持,并会自动包装在一个具有 `str` 属性的对象中。`str` 属性用于存储字符串字面量转换的结果,例如 ` ["rock", "pop"]|map:item => "genres/${item}" ` 返回 ` [{str: "genres/rock"}, {str: "genres/pop"}] `。

将 `map` 与 `template` 过滤器结合使用,例如 ` map:item => ({name: ${item.gem}, color: item.color})|template:"- ${name} is ${color}\n" `。

merge

向数组中添加新值。

  • 对于数组:`["a","b"]|merge:("c","d")` 返回 `["a","b","c","d"]`。
  • 单一值:`["a","b"]|merge:"c"` 返回 `["a","b","c"]`。
  • 如果输入不是数组,它会创建一个新的数组:`"a"|merge:("b","c")` 返回 `["a","b","c"]`。
  • 值可以被引号引用:`["a"]|merge:('b,"c,d",e')` 返回 `["a","b","c,d","e"]`。

nth

使用 CSS 风格的 nth-child 语法和分组模式保留数组中的第 n 项。所有位置都是 1 为基础(第一个元素是位置 1)。

  • `array|nth:3` 仅保留第 3 个元素。
  • `array|nth:3n` 每隔 3 个元素保留一个(3, 6, 9 等)。
  • `array|nth:n+3` 保留第 3 个及之后的所有元素。

重复结构的分组模式语法:

  • array|nth:1,2,3:5 从每组 5 个项目中保留位置 1、2、3。示例: [1,2,3,4,5,6,7,8,9,10]|nth:1,2,3:5 返回 [1,2,3,6,7,8]

object

Manipulates object data:

  • object:array converts an object to an array of key-value pairs.
  • object:keys returns an array of the object's keys.
  • object:values returns an array of the object's values.
  • Example: {"a":1,"b":2}|object:array returns [["a",1],["b",2]].

slice

Extracts a portion of a string or array.

  • For strings: "hello"|slice:1,4 returns "ell".
  • For arrays: ["a","b","c","d"]|slice:1,3 returns ["b","c"].
  • If only one parameter is provided, it slices from that index to the end: "hello"|slice:2 returns "llo".
  • Negative indices count from the end: "hello"|slice:-3 returns "llo".
  • The second parameter is exclusive: "hello"|slice:1,4 includes characters at indices 1, 2, and 3.
  • Using a negative second parameter excludes elements from the end: "hello"|slice:0,-2 returns "hel".

split

Divides a string into an array of substrings.

  • "a,b,c"|split:"," returns ["a","b","c"].
  • "hello world"|split:" " returns ["hello","world"].
  • If no separator is provided, it splits on every character: "hello"|split returns ["h","e","l","l","o"].
  • Regular expressions can be used as separators: "a1b2c3"|split:[0-9] returns ["a","b","c"].

template

Applies a template string to an object or array of objects, using the syntax object|template:"Template with ${variable}".

  • Access nested properties: {"gem":{"name":"Obsidian"}}|template:"${gem.name}" returns "Obsidian".
  • For objects: {"gem":"obsidian","hardness":5}|template:"${gem} has a hardness of ${hardness}" returns "obsidian has a hardness of 5".
  • For arrays: [{"gem":"obsidian","hardness":5},{"gem":"amethyst","hardness":7}]|template:"- ${gem} has a hardness of ${hardness}\n" returns a formatted list.

Works with string literals from map by accessing the str property:

  • Example: ["rock", "pop"]|map:item => "genres/${item}"|template:"${str}" returns "genres/rock\ngenres/pop".
  • The str property is automatically used when applying template to objects created by map with string literals.

unique

Removes duplicate values from arrays and objects.

  • For arrays of primitives: [1,2,2,3,3]|unique returns [1,2,3].
  • For arrays of objects: [{"a":1},{"b":2},{"a":1}]|unique returns [{"a":1},{"b":2}].
  • For objects it removes properties with duplicate values, keeping the last occurrence's key.
  • For strings it returns the input unchanged.
过滤器
交互式图表
本页内容
日期
date
date_modify
持续时间
文本转换和大小写
驼峰
首字母大写
驼峰命名
小写
帕斯卡命名
replace
safe_name
snake
title
trim
uncamel
顶部
格式化文本
引用
提示
脚注
片段链接
image
link
列表
表格
维基链接
数字
calc
length
round
HTML processing
markdown
remove_attr
remove_html
remove_tags
replace_tags
strip_attr
strip_md
strip_tags
Arrays and objects
first
join
last
map
merge
nth
object
slice
split
template
unique