From f8cd441ed82e2c264b0042d54ab1b81cb0a8774d Mon Sep 17 00:00:00 2001 From: yanmao <55792257+yanmao-cc@users.noreply.github.com> Date: Sun, 13 Feb 2022 21:34:43 +0800 Subject: [PATCH] =?UTF-8?q?update(iamge=20&=20link):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=20markdown=20=E8=A7=A3=E6=9E=90=E5=92=8C=E8=A7=A6=E5=8F=91?= =?UTF-8?q?=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/image/src/uploader.ts | 20 +++++++++----------- plugins/link-vue/src/index.ts | 2 +- plugins/link/src/index.ts | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/plugins/image/src/uploader.ts b/plugins/image/src/uploader.ts index e0e56941..9b7cdbee 100644 --- a/plugins/image/src/uploader.ts +++ b/plugins/image/src/uploader.ts @@ -148,7 +148,7 @@ export default class< init() { if (isEngine(this.editor)) { - this.editor.on('keydown:enter', (event) => this.markdown(event)); + this.editor.on('keydown:space', (event) => this.markdown(event)); this.editor.on('drop:files', (files) => this.dropFiles(files)); this.editor.on('paste:event', ({ files }) => this.pasteFiles(files), @@ -684,20 +684,18 @@ export default class< const range = change.range.get(); if (!range.collapsed || change.isComposing() || !this.markdown) return; - const blockApi = this.editor.block; - const block = blockApi.closest(range.startNode); - - if (!node.isRootBlock(block)) { - return; - } - - const chars = blockApi.getLeftText(block); - const match = /!\[([^\]]{0,})\]\((https?:\/\/[^\)]{5,})\)/.exec(chars); + const cloneRange = range.cloneRange(); + cloneRange.shrinkToTextNode(); + const { startNode } = cloneRange; + if (!startNode.isText()) return; + const text = startNode.text(); + const match = /!\[([^\]]{0,})\]\((https?:\/\/[^\)]{5,})\)/.exec(text); if (match) { + cloneRange.setStart(startNode, match.index); + change.range.select(cloneRange); event.preventDefault(); const splits = match[1].split('|'); const src = match[2]; - blockApi.removeLeftText(block); const alignment = splits[1]; if (alignment === 'center' || alignment === 'right') { this.editor.command.execute('alignment', alignment); diff --git a/plugins/link-vue/src/index.ts b/plugins/link-vue/src/index.ts index 7068752d..e2e107f8 100644 --- a/plugins/link-vue/src/index.ts +++ b/plugins/link-vue/src/index.ts @@ -41,7 +41,7 @@ export default class< markdown = this.options.markdown === undefined - ? '\\[(.+?)\\]\\(s*([\\S]+?)\\s*\\)$' + ? '[^!]\\[(.+?)\\]\\(s*([\\S]+?)\\s*\\)$' : this.options.markdown; init() { diff --git a/plugins/link/src/index.ts b/plugins/link/src/index.ts index 1e0a2d34..f737b28a 100644 --- a/plugins/link/src/index.ts +++ b/plugins/link/src/index.ts @@ -45,7 +45,7 @@ export default class< markdown = this.options.markdown === undefined - ? '\\[(.+?)\\]\\(\\s*([\\S]+?)\\s*\\)$' + ? '[^!]\\[(.+?)\\]\\(\\s*([\\S]+?)\\s*\\)$' : this.options.markdown; init() {