Skip to content

Commit e19c813

Browse files
committed
✨ 脚注容器标题可以支持设置为段落块,不需要一定是标题了!
1 parent d038ba7 commit e19c813

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## v1.2.2 / 2024.12.02
2+
3+
- ✨ 脚注容器标题可以支持设置为段落块,不需要一定是标题了!
4+
5+
16
## v1.2.1 / 2024.12.02
27

38
- 📝 优化模板index变量的i18n,中文默认为[],英文为[*]

src/index.ts

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -725,16 +725,16 @@ export default class PluginFootnote extends Plugin {
725725
case '1':
726726
footnoteContainerTitle = this.settingUtils.get("footnoteContainerTitle").replace(/\$\{filename\}/g, currentDocTitle);
727727
// 需要检测输入的title有没有#,没有会自动变为二级title
728-
if (!footnoteContainerTitle.startsWith("#")) {
729-
footnoteContainerTitle = `## ${footnoteContainerTitle}`;
730-
}
728+
// if (!footnoteContainerTitle.startsWith("#")) {
729+
// footnoteContainerTitle = `## ${footnoteContainerTitle}`;
730+
// }
731731
break;
732732
case '2':
733733
footnoteContainerTitle = this.settingUtils.get("footnoteContainerTitle2").replace(/\$\{filename\}/g, currentDocTitle);
734734
// 需要检测输入的title有没有#,没有会自动变为二级title
735-
if (!footnoteContainerTitle.startsWith("#")) {
736-
footnoteContainerTitle = `## ${footnoteContainerTitle}`;
737-
}
735+
// if (!footnoteContainerTitle.startsWith("#")) {
736+
// footnoteContainerTitle = `## ${footnoteContainerTitle}`;
737+
// }
738738
break;
739739
case '3':
740740
footnoteContainerTitle = this.settingUtils.get("footnoteContainerTitle3").replace(/\$\{filename\}/g, currentDocTitle);
@@ -751,7 +751,7 @@ export default class PluginFootnote extends Plugin {
751751
query_res = await sql(
752752
`SELECT * FROM blocks AS b
753753
WHERE root_id = '${docID}'
754-
AND b.type='h'
754+
AND b.type !='d'
755755
AND b.ial like '%custom-plugin-footnote-parent="${protyle.block.id}"%'
756756
ORDER BY created DESC
757757
limit 1`
@@ -780,7 +780,7 @@ export default class PluginFootnote extends Plugin {
780780
query_res = await sql(
781781
`SELECT * FROM blocks AS b
782782
WHERE root_id = '${docID}'
783-
AND b.type='h'
783+
AND b.type !='d'
784784
AND b.ial like '%custom-plugin-footnote-parent="${protyle.block.id}"%'
785785
ORDER BY created DESC
786786
limit 1`
@@ -824,6 +824,13 @@ export default class PluginFootnote extends Plugin {
824824
await setBlockAttrs(docID, {
825825
"custom-plugin-footnote-parent": protyle.block.id
826826
});
827+
828+
// 删除默认生成的块
829+
// const defaultBlock = await sql(`SELECT * FROM blocks WHERE root_id = '${docID}' AND type != 'd'`);
830+
// console.log(defaultBlock);
831+
// if (defaultBlock.length > 0) {
832+
// await deleteBlock(defaultBlock[0].id);
833+
// }
827834
}
828835
footnoteContainerID = docID;
829836
break;
@@ -972,19 +979,29 @@ export default class PluginFootnote extends Plugin {
972979
case '1':
973980
default:
974981
if (this.settingUtils.get("saveLocation") != 3) {
975-
let children = await getChildBlocks(footnoteContainerID);
982+
983+
let footnoteContainerDom = (await getBlockDOM(docID)).dom;
984+
console.log(docID);
976985
// 默认顺序插入
977-
if (children.length > 0) {
978-
// 在最后一个子块后面添加(使用 insertBlock 并指定 previousID)
986+
const parser = new DOMParser();
987+
// 将DOM字符串解析为DOM文档
988+
const doc = parser.parseFromString(footnoteContainerDom, 'text/html');
989+
990+
// 查找所有符合条件的div元素
991+
const footnotes = doc.querySelectorAll(`div[custom-plugin-footnote-content="${protyle.block.id}"]`);
992+
console.log(footnotes);
993+
if (footnotes.length > 0) {
994+
const lastFootnote = footnotes[footnotes.length - 1];
995+
let lastFootnoteID = lastFootnote.getAttribute('data-node-id');
979996
back = await insertBlock(
980997
"markdown",
981998
templates,
982999
undefined, // nextID
983-
children[children.length - 1].id, // previousID - 放在最后一个子块后面
1000+
lastFootnoteID, // previousID - 放在最后一个子块后面
9841001
undefined // parentID
9851002
);
9861003
} else {
987-
// 如果没有子块,直接在标题下添加
1004+
// 如果没有找到子块,直接在标题下添加
9881005
back = await appendBlock("markdown", templates, footnoteContainerID);
9891006
}
9901007
}

src/libs/setting-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export class SettingUtils {
131131
async save(data?: any) {
132132
data = data ?? this.dump();
133133
await this.plugin.saveData(this.file, this.dump());
134-
console.debug('Save config:', data);
134+
// console.debug('Save config:', data);
135135
return data;
136136
}
137137

0 commit comments

Comments
 (0)