Skip to content

Commit

Permalink
🔖 v1.1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Achuan-2 committed Dec 1, 2024
1 parent 1672cde commit 30698c1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@
实现上面GIF的效果:
开启脚注自动编号,脚注内容模板设置为
```markdown
{{{col
${index}
{: style="width: 2.5em; flex: 0 0 auto;"}

{{{row
${index} ${content}
${content}
}}}

}}}
```
之前版本或者原来模板没有添加`${index}`变量的块想要自动编号,可以在每个脚注内容块里粘贴下面内容,然后命令面板运行【脚注编号】命令
Expand Down
8 changes: 7 additions & 1 deletion README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}`变量的块想要自动编号,可以在每个脚注内容块里粘贴下面内容,然后命令面板运行【脚注编号】命令
Expand Down
19 changes: 14 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(/<span data-type=".*?custom-footnote-index[^>]*>\[(\d+)\]<\/span>/);
Expand All @@ -1079,9 +1086,11 @@ export default class PluginFootnote extends Plugin {
const renderedTemplate = await renderTemplates(templates);

// Update block content

await updateBlock("markdown", renderedTemplate, newBlockId);

// Restore block attributes that could have been reset by updateBlock
const existingAttrs = await getBlockAttrs(newBlockId);
if (existingAttrs) {
await setBlockAttrs(newBlockId, {
"custom-plugin-footnote-content": existingAttrs["custom-plugin-footnote-content"],
Expand Down

0 comments on commit 30698c1

Please sign in to comment.