Skip to content

Commit

Permalink
🔖 v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Achuan-2 committed Nov 18, 2024
1 parent bcddcab commit 8fd2bbf
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
10 changes: 6 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
TODO

- [ ] 支持数字编号
- [ ] 思路:添加一个命令,把当前文档的脚注转化为数字编号,考虑到思源的动态加载机制,应该是把当前文档导出kramdown文本,直接对kramdown进行处理。注意,导出kramdown需要用span样式(https://github.com/siyuan-note/siyuan/issues/13183)
1. 首先先用正则搜索形如`<sup>((20241118190709-lx2usll "注"))</sup>{: style="--memo: 1"}`的块引,根据搜索,获取每个被引用的块id,考虑到可能会存在重复,只考虑这个id在整个文档第一次出现的顺序进行排序。排序后将块引中的`"注"`改为单引号包裹的对应块id的序号(思源笔记kramdown语法单引号代表动态锚文本)。
2. 然后用设置属性api,添加命名,并把脚注引用变为动态锚文本(块引由原来的s改为d),应该就可以实现了
- [ ] 需要改进下如何做到选择同一文本,如果已经有脚注了,脚注块引应该放在最后,而不是放在最浅
- [ ] 优化导出到微信公众号
- [ ] 去除脚注块引锚文本,只保留导出
- [ ] 不导出脚注内容,只显示思源的脚注
- [ ] 自定义选中文本的样式
- [ ] 参考<https://github.com/zxhd863943427/siyuan-plugin-memo>,添加css样式
- [ ] 支持数字编号
- [ ] 可以通过给脚注内容添加命名,把脚注锚文本变为动态锚文本实现
- [ ] 不过脚注增删后,如何更新是一个问题
- [ ] 这个可以搞一个命令,进行刷新



Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Implement footnotes and remarks using SiYuan's blockref.
## 📝Usage Instructions

the requirement of SiYuan minAppVersion:v3.1.12

**Settings**

Here's the translation of the provided text into English:
Expand All @@ -18,7 +20,7 @@ Here's the translation of the provided text into English:
- **Order of Inserting Footnotes**: ascending or descending order. The default is `ascending `.
- **Footnote Title**: Set the title for storing footnotes. The default is `Footnote`.
- **Footnote Anchor Text**: Set the anchor text for footnote references. The default is `Footnote`.
- **Footnote Template**: Set the template for footnotes. It is recommended to use a blockquote or superblock combination to ensure the input content belongs to the same block. The default is a nested blockquote template, which can be changed. `${selection}` represents the content of the selected text, and `${content}` represents the placeholder for footnote content.
- **Footnote Template**: Set the template for footnotes. It is recommended to use a blockquote or superblock combination to ensure the input content belongs to the same block. `${selection}` represents the content of the selected text, and `${content}` represents the placeholder for footnote content.
- **Nested Quote Block Template**

```markdown
Expand Down
4 changes: 3 additions & 1 deletion README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
## 📝使用介绍

思源笔记最低版本要求:v3.1.12

**本插件支持高度自定义化,支持的设置如下:**

- **脚注存放位置**:可以设置存放在当前文档或者指定文档,默认为`当前文档`
- **选中文本的样式**:可以为选中文本添加加粗、高亮、斜体、下划线样式,默认:`无样式`
- **插入脚注的顺序**:顺序或者倒序,默认:`顺序`
- **脚注标题**:设置存放脚注的标题名,默认:`脚注`
- **脚注块引锚文本**:设置脚注引用的锚文本,默认:``
- **脚注内容模板**:设置脚注的模板,推荐使用引述块或超级块组合,保证脚注内容属于同一个块,默认使用嵌套引述块模板,可以自行更改,`${selection}`表示选中文本的内容,`${content}`代表脚注内容占位
- **脚注内容模板**:设置脚注的模板,推荐使用引述块或超级块组合,保证脚注内容属于同一个块,`${selection}`表示选中文本的内容,`${content}`代表脚注内容占位

- 嵌套引述块模板

Expand Down
33 changes: 18 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
Plugin,
getFrontend,
// getFrontend,
Protyle
} from "siyuan";
import "@/index.scss";
Expand All @@ -16,10 +16,8 @@ const zeroWhite = "​"

export default class PluginMemo extends Plugin {

private isMobile: boolean;
// private isMobile: boolean;
private settingUtils: SettingUtils;
private memoRangeMap: Map<string, Range> = new Map(); // 存储脚注id与原文range的映射
// 添加自定义svg

// 添加工具栏按钮
updateProtyleToolbar(toolbar: Array<string | IMenuItem>) {
Expand Down Expand Up @@ -149,9 +147,11 @@ export default class PluginMemo extends Plugin {
});
this.settingUtils.addItem({
key: "templates",
value: `>> \${selection}
>>
> 💡\${content}`,
value: `{{{ row
> \${selection}
>
💡\${content}
}}}`,
type: "textarea",
title: this.i18n.settings.template.title,
description: this.i18n.settings.template.description,
Expand All @@ -166,9 +166,9 @@ export default class PluginMemo extends Plugin {
await this.settingUtils.load(); //导入配置并合并


const frontEnd = getFrontend();
// const frontEnd = getFrontend();

this.isMobile = frontEnd === "mobile" || frontEnd === "browser-mobile";
// this.isMobile = frontEnd === "mobile" || frontEnd === "browser-mobile";


this.eventBus.on("open-menu-blockref", this.deleteMemo.bind(this)); // 注意:事件回调函数中的 this 指向发生了改变。需要bind
Expand All @@ -187,8 +187,9 @@ export default class PluginMemo extends Plugin {
icon: "iconTrashcan",
label: this.i18n.deleteFootnote,
click: () => {
// 删除脚注
deleteBlock(detail.element.getAttribute("data-id"));
// 删除detail element
// 删除块引
detail.element.remove();
}
});
Expand Down Expand Up @@ -284,11 +285,11 @@ export default class PluginMemo extends Plugin {
}


// 获取脚注模板
// 获取脚注模板并替换为具体变量值
const selection = await navigator.clipboard.readText(); // 获取选中文本
let templates = this.settingUtils.get("templates");
templates = templates.replace("${selection}", selection);
templates = templates.replace("${content}", zeroWhite);
templates = templates.replace(/\$\{selection\}/g, selection);
templates = templates.replace(/\$\{content\}/g, zeroWhite);

// 插入脚注
let children = await getChildBlocks(headingID);
Expand Down Expand Up @@ -316,13 +317,15 @@ export default class PluginMemo extends Plugin {
}

let newBlockId = back[0].doOperations[0].id
// 添加脚注属性
await setBlockAttrs(newBlockId, { "custom-plugin-footnote-content": 'true' });
// 添加脚注引用
const { x, y } = protyle.toolbar.range.getClientRects()[0]
let range = protyle.toolbar.range;

//
// 将range的起始点和结束点都移动到选中文本的末尾
const str = ""
const textNode = document.createTextNode(str);
// 将范围的起始点和结束点都移动到选中文本的末尾
range.collapse(false);
protyle.toolbar.range.insertNode(textNode);
protyle.toolbar.range.setEndAfter(textNode);
Expand Down

0 comments on commit 8fd2bbf

Please sign in to comment.