Skip to content

Commit

Permalink
Merge pull request #878 from obgnail/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
obgnail authored Nov 28, 2024
2 parents e2b5508 + 99205a9 commit 2d73d91
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 68 deletions.
87 changes: 47 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,46 +34,47 @@
| 18 | markmap | 提供 markmap 组件支持 | |
| 19 | echarts | 提供 echarts 组件支持 | |
| 20 | chart | 提供 chartjs 组件支持 | |
| 21 | abc | 提供 abcjs 组件支持 | |
| 22 | calendar | 提供 tui.calendar 组件支持 | |
| 23 | wavedrom | 提供 wavedrom 组件支持 | |
| 24 | marp | 提供 marp 组件支持 | |
| 25 | callouts | 提供 callouts 支持 | |
| 26 | text_stylize | 文字风格化 | |
| 27 | read_only | 只读模式 | |
| 28 | blur | 模糊模式 | |
| 29 | kanban | 看板 | |
| 30 | timeline | 时间线 | |
| 31 | chat | 聊天 | |
| 32 | file_counter | 显示目录下的文件数 | |
| 33 | auto_number | 章节、表格、图片、代码块等自动编号 | |
| 34 | imageReviewer | 图片查看器 | |
| 35 | chineseSymbolAutoPairer | 中文符号自动补全 | |
| 36 | datatables | 表格增强(搜索、过滤、分页、排序等) | × |
| 37 | resize_table | 调整表格行高列宽 | |
| 38 | resize_image | 调整图片显示大小 | |
| 39 | export_enhance | 导出 html 时避免图片丢失 | |
| 40 | markdownLint | markdown 格式规范检测 | |
| 41 | go_top | 一键到文章顶部、底部 | |
| 42 | reopenClosedFiles | 打开上次退出 Typora 时尚未关闭的标签页 | × |
| 43 | truncate_text | 暂时隐藏内容,提高大文件渲染性能 | × |
| 44 | dark | 夜间模式 | |
| 45 | no_image | 无图模式 | |
| 46 | updater | 一键升级插件 | |
| 47 | easy_modify | 编辑工具 | |
| 48 | editor_width_slider | 写作区宽度调整 | |
| 49 | redirectLocalRootUrl | 重定向本地资源根目录 | × |
| 50 | blockSideBySide | 并列显示活动块 | × |
| 51 | scrollBookmarker | 书签管理器 | × |
| 52 | openInTotalCommander | 在 total commander 打开 | × |
| 53 | cipher | 加密文件 | × |
| 54 | ripgrep | 使用 ripgrep 搜索文件 | × |
| 55 | article_uploader | 一键上传博客到支持的所有平台 | × |
| 56 | help | 用户帮助 | |
| 57 | custom | 开放平台,用户自定义插件(高级) | |
| 58 | hotkeys | 快捷键注册中心(高级) | |
| 59 | quickButton | 于右下角添加功能按钮(高级) | |
| 60 | json_rpc | 外部操纵 Typora(高级) | × |
| 21 | drawIO | 提供 drawIO 组件支持 | |
| 22 | abc | 提供 abcjs 组件支持 | |
| 23 | calendar | 提供 tui.calendar 组件支持 | |
| 24 | wavedrom | 提供 wavedrom 组件支持 | |
| 25 | marp | 提供 marp 组件支持 | |
| 26 | callouts | 提供 callouts 支持 | |
| 27 | text_stylize | 文字风格化 | |
| 28 | read_only | 只读模式 | |
| 29 | blur | 模糊模式 | |
| 30 | kanban | 看板 | |
| 31 | timeline | 时间线 | |
| 32 | chat | 聊天 | |
| 33 | file_counter | 显示目录下的文件数 | |
| 34 | auto_number | 章节、表格、图片、代码块等自动编号 | |
| 35 | imageReviewer | 图片查看器 | |
| 36 | chineseSymbolAutoPairer | 中文符号自动补全 | |
| 37 | datatables | 表格增强(搜索、过滤、分页、排序等) | × |
| 38 | resize_table | 调整表格行高列宽 | |
| 39 | resize_image | 调整图片显示大小 | |
| 40 | export_enhance | 导出 html 时避免图片丢失 | |
| 41 | markdownLint | markdown 格式规范检测 | |
| 42 | go_top | 一键到文章顶部、底部 | |
| 43 | reopenClosedFiles | 打开上次退出 Typora 时尚未关闭的标签页 | × |
| 44 | truncate_text | 暂时隐藏内容,提高大文件渲染性能 | × |
| 45 | dark | 夜间模式 | |
| 46 | no_image | 无图模式 | |
| 47 | updater | 一键升级插件 | |
| 48 | easy_modify | 编辑工具 | |
| 49 | editor_width_slider | 写作区宽度调整 | |
| 50 | redirectLocalRootUrl | 重定向本地资源根目录 | × |
| 51 | blockSideBySide | 并列显示活动块 | × |
| 52 | scrollBookmarker | 书签管理器 | × |
| 53 | openInTotalCommander | 在 total commander 打开 | × |
| 54 | cipher | 加密文件 | × |
| 55 | ripgrep | 使用 ripgrep 搜索文件 | × |
| 56 | article_uploader | 一键上传博客到支持的所有平台 | × |
| 57 | help | 用户帮助 | |
| 58 | custom | 开放平台,用户自定义插件(高级) | |
| 59 | hotkeys | 快捷键注册中心(高级) | |
| 60 | quickButton | 于右下角添加功能按钮(高级) | |
| 61 | json_rpc | 外部操纵 Typora(高级) | × |

