Skip to content

Commit

Permalink
pref: reduce re-mapped codeblock duplicated render
Browse files Browse the repository at this point in the history
  • Loading branch information
plylrnsdy committed Aug 31, 2024
1 parent 6cb225b commit ec64faa
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@rollup/plugin-virtual": "^3.0.2",
"@types/jquery": "3.3.1",
"@types/node": "16.18.0",
"@types/typora": "npm:@typora-community-plugin/typora-types@^1.0.8",
"@types/typora": "npm:@typora-community-plugin/typora-types@^1.0.10",
"@typora-community-plugin/core": "^2.0.0-beta.36",
"archiver": "^5.3.2",
"esbuild": "^0.18.20",
Expand Down
12 changes: 8 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ export default class LangMapperPlugin extends Plugin<LangMapperSettings> {
this.settings.setDefault(DEFAULT_SETTINGS)

this.register(
decorate.returnValue(editor.fences, 'addCodeBlock', (_, cm) => {
decorate(editor.fences, 'addCodeBlock', fn => (cid) => {
const node = editor.getNode(cid)
const mapper = this.settings.get('mapper')
const lang = cm.getOption('mode')
const lang = node.get('lang')
const lang2 = mapper[lang]
const lang3 = aliasMapper[lang2] ?? lang2 ?? lang
if (lang !== lang3) cm.setOption('mode', lang3)
return cm
if (lang !== lang3) {
node.set('lang', lang3)
setTimeout(() => node.set('lang', lang))
}
return fn(cid)
}))

this.registerSettingTab(new LangMapperSettingTab(this))
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "plylrnsdy",
"authorUrl": "https://github.com/plylrnsdy",
"repo": "typora-community-plugin/typora-plugin-codeblock-highlight-mapper",
"version": "1.1.2",
"version": "1.1.3",
"minAppVersion": "1.5.0",
"minCoreVersion": "2.0.0-beta.31",
"platforms": ["win32", "linux", "darwin"]
Expand Down

0 comments on commit ec64faa

Please sign in to comment.