支持公式和脚注的知乎回答剪藏web clipper模板

支持公式和脚注的知乎回答剪藏web clipper模板

感谢

@HAFEN 佬的这个脚本基础上修改: 修改并写了新的知乎剪藏模版obsidian web clipper

新增功能:

  • 公式的支持,包括行内公式和独立的大型公式
  • 脚注的支持,现在摘录有脚注的内容可以完美识别了

注:GPT-5.5写的,反复调了几版,只测试了几篇比较典型的文章

配置文件如下


{
	"schemaVersion": "0.1.0",
	"name": "知乎回答",
	"behavior": "create",
	"noteContentFormat": "{{selectorHtml:.RichContent-inner|first|replace:\"/<span class=\\\"ztext-math\\\"[^>]*data-tex=\\\"([^\\\"]*\\\\begin\\\\{[^\\\"]*\\\\end\\\\{[^\\\"]*)\\\"[^>]*>[\\\\s\\\\S]*?<\\\\/span><\\\\/span>/g\":\"<code>ZZZCLIPPERMATHBLOCK$1ZZZ</code>\"|replace:\"/<span class=\\\"ztext-math\\\"[^>]*data-tex=\\\"([^\\\"]*)\\\"[^>]*>[\\\\s\\\\S]*?<script type=\\\"math\\/tex;mode=display\\\"[\\\\s\\\\S]*?<\\\\/script>[\\\\s\\\\S]*?<\\\\/span><\\\\/span>/g\":\"<code>ZZZCLIPPERMATHBLOCK$1ZZZ</code>\"|replace:\"/<span class=\\\"ztext-math\\\"[^>]*data-tex=\\\"([^\\\"]*)\\\"[^>]*>[\\\\s\\\\S]*?<\\\\/span><\\\\/span>/g\":\"<code>ZZZCLIPPERMATHINLINE$1ZZZ</code>\"|remove_html:\".math-holder\"|replace:\"/<sup[^>]*data-numero=\\\"(\\\\d+)\\\"[^>]*>[\\\\s\\\\S]*?<\\\\/sup>/g\":\"ZZZCLIPPERFOOTNOTEREF$1ZZZ\"|replace:\"href=\\\"https\\://zhida\":\"\"|markdown|replace:\"/&amp;/g\":\"&\"|replace:\"/&#39;/g\":\"'\"|replace:\"/&lt;/g\":\"<\"|replace:\"/&gt;/g\":\">\"|replace:\"/␣/g\":\"⊔\"|replace:\"/⧵/g\":\"∖\"|replace:\"/`ZZZCLIPPERMATHBLOCK\\\\s*([\\\\s\\\\S]*?\\\\S?)\\\\s*(?:\\\\\\\\)?\\\\s*ZZZ`/g\":\"\\n$$$$\\n$1\\n$$$$\\n\"|replace:\"/`ZZZCLIPPERMATHINLINE\\\\s*([\\\\s\\\\S]*?\\\\S)\\\\s*(?:\\\\\\\\)?\\\\s*ZZZ`/g\":\"$$$1$$\"|replace:\"/ZZZCLIPPERFOOTNOTEREF(\\\\d+)ZZZ/g\":\"[^$1]\"|replace:\"/^\\\\s*(\\\\d+)\\\\.\\\\s+\\\\[\\\\^\\\\]\\\\(#ref_\\\\d+_0\\\\)\\\\s*(.*)$/gm\":\"[^$1]: $2\"|replace:\"/\\\\n{3,}/g\":\"\\\\n\\\\n\"}}",
	"properties": [
		{
			"name": "title",
			"value": "{{title|replace:\\\" - 知乎\\\":\\\"\\\"}}",
			"type": "text"
		},
		{
			"name": "source",
			"value": "{{url}}",
			"type": "text"
		},
		{
			"name": "author",
			"value": "{{selector:.UserLink-link|slice:1,2}}",
			"type": "multitext"
		},
		{
			"name": "published",
			"value": "{{selector:.ContentItem-time|split:\\\",\\\"|first|split:\\\"发布于 \\\"|last|date:\\\"YYYY-MM-DD\\\"}}",
			"type": "date"
		},
		{
			"name": "created",
			"value": "{{date}}",
			"type": "date"
		},
		{
			"name": "description",
			"value": "{{description}}",
			"type": "text"
		}
	],
	"triggers": [
		"/^https.+zhihu.+answer.+$/"
	],
	"noteNameFormat": "{{title|replace:\" - 知乎\":\"\"}}",
	"path": "70_Clippings (剪藏)"
}


tips:

  • 包含大量公式的回答请先慢慢滚动到最底部,等回答中的公式全部都加载出来(而不是latex原格式)后再使用clipper剪藏。
  • AI写的,未经过严格测试,比如行内公式的测试只粗略浏览了一下,找出了明显有问题的bug并修复,如果还是有不能识别的情况请回帖。
