@@ -725,16 +725,16 @@ export default class PluginFootnote extends Plugin {
725
725
case '1' :
726
726
footnoteContainerTitle = this . settingUtils . get ( "footnoteContainerTitle" ) . replace ( / \$ \{ f i l e n a m e \} / g, currentDocTitle ) ;
727
727
// 需要检测输入的title有没有#,没有会自动变为二级title
728
- if ( ! footnoteContainerTitle . startsWith ( "#" ) ) {
729
- footnoteContainerTitle = `## ${ footnoteContainerTitle } ` ;
730
- }
728
+ // if (!footnoteContainerTitle.startsWith("#")) {
729
+ // footnoteContainerTitle = `## ${footnoteContainerTitle}`;
730
+ // }
731
731
break ;
732
732
case '2' :
733
733
footnoteContainerTitle = this . settingUtils . get ( "footnoteContainerTitle2" ) . replace ( / \$ \{ f i l e n a m e \} / g, currentDocTitle ) ;
734
734
// 需要检测输入的title有没有#,没有会自动变为二级title
735
- if ( ! footnoteContainerTitle . startsWith ( "#" ) ) {
736
- footnoteContainerTitle = `## ${ footnoteContainerTitle } ` ;
737
- }
735
+ // if (!footnoteContainerTitle.startsWith("#")) {
736
+ // footnoteContainerTitle = `## ${footnoteContainerTitle}`;
737
+ // }
738
738
break ;
739
739
case '3' :
740
740
footnoteContainerTitle = this . settingUtils . get ( "footnoteContainerTitle3" ) . replace ( / \$ \{ f i l e n a m e \} / g, currentDocTitle ) ;
@@ -751,7 +751,7 @@ export default class PluginFootnote extends Plugin {
751
751
query_res = await sql (
752
752
`SELECT * FROM blocks AS b
753
753
WHERE root_id = '${ docID } '
754
- AND b.type='h '
754
+ AND b.type !='d '
755
755
AND b.ial like '%custom-plugin-footnote-parent="${ protyle . block . id } "%'
756
756
ORDER BY created DESC
757
757
limit 1`
@@ -780,7 +780,7 @@ export default class PluginFootnote extends Plugin {
780
780
query_res = await sql (
781
781
`SELECT * FROM blocks AS b
782
782
WHERE root_id = '${ docID } '
783
- AND b.type='h '
783
+ AND b.type !='d '
784
784
AND b.ial like '%custom-plugin-footnote-parent="${ protyle . block . id } "%'
785
785
ORDER BY created DESC
786
786
limit 1`
@@ -824,6 +824,13 @@ export default class PluginFootnote extends Plugin {
824
824
await setBlockAttrs ( docID , {
825
825
"custom-plugin-footnote-parent" : protyle . block . id
826
826
} ) ;
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
+ // }
827
834
}
828
835
footnoteContainerID = docID ;
829
836
break ;
@@ -972,19 +979,29 @@ export default class PluginFootnote extends Plugin {
972
979
case '1' :
973
980
default :
974
981
if ( this . settingUtils . get ( "saveLocation" ) != 3 ) {
975
- let children = await getChildBlocks ( footnoteContainerID ) ;
982
+
983
+ let footnoteContainerDom = ( await getBlockDOM ( docID ) ) . dom ;
984
+ console . log ( docID ) ;
976
985
// 默认顺序插入
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' ) ;
979
996
back = await insertBlock (
980
997
"markdown" ,
981
998
templates ,
982
999
undefined , // nextID
983
- children [ children . length - 1 ] . id , // previousID - 放在最后一个子块后面
1000
+ lastFootnoteID , // previousID - 放在最后一个子块后面
984
1001
undefined // parentID
985
1002
) ;
986
1003
} else {
987
- // 如果没有子块 ,直接在标题下添加
1004
+ // 如果没有找到子块 ,直接在标题下添加
988
1005
back = await appendBlock ( "markdown" , templates , footnoteContainerID ) ;
989
1006
}
990
1007
}
0 commit comments