From cd75cf0fcf8e095cda72d523799ff7e3e19d36c1 Mon Sep 17 00:00:00 2001 From: Oleksandr Maslakov Date: Sun, 15 Oct 2023 20:07:07 +0300 Subject: [PATCH 1/2] Fix #361 Error converting Image Block to Markdown --- .../formatConversions/simplifyBlocksRehypePlugin.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/core/src/api/formatConversions/simplifyBlocksRehypePlugin.ts b/packages/core/src/api/formatConversions/simplifyBlocksRehypePlugin.ts index 13fa69e783..53eb46f0d9 100644 --- a/packages/core/src/api/formatConversions/simplifyBlocksRehypePlugin.ts +++ b/packages/core/src/api/formatConversions/simplifyBlocksRehypePlugin.ts @@ -38,6 +38,8 @@ export function simplifyBlocks(options: SimplifyBlocksOptions) { blockContent.properties!["dataContentType"] as string ); + const isImageBlock = blockContent.properties!["dataContentType"] as string === 'image'; + const listItemBlockType = isListItemBlock ? options.orderedListItemBlockTypes.has( blockContent.properties!["dataContentType"] as string @@ -104,6 +106,15 @@ export function simplifyBlocks(options: SimplifyBlocksOptions) { const numElementsAdded = blockGroup.children.length; i += numElementsAdded; numChildElements += numElementsAdded; + } else if (isImageBlock) { + const img = document.createElement("img"); + img.setAttribute('src', blockContent.properties!['dataUrl'] as string || ''); + + const imgElement = fromDom( + img + ) as HASTElement; + + tree.children[i] = imgElement; } else { // Replaces the block with only the content inside it. tree.children[i] = blockContent.children[0]; From 9e61058880f38afa0e7d0d7e87a0d344ec27bd16 Mon Sep 17 00:00:00 2001 From: Oleksandr Maslakov Date: Sun, 15 Oct 2023 22:06:08 +0300 Subject: [PATCH 2/2] Add: caption --- .../core/src/api/formatConversions/simplifyBlocksRehypePlugin.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/api/formatConversions/simplifyBlocksRehypePlugin.ts b/packages/core/src/api/formatConversions/simplifyBlocksRehypePlugin.ts index 53eb46f0d9..01b1edbde6 100644 --- a/packages/core/src/api/formatConversions/simplifyBlocksRehypePlugin.ts +++ b/packages/core/src/api/formatConversions/simplifyBlocksRehypePlugin.ts @@ -109,6 +109,7 @@ export function simplifyBlocks(options: SimplifyBlocksOptions) { } else if (isImageBlock) { const img = document.createElement("img"); img.setAttribute('src', blockContent.properties!['dataUrl'] as string || ''); + img.setAttribute('alt', blockContent.properties!['dataCaption'] as string || ''); const imgElement = fromDom( img