Comments (4)
上次的位置已修改
from typora_plugin.
给一些建议:
-
如果你的 Typora_plugin 升级到最新版本,可以使用内置的 this.utils.editCurrentFile 函数
class utils{ static editCurrentFile = async (editFileFunc, reloadTypora = true) => { const filepath = this.getFilePath(); const content = await this.Package.Fs.promises.readFile(filepath, "utf-8"); const replacedContent = editFileFunc(content); await this.Package.Fs.promises.writeFile(filepath, replacedContent); reloadTypora && File.reloadContent(replacedContent, {fromDiskChange: false}); } }
使用上述方法,将其改造为:
class MarkdownToCode extends BaseCustomPlugin { callback = async anchorNode => await this.utils.editCurrentFile(this.convertMarkdownToCode) // 主要逻辑代码 convertMarkdownToCode = content => { } } module.exports = { plugin: MarkdownToCode };
-
如果将语言放在配置中,限制有点死。如果你愿意的话,可以使用 this.utils.modal 弹出一个弹窗,填写目标语言(将 this.config.code 作为默认语言),这样可以支持任意语言:
class MarkdownToCode extends BaseCustomPlugin { callback = async anchorNode => await this.utils.editCurrentFile(this.convertMarkdownToCode) // 主要逻辑代码 convertMarkdownToCode = content => { const components = [{label: "语言", type: "input", value: this.config.code.toLowerCase()}]; this.utils.modal({title: "添加语言", components}, ([{submit: targetLang}]) => { if (!targetLang) return; alert("your target language is:", targetLang) // TODO }) } }
-
如果你在右下角添加了按钮,如果你愿意的话,可以使用 hide 参数在右键菜单中隐藏此插件,或者使用 order 参数修改在右键菜单中的出现顺序:
[MarkdownToCode] name = "标注全部代码块" # 右键菜单中展示的名称 enable = true # 是否启用此自定义插件 hide = true # 是否在右键菜单中隐藏 order = 1 # 在右键菜单中的出现顺序(越大越排到后面,允许负数) [MarkdownToCode.config] code = "python" ##这里引号内改为你想要格式化的编程语言
注:name、enable、hide、order 是所有自定义插件都支持的参数,其中前两个必填,后两个选填(默认值分别为 false 和 1)
-
上次的 ReplaceBackslash,hotkey 方法放错位置了,应该为:
class ReplaceBackslash extends BaseCustomPlugin { // hotkey 作为插件类的方法,返回 Array<string> 类型 // 为什么返回数组?答:支持为同一个功能绑定多个快捷键 hotkey = () => [this.config.hotkey] callback = async anchorNode => { const filepath = this.utils.getFilePath(); ... } }
from typora_plugin.
@obgnail 谢谢大佬,理解了,我会重新修改内容
from typora_plugin.
本帖已修改
from typora_plugin.
Related Issues (20)
- 【fence_enhance】 建议:能否支持代码块添加输入代码块名称 HOT 3
- Typora右键未显示插件 HOT 5
- 【templater:文件模板】改进建议 HOT 21
- aur包 `PKGBUILD` 未添加 `backup` 属性会导致更新后覆盖 `*.user.toml` 配置 HOT 7
- [bug]: 初始界面中 `CTRL+P` 后无法进入任一文件 HOT 3
- 只读模式的bug HOT 2
- 启停插件问题 HOT 5
- 正文区域点击鼠标右键,不显示右键菜单栏;但是插件的功能却能使用 HOT 9
- 建议:【升级插件】功能 HOT 4
- 【文件模版】:模板变量优化建议 HOT 4
- 【文件模版】:模板预览固定,不发生变化。 HOT 4
- callouts渲染异常 HOT 5
- 如何默认开启调试模式 HOT 1
- 能否在markmap中添加自定义字体的设置? HOT 2
- 代码块右上角工具优化 HOT 2
- 如何点标题即可修改标题等级 HOT 2
- 文件规范性检查的小方块不见了 HOT 8
- 自动编号功能问题 HOT 3
- timeline 问题反馈 HOT 8
- 按要求修改了快捷键配置文件,快捷键无效 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typora_plugin.