diff --git a/package.json b/package.json index c3225e4..a25b6bc 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c79285c..8aac991 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,7 +12,7 @@ specifiers: '@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 @@ -34,7 +34,7 @@ devDependencies: '@rollup/plugin-virtual': 3.0.2_rollup@4.6.1 '@types/jquery': 3.3.1 '@types/node': 16.18.0 - '@types/typora': /@typora-community-plugin/typora-types/1.0.8 + '@types/typora': /@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 @@ -1635,6 +1635,7 @@ packages: resolution: {integrity: sha512-9lhc4UZstsegbNLhH0Zu6TqvDfmhGzuCWtcTFXY10VjLLUe4Mr0Ye2L3rrtHaDd/J5+tFMEuo5LTCSCMXWfUKw==} cpu: [arm64] os: [linux] + libc: [glibc] requiresBuild: true dev: true optional: true @@ -1643,6 +1644,7 @@ packages: resolution: {integrity: sha512-FfoOK1yP5ksX3wwZ4Zk1NgyGHZyuRhf99j64I5oEmirV8EFT7+OhUZEnP+x17lcP/QHJNWGsoJwrz4PJ9fBEXw==} cpu: [arm64] os: [linux] + libc: [musl] requiresBuild: true dev: true optional: true @@ -1651,6 +1653,7 @@ packages: resolution: {integrity: sha512-DNGZvZDO5YF7jN5fX8ZqmGLjZEXIJRdJEdTFMhiyXqyXubBa0WVLDWSNlQ5JR2PNgDbEV1VQowhVRUh+74D+RA==} cpu: [x64] os: [linux] + libc: [glibc] requiresBuild: true dev: true optional: true @@ -1659,6 +1662,7 @@ packages: resolution: {integrity: sha512-RkJVNVRM+piYy87HrKmhbexCHg3A6Z6MU0W9GHnJwBQNBeyhCJG9KDce4SAMdicQnpURggSvtbGo9xAWOfSvIQ==} cpu: [x64] os: [linux] + libc: [musl] requiresBuild: true dev: true optional: true @@ -1717,8 +1721,8 @@ packages: resolution: {integrity: sha512-WzfNs9BLDNTXyc0RZQjkPtzmTrDV6nqdZR9+uRAbPPERyrUvc5L6prX+KnXCatEBdfyiSlfNRfe05UCI33LC9A==} dev: true - /@typora-community-plugin/typora-types/1.0.8: - resolution: {integrity: sha512-FzGiuJp1jAIOZ7aTQHqXdtfrepwFdngYzRRlneMrFnopOsc6pBdbElWcKHHar7xc5rSWXa8iHeCrQPTxRi00wg==} + /@typora-community-plugin/typora-types/1.0.10: + resolution: {integrity: sha512-KJU4skdsPsiQ+EPH8Muqj6r9onRBcu1AGIvJc+HX7TQhJ/9pGn0668xQyyS53p9QzwEOTzk7Zoz5U2wl16XPtg==} dev: true /acorn/8.11.2: diff --git a/src/main.ts b/src/main.ts index 9a58764..9d94cf3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -30,13 +30,17 @@ export default class LangMapperPlugin extends Plugin { 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)) diff --git a/src/manifest.json b/src/manifest.json index aa27bb5..fa8a4c4 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -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"]