From ef94a378fb0e9ad7ac45c842a96ae48fe6227514 Mon Sep 17 00:00:00 2001 From: Amelia Wattenberger Date: Tue, 30 Aug 2022 13:33:19 -0700 Subject: [PATCH] fix: markdown: default image width to 100% --- blocks/file-blocks/markdown-edit/extensions.ts | 4 +++- blocks/file-blocks/markdown-edit/image-widget.tsx | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/blocks/file-blocks/markdown-edit/extensions.ts b/blocks/file-blocks/markdown-edit/extensions.ts index de78b95..afad1b5 100644 --- a/blocks/file-blocks/markdown-edit/extensions.ts +++ b/blocks/file-blocks/markdown-edit/extensions.ts @@ -166,8 +166,10 @@ export function makeExtensions({ !(match = /^https?:\/\/.*/.exec(fullText)) ) return -1; + const hasIncludedLink = match[0].indexOf("](http") !== -1; + if (hasIncludedLink) return -1; return cx.addElement( - cx.elt("URL", start, start + 1 + match[0].length) + cx.elt("URL", start, start + 1 + firstMatch.length) ); }, }, diff --git a/blocks/file-blocks/markdown-edit/image-widget.tsx b/blocks/file-blocks/markdown-edit/image-widget.tsx index f14d295..442f92a 100644 --- a/blocks/file-blocks/markdown-edit/image-widget.tsx +++ b/blocks/file-blocks/markdown-edit/image-widget.tsx @@ -60,7 +60,7 @@ class ImageWidget extends WidgetType { if (Number.isFinite(+style)) return `${style}px`; return style; }; - image.style.width = parseStyle(this.width) || "auto"; + image.style.width = parseStyle(this.width) || "100%"; image.style.maxWidth = "100%"; image.style.height = parseStyle(this.height) || "auto"; image.alt = this.alt || ""; @@ -97,7 +97,6 @@ export const images = ({ enter: ({ type, from, to }) => { if (type.name === "Image") { const text = state.doc.sliceString(from, to); - console.log(text); const result = imageRegex.exec(text); if (result && result.groups && result.groups.url) {