Skip to content

Commit 00911e5

Browse files
committed
🔖v1.1.3 / 2024.11.24
- ✨ 脚注内容模板支持渲染sprig语法,现在可以在脚注内容中插入当前时间了 ```markdown >> ${{now | date "20060102 15:04:05"}} 摘抄 >> ${selection} [[↩️]](siyuan://blocks/${refID}) >> > 💡${content} ``` ![]
1 parent bddcc35 commit 00911e5

File tree

6 files changed

+60
-4
lines changed

6 files changed

+60
-4
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
2+
## v1.1.3 / 2024.11.24
3+
4+
- ✨ 脚注内容模板支持渲染sprig语法,现在可以在脚注内容中插入当前时间了
5+
```markdown
6+
>> ${{now | date "20060102 15:04:05"}} 摘抄
7+
>> ${selection} [[↩️]](siyuan://blocks/${refID})
8+
>>
9+
> 💡${content}
10+
```
11+
![](https://fastly.jsdelivr.net/gh/Achuan-2/PicBed/assets/PixPin_2024-11-24_13-44-34-2024-11-24.png)
12+
13+
14+
115
## v1.1.2 /2024.11.24
216
- 🐛 脚注内容模板中的selection变量:过滤掉脚注文本的正则表达式优化
317
- ✨ 选中文本添加自定义样式,现在支持对重叠文字添加不同脚注时,能保留不同脚注的选中文字样式,删除脚注时,只删除当前脚注选中的文本,不影响其他脚注选中文字的样式

README_zh_CN.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88
99
## 📝更新日志
1010

11+
v1.1.3 / 2024.11.24
12+
13+
- ✨ 脚注内容模板支持渲染sprig语法,现在可以在脚注内容中插入当前时间了
14+
```markdown
15+
>> ${{now | date "20060102 15:04:05"}} 摘抄
16+
>> ${selection} [[↩️]](siyuan://blocks/${refID})
17+
>>
18+
> 💡${content}
19+
```
20+
![](https://fastly.jsdelivr.net/gh/Achuan-2/PicBed/assets/PixPin_2024-11-24_13-44-34-2024-11-24.png)
21+
22+
1123
v1.1.2 /2024.11.24
1224
- 🐛 脚注内容模板中的selection变量:过滤掉脚注文本的正则表达式优化
1325
- ✨ 选中文本添加自定义样式,现在支持对重叠文字添加不同脚注时,能保留不同脚注的选中文字样式,删除脚注时,只删除当前脚注选中的文本,不影响其他脚注选中文字的样式
@@ -88,6 +100,14 @@ v1.0.9 / 2024.11.23
88100
}}}
89101

90102
```
103+
- 脚注内容模板支持渲染sprig语法,现在可以在脚注内容中插入当前时间了
104+
```markdown
105+
>> ${{now | date "20060102 15:04:05"}} 摘抄
106+
>> ${selection} [[↩️]](siyuan://blocks/${refID})
107+
>>
108+
> 💡${content}
109+
```
110+
91111

92112

93113

plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "siyuan-plugin-blockref-footnote",
33
"author": "Achuan-2",
44
"url": "https://github.com/Achuan-2/siyuan-plugin-blockref-footnote",
5-
"version": "1.1.2",
5+
"version": "1.1.3",
66
"minAppVersion": "3.1.13",
77
"backends": [
88
"windows",

public/i18n/en_US.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
},
6666
"template": {
6767
"title": "Footnote Template",
68-
"description": "Template variables: <code>${selection}</code> is the content of the selected text , <code>${content}</code> is the placeholder for footnote content, and <code>${refID}</code> is the block ID containing the selected text <br/>You can use kramdown syntax to style the block."
68+
"description": "Template variables: <code>${selection}</code> is the content of the selected text , <code>${content}</code> is the placeholder for footnote content, and <code>${refID}</code> is the block ID containing the selected text <br/> ${{...}} for Sprig templated, e.g. ${{now | date \"20060102 15:04:05\"}} </br>You can use kramdown syntax to style the block."
6969
},
7070
"reset": {
7171
"title": "<span data-type=\"strong text\" style=\"color: var(--b3-font-color1); font-size: 130%\">Reset Settings</span>",

public/i18n/zh_CN.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
},
6666
"template": {
6767
"title": "脚注内容模版",
68-
"description": "模板变量:<code>${selection}</code>选中文本的内容,<code>${content}</code>脚注内容占位,<code>${refID}</code>选中文本所在的块的ID<br/>可以使用kramdown语法设置块样式"
68+
"description": "模板变量:<code>${selection}</code>选中文本的内容,<code>${content}</code>脚注内容占位,<code>${refID}</code>选中文本所在的块的ID<br/>使用<code>${{...}}</code>可以使用Sprig语法,例如插入当前时间<code>${{now | date \"20060102 15:04:05\"}}</code></br>可以使用kramdown语法设置块样式"
6969
},
7070
"reset": {
7171
"title": "<span data-type=\"strong text\" style=\"color: var(--b3-font-color1); font-size: 130%\">重置设置</span>",

src/index.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
import "@/index.scss";
77
import { IMenuItem } from "siyuan/types";
88

9-
import { appendBlock, deleteBlock, setBlockAttrs, pushErrMsg, sql, getChildBlocks, insertBlock, renameDocByID, prependBlock, updateBlock, createDocWithMd, getBlockKramdown } from "./api";
9+
import { appendBlock, deleteBlock, setBlockAttrs, pushErrMsg, sql, renderSprig, getChildBlocks, insertBlock, renameDocByID, prependBlock, updateBlock, createDocWithMd, getBlockKramdown } from "./api";
1010
import { SettingUtils } from "./libs/setting-utils";
1111

1212
const STORAGE_NAME = "config";
@@ -497,6 +497,28 @@ export default class PluginFootnote extends Plugin {
497497
templates = templates.replace(/\$\{selection\}/g, cleanSelection);
498498
templates = templates.replace(/\$\{content\}/g, zeroWhite);
499499
templates = templates.replace(/\$\{refID\}/g, currentBlockId);
500+
templates = await renderTemplates(templates);
501+
502+
async function renderTemplates(templates: string): Promise<string> {
503+
// First pattern to match ${{...}}
504+
const dollarPattern = /\$(\{\{[^}]*\}\})/g;
505+
let renderedTemplate = templates;
506+
let match;
507+
508+
// Process each ${{...}} block one at a time
509+
while ((match = dollarPattern.exec(templates)) !== null) {
510+
const sprigExpression = match[1]; // 获取{{...}}部分
511+
console.log("Sprig expression:", sprigExpression);
512+
// Render the sprig expression using renderSprig
513+
const renderedAction = await renderSprig(sprigExpression);
514+
// Replace the entire ${{...}} block with the rendered result
515+
renderedTemplate = renderedTemplate.replace(match[0], renderedAction);
516+
}
517+
518+
// Finally render the complete template
519+
return await renderedTemplate;
520+
}
521+
500522

501523
// 插入脚注内容
502524
let back;

0 commit comments

Comments
 (0)