1 个赞

测试用例:

2 个赞

这个好厉害, owc 本地化的强有力的扩展

手机上剪藏知乎也可以试试笔记同步助手插件,支持剪藏知乎回答到Obsidian

这个对知乎文章支持吗,比如专栏里面的。https://zhuanlan.zhihu.com/p/2007250216227729670

让哈基米帮我改成同时适用回答和专栏,我用着公式确实没问题,没有大范围测试

{
	"schemaVersion": "0.1.0",
	"name": "知乎回答与专栏",
	"behavior": "create",
	"noteContentFormat": "{{selectorHtml:.RichContent-inner, .Post-RichText|first|replace:\"/<span class=\\\"ztext-math\\\"[^>]*data-tex=\\\"([^\\\"]*\\\\begin\\\\{[^\\\"]*\\\\end\\\\{[^\\\"]*)\\\"[^>]*>[\\\\s\\\\S]*?<\\\\/span><\\\\/span>/g\":\"<code>ZZZCLIPPERMATHBLOCK$1ZZZ</code>\"|replace:\"/<span class=\\\"ztext-math\\\"[^>]*data-tex=\\\"([^\\\"]*)\\\"[^>]*>[\\\\s\\\\S]*?<script type=\\\"math\\/tex;mode=display\\\"[\\\\s\\\\S]*?<\\\\/script>[\\\\s\\\\S]*?<\\\\/span><\\\\/span>/g\":\"<code>ZZZCLIPPERMATHBLOCK$1ZZZ</code>\"|replace:\"/<span class=\\\"ztext-math\\\"[^>]*data-tex=\\\"([^\\\"]*)\\\"[^>]*>[\\\\s\\\\S]*?<\\\\/span><\\\\/span>/g\":\"<code>ZZZCLIPPERMATHINLINE$1ZZZ</code>\"|remove_html:\".math-holder\"|replace:\"/<sup[^>]*data-numero=\\\"(\\\\d+)\\\"[^>]*>[\\\\s\\\\S]*?<\\\\/sup>/g\":\"ZZZCLIPPERFOOTNOTEREF$1ZZZ\"|replace:\"href=\\\"https\\://zhida\":\"\"|markdown|replace:\"/&amp;/g\":\"&\"|replace:\"/&#39;/g\":\"'\"|replace:\"/&lt;/g\":\"<\"|replace:\"/&gt;/g\":\">\"|replace:\"/␣/g\":\"⊔\"|replace:\"/⧵/g\":\"∖\"|replace:\"/`ZZZCLIPPERMATHBLOCK\\\\s*([\\\\s\\\\S]*?\\\\S?)\\\\s*(?:\\\\\\\\)?\\\\s*ZZZ`/g\":\"\\n$$$$\\n$1\\n$$$$\\n\"|replace:\"/`ZZZCLIPPERMATHINLINE\\\\s*([\\\\s\\\\S]*?\\\\S)\\\\s*(?:\\\\\\\\)?\\\\s*ZZZ`/g\":\"$$$1$$\"|replace:\"/ZZZCLIPPERFOOTNOTEREF(\\\\d+)ZZZ/g\":\"[^$1]\"|replace:\"/^\\\\s*(\\\\d+)\\\\.\\\\s+\\\\[\\\\^\\\\]\\\\(#ref_\\\\d+_0\\\\)\\\\s*(.*)$/gm\":\"[^$1]: $2\"|replace:\"/\\\\n{3,}/g\":\"\\\\n\\\\n\"}}",
	"properties": [
		{
			"name": "title",
			"value": "{{title|replace:\\\" - 知乎\\\":\\\"\\\"}}",
			"type": "text"
		},
		{
			"name": "source",
			"value": "{{url}}",
			"type": "text"
		},
		{
			"name": "author",
			"value": "{{selector:.AuthorInfo-name, .UserLink-link|first}}",
			"type": "multitext"
		},
		{
			"name": "published",
			"value": "{{selector:.ContentItem-time|split:\\\",\\\"|first|split:\\\"发布于 \\\"|last|date:\\\"YYYY-MM-DD\\\"}}",
			"type": "date"
		},
		{
			"name": "created",
			"value": "{{date}}",
			"type": "date"
		},
		{
			"name": "description",
			"value": "{{description}}",
			"type": "text"
		}
	],
	"triggers": [
		"/^https.+zhihu.+answer.+$/",
		"/^https.+zhuanlan.+zhihu.+p.+$/"
	],
	"noteNameFormat": "{{title|replace:\" - 知乎\":\"\"}}",
	"path": "70_Clippings (剪藏)"
}

确实可以,之前只是剪切回答,最近遇到了专栏的帖子发现剪切不了,用官方插件自带的模板就就可以了,然后就来站里搜方案,让AI帮忙修改。