Skip to content

Commit

Permalink
🔖v1.1.3 / 2024.11.24
Browse files Browse the repository at this point in the history
- ✨ 脚注内容模板支持渲染sprig语法,现在可以在脚注内容中插入当前时间了
    ```markdown
    >> ${{now | date "20060102 15:04:05"}} 摘抄
    >> ${selection} [[↩️]](siyuan://blocks/${refID})
    >>
    > 💡${content}
    ```
    ![]
  • Loading branch information
Achuan-2 committed Nov 24, 2024
1 parent bddcc35 commit 00911e5
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 4 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@

## v1.1.3 / 2024.11.24

- ✨ 脚注内容模板支持渲染sprig语法,现在可以在脚注内容中插入当前时间了
```markdown
>> ${{now | date "20060102 15:04:05"}} 摘抄
>> ${selection} [[↩️]](siyuan://blocks/${refID})
>>
> 💡${content}
```
![](https://fastly.jsdelivr.net/gh/Achuan-2/PicBed/assets/PixPin_2024-11-24_13-44-34-2024-11-24.png)



## v1.1.2 /2024.11.24
- 🐛 脚注内容模板中的selection变量:过滤掉脚注文本的正则表达式优化
- ✨ 选中文本添加自定义样式,现在支持对重叠文字添加不同脚注时,能保留不同脚注的选中文字样式,删除脚注时,只删除当前脚注选中的文本,不影响其他脚注选中文字的样式
Expand Down
20 changes: 20 additions & 0 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
## 📝更新日志

v1.1.3 / 2024.11.24

- ✨ 脚注内容模板支持渲染sprig语法,现在可以在脚注内容中插入当前时间了
```markdown
>> ${{now | date "20060102 15:04:05"}} 摘抄
>> ${selection} [[↩️]](siyuan://blocks/${refID})
>>
> 💡${content}
```
![](https://fastly.jsdelivr.net/gh/Achuan-2/PicBed/assets/PixPin_2024-11-24_13-44-34-2024-11-24.png)


v1.1.2 /2024.11.24
- 🐛 脚注内容模板中的selection变量:过滤掉脚注文本的正则表达式优化
- ✨ 选中文本添加自定义样式,现在支持对重叠文字添加不同脚注时,能保留不同脚注的选中文字样式,删除脚注时,只删除当前脚注选中的文本,不影响其他脚注选中文字的样式
Expand Down Expand Up @@ -88,6 +100,14 @@ v1.0.9 / 2024.11.23
}}}

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




Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "siyuan-plugin-blockref-footnote",
"author": "Achuan-2",
"url": "https://github.com/Achuan-2/siyuan-plugin-blockref-footnote",
"version": "1.1.2",
"version": "1.1.3",
"minAppVersion": "3.1.13",
"backends": [
"windows",
Expand Down
2 changes: 1 addition & 1 deletion public/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
},
"template": {
"title": "Footnote Template",
"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."
"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."
},
"reset": {
"title": "<span data-type=\"strong text\" style=\"color: var(--b3-font-color1); font-size: 130%\">Reset Settings</span>",
Expand Down
2 changes: 1 addition & 1 deletion public/i18n/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
},
"template": {
"title": "脚注内容模版",
"description": "模板变量:<code>${selection}</code>选中文本的内容,<code>${content}</code>脚注内容占位,<code>${refID}</code>选中文本所在的块的ID<br/>可以使用kramdown语法设置块样式"
"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语法设置块样式"
},
"reset": {
"title": "<span data-type=\"strong text\" style=\"color: var(--b3-font-color1); font-size: 130%\">重置设置</span>",
Expand Down
24 changes: 23 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import "@/index.scss";
import { IMenuItem } from "siyuan/types";

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

const STORAGE_NAME = "config";
Expand Down Expand Up @@ -497,6 +497,28 @@ export default class PluginFootnote extends Plugin {
templates = templates.replace(/\$\{selection\}/g, cleanSelection);
templates = templates.replace(/\$\{content\}/g, zeroWhite);
templates = templates.replace(/\$\{refID\}/g, currentBlockId);
templates = await renderTemplates(templates);

async function renderTemplates(templates: string): Promise<string> {
// First pattern to match ${{...}}
const dollarPattern = /\$(\{\{[^}]*\}\})/g;
let renderedTemplate = templates;
let match;

// Process each ${{...}} block one at a time
while ((match = dollarPattern.exec(templates)) !== null) {
const sprigExpression = match[1]; // 获取{{...}}部分
console.log("Sprig expression:", sprigExpression);
// Render the sprig expression using renderSprig
const renderedAction = await renderSprig(sprigExpression);
// Replace the entire ${{...}} block with the rendered result
renderedTemplate = renderedTemplate.replace(match[0], renderedAction);
}

// Finally render the complete template
return await renderedTemplate;
}


// 插入脚注内容
let back;
Expand Down

0 comments on commit 00911e5

Please sign in to comment.