**尊重用户的一切选择**。本项目的任何插件、任何功能皆可永久启用 / 禁用。

Expand Down Expand Up @@ -542,6 +543,12 @@ LIST = [



### drawIO:提供 drawIO 组件支持

![drawIO](./assets/drawIO.png)



### abc:提供 abc 组件支持

使用方式:右键菜单 -> 常用插件 -> 二级插件 -> ABC
Expand Down
Binary file added assets/drawIO.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
113 changes: 113 additions & 0 deletions plugin/custom/plugins/drawIO/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
class drawIOPlugin extends BaseCustomPlugin {
init = () => {
this.hasLoaded = null
this.defaultConfig = this._getDefaultConfig()
}

callback = anchorNode => this.utils.insertText(anchorNode, this.config.TEMPLATE)

process = () => {
this.utils.thirdPartyDiagramParser.register({
lang: this.config.LANGUAGE,
mappingLang: "javascript",
destroyWhenUpdate: false,
interactiveMode: this.config.INTERACTIVE_MODE,
checkSelector: ".plugin-drawio-content",
wrapElement: '<div class="plugin-drawio-content"></div>',
css: {
height: this.config.DEFAULT_FENCE_HEIGHT,
"background-color": this.config.DEFAULT_FENCE_BACKGROUND_COLOR,
},
lazyLoadFunc: this.lazyLoad,
createFunc: this.create,
updateFunc: null,
destroyFunc: null,
beforeExport: null,
extraStyleGetter: null,
versionGetter: this.versionGetter,
})
}

create = async ($wrap, content) => {
const graphConfig = this._getConfig(content)
if (!graphConfig.source && !graphConfig.xml) {
throw new Error("缺失必须的配置项: source")
}
await this._getXML(graphConfig)
$wrap[0].innerHTML = await this._toElement(graphConfig)
this._refresh()
}

_getConfig = content => new Function(`return (${content})`)()

_getXML = async graphConfig => {
if (graphConfig.xml) return

let { source } = graphConfig
const isNetwork = this.utils.isNetworkImage(source)
try {
if (isNetwork) {
graphConfig.xml = await this._memorizedFetch(source)
} else {
const dir = this.utils.getCurrentDirPath()
source = this.utils.Package.Path.resolve(dir, source)
graphConfig.xml = await this.utils.Package.Fs.promises.readFile(source, "utf-8")
}
} catch (e) {
const from = isNetwork ? "网络" : "本地"
throw new Error(`读取${from}文件失败: ${source}\n\n${e}`)
}
}

_toElement = graphConfig => {
const mxGraphData = { ...this.defaultConfig, ...graphConfig }
const jsonString = JSON.stringify(mxGraphData)
const escaped = this.utils.escape(jsonString)
return `<div class="mxgraph" style="max-width:100%; width:100%; margin-top: 26px;" data-mxgraph="${escaped}"></div>`
}

_refresh = this.utils.debounce(() => window.GraphViewer.processElements(), 100)

_memorizedFetch = this.utils.memorize(async url => {
console.log(`memorized fetch url: ${url}`)
const resp = await this.utils.fetch(url, { timeout: 60 * 1000 })
return resp.text()
})

_getDefaultConfig = (type = "showOnly") => {
const config = {
showOnly: { highlight: "#0000ff", nav: false, resize: false, edit: null, editable: true, lightbox: false, zoom: "1", toolbar: null, "toolbar-nohide": true, },
editable: { highlight: "#0000ff", nav: false, resize: true, edit: null, editable: false, toolbar: null, "toolbar-nohide": true, },
showToolbar: {
highlight: "#0000ff",
nav: true,
resize: true,
edit: null,
editable: true,
lightbox: false,
zoom: "1",
toolbar: "zoom lightbox layers",
"toolbar-position": "inline",
"toolbar-nohide": true,
},
}
return config[type]
}

lazyLoad = async () => {
if (!this.hasLoaded) {
const from = this.config.RESOURCE_URI
const path = this.utils.isNetworkImage(from) ? from : `file:///${this.utils.Package.Path.resolve(from)}`
await $.getScript(path)
this.hasLoaded = true

window.GraphViewer.prototype.toolbarZIndex = 7
}
}

versionGetter = () => "24.8.9"
}

module.exports = {
plugin: drawIOPlugin,
}
2 changes: 1 addition & 1 deletion plugin/global/core/utils/mixin/diagramParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class diagramParser {
$pre.children(".md-diagram-panel").remove();
} else {
$pre.find(".md-diagram-panel-header").text(lang);
$pre.find(".md-diagram-panel-preview").text("语法错误,绘图失败");
$pre.find(".md-diagram-panel-preview").text("发生异常,绘图失败");
$pre.find(".md-diagram-panel-error").html(`<pre>${this.getErrorMessage(error)}</pre>`);
}
await this.noticeRollback(cid);
Expand Down
7 changes: 6 additions & 1 deletion plugin/global/core/utils/mixin/thirdPartyDiagramParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ class thirdPartyDiagramParser {
const $wrap = this.getWrap(parser, $pre);
try {
this.setStyle(parser, $pre, $wrap, content);
const instance = this.createOrUpdate(parser, cid, content, $wrap, lang);
let instance = this.createOrUpdate(parser, cid, content, $wrap, lang);
// 为什么不使用await this.createOrUpdate,而是判断isPromise?
// 答:有些parser的createFunc可能会抢占element,如果使用await会出现race问题
if (this.utils.isPromise(instance)) {
instance = await instance
}
instance && parser.instanceMap.set(cid, instance);
} catch (e) {
e.stack += this.getSettingMsg(parser);
Expand Down
39 changes: 39 additions & 0 deletions plugin/global/settings/custom_plugin.default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,45 @@ G2 G2|A2 A2|B2 B2|c3 z|G2 G2|A2 A2|B2 G2|c3 z||
```
"""

############### drawIO ###############
[drawIO]
# 是否启用此二级插件
enable = true
# 插件名称
name = "drawIO"
# 是否在右键菜单中隐藏
hide = false
# 在右键菜单中的出现顺序(越大越排到后面,允许负数)
order = 1
# 依赖资源从何处加载
# 由于drawio的格式经常发生变动,官网强烈建议使用cdn获取依赖资源,而不是将依赖资源保存在本地。所以此插件默认需要从网络拉取依赖。如果你希望将依赖资源保存在本地,请按如下操作
# 1. 下载文件:https://viewer.diagrams.net/js/viewer-static.min.js
# 2. RESOURCE_URI修改为你自己的文件地址(比如:D:\\tmp\\viewer-static.min.js)
RESOURCE_URI = "https://viewer.diagrams.net/js/viewer-static.min.js"
# 代码块语言
# 强烈建议不要修改。如果要修改,请跟着修改TEMPLATE选项里的语言
LANGUAGE = "drawio"
# 开启交互模式(处于交互模式下,鼠标点击图表并不会展开代码块)
INTERACTIVE_MODE = true
# 图表默认高度
DEFAULT_FENCE_HEIGHT = "auto"
# 图表背景颜色
DEFAULT_FENCE_BACKGROUND_COLOR = "transparent"
# 自动插入的模板
TEMPLATE = """```drawio
// 支持配置项:allow-zoom-in、allow-zoom-out、auto-crop、auto-fit、auto-origin、border、center、check-visible-state、dark-mode、edit、editable、forceCenter、highlight、layerIds、layers、lightbox、max-height、move、nav、page、pageId、resize、responsive、source、target、title、titleTooltip、toolbar、toolbar-buttons、toolbar-nohide、toolbar-position、tooltips、xml、zoom
// 配置项使用方法请参考:https://github.com/jgraph/drawio/blob/f7158bfb0029a6456c215791b7fd005ccb5c3e76/src/main/webapp/js/diagramly/GraphViewer.js#L118C1-L118C71
graphConfig = {
// 必须配置项:.drawio文件的路径。
// 支持本地路径:例如:"./assets/example.drawio"或者"D:\\tmp\\example.drawio"
// 支持网络路径:例如:"https://cdn.jsdelivr.net/gh/obgnail/typora_images@master/image/example.drawio"
"source": "./assets/example.drawio",
// 如果存在多页,可以使用page切换
"page": 0,
}
```
"""

############### callouts ###############
[callouts]
Expand Down
Loading

0 comments on commit 2d73d91

Please sign in to comment.