From d731e82fba3819143144d3d64ebb71309284c4df Mon Sep 17 00:00:00 2001 From: Jaiwanth Date: Mon, 1 Mar 2021 22:44:48 +0530 Subject: [PATCH] Fixed edit for markdown images Signed-off-by: Jaiwanth --- src/editor/deserialize.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/editor/deserialize.ts b/src/editor/deserialize.ts index 6336b4c46b..bc1dd74c7d 100644 --- a/src/editor/deserialize.ts +++ b/src/editor/deserialize.ts @@ -60,6 +60,11 @@ function parseLink(a: HTMLAnchorElement, partCreator: PartCreator) { } } +function parseImage(img: HTMLImageElement, partCreator: PartCreator) { + const { src } = img; + return partCreator.plain(`![${img.alt.replace(/[[\\\]]/g, c => "\\" + c)}](${src})`); +} + function parseCodeBlock(n: HTMLElement, partCreator: PartCreator) { const parts = []; let language = ""; @@ -102,6 +107,8 @@ function parseElement(n: HTMLElement, partCreator: PartCreator, lastNode: HTMLEl return parseHeader(n, partCreator); case "A": return parseLink(n, partCreator); + case "IMG": + return parseImage(n, partCreator); case "BR": return partCreator.newline(); case "EM":