diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ed5919..bd36017 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,8 +10,14 @@ 实现上面GIF的效果: 开启脚注自动编号,脚注内容模板设置为 ```markdown +{{{col +${index} +{: style="width: 2.5em; flex: 0 0 auto;"} + {{{row -${index} ${content} +${content} +}}} + }}} ``` 之前版本或者原来模板没有添加`${index}`变量的块想要自动编号,可以在每个脚注内容块里粘贴下面内容,然后命令面板运行【脚注编号】命令 diff --git a/README_zh_CN.md b/README_zh_CN.md index 9acb5f3..c48365e 100644 --- a/README_zh_CN.md +++ b/README_zh_CN.md @@ -18,8 +18,14 @@ v1.2.0 / 2024.12.01 实现上面GIF的效果: 开启脚注自动编号,脚注内容模板设置为 ```markdown +{{{col +${index} +{: style="width: 2.5em; flex: 0 0 auto;"} + {{{row -${index} ${content} +${content} +}}} + }}} ``` 之前版本或者原来模板没有添加`${index}`变量的块想要自动编号,可以在每个脚注内容块里粘贴下面内容,然后命令面板运行【脚注编号】命令 diff --git a/src/index.ts b/src/index.ts index 26ddb48..d1b7d8e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -326,9 +326,15 @@ export default class PluginFootnote extends Plugin { footnoteRefStyle: '1', footnoteBlockref: this.i18n.settings.footnoteBlockref.value, selectFontStyle: '1', - templates: `{{{row -\${index} \${content} -}}}`, + templates: `{{{col +\${index} +{: style="width: 2.5em; flex: 0 0 auto;"} + +{{{row +\${content} +}}} +}}} +`, enableOrderedFootnotes: false, // Add new setting footnoteAlias: '', css: this.STYLES @@ -1049,13 +1055,14 @@ export default class PluginFootnote extends Plugin { cleanSelection, '', async (content) => { + // TODO: 如果关的时候恰好内容块在刷新,编号可能会获取不到 // Get existing block attributes before update - const existingAttrs = await getBlockAttrs(newBlockId); + // 获取脚注内容块的内容 const originDOM = (await getBlockDOM(newBlockId)).dom; // DOM是string,使用正则表达式检测是否span[data - type*= "custom-footnote-index"]节点,如果有则提取其[number]中的数字 - let number = 0; + let number = 1; if (originDOM) { // 使用 .*? 来匹配 data-type 中任意的前缀值 const match = originDOM.match(/