From cc32217c10d660f1c43ce3f9885f7e5e3eda3c91 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Thu, 4 Jan 2024 14:18:21 +0100 Subject: [PATCH] fix: duplicate improted attribute --- packages/process/package.json | 2 +- packages/process/src/renderer.ts | 25 +++++++++++-------- .../images - enhanced - node/compiled.txt | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/packages/process/package.json b/packages/process/package.json index a34bbf5..d400805 100644 --- a/packages/process/package.json +++ b/packages/process/package.json @@ -1,6 +1,6 @@ { "name": "svelte-markdoc-preprocess", - "version": "2.0.0-rc.2", + "version": "2.0.0-rc.3", "description": "A Svelte preprocessor that allows you to use Markdoc.", "type": "commonjs", "keywords": [ diff --git a/packages/process/src/renderer.ts b/packages/process/src/renderer.ts index 5b1a121..3f6b546 100644 --- a/packages/process/src/renderer.ts +++ b/packages/process/src/renderer.ts @@ -50,20 +50,23 @@ export function render_html( */ let output = `<${name}`; for (const [key, value] of Object.entries(attributes ?? {})) { - const is_imported_image = key === 'src' && is_relative_path(value); + const is_src_key = key === 'src'; + const is_imported_image = is_src_key && is_relative_path(value); if (is_svelte) { switch (name.toLowerCase()) { case `${NODES_IMPORT}.image`.toLowerCase(): - if (is_imported_image) { - const unique_name = `${IMAGE_PREFIX}${dependencies.size}`; - dependencies.set(unique_name, String(value)); - output += ` imported={true} ${key.toLowerCase()}=${generate_svelte_attribute_value( - unique_name, - 'import', - )}`; - break; - } else { - output += ` imported={false}`; + if (is_src_key) { + if (is_imported_image) { + const unique_name = `${IMAGE_PREFIX}${dependencies.size}`; + dependencies.set(unique_name, String(value)); + output += ` imported={true} ${key.toLowerCase()}=${generate_svelte_attribute_value( + unique_name, + 'import', + )}`; + break; + } else { + output += ` imported={false}`; + } } default: diff --git a/packages/process/tests/processor/images - enhanced - node/compiled.txt b/packages/process/tests/processor/images - enhanced - node/compiled.txt index 126d2aa..69b1e76 100644 --- a/packages/process/tests/processor/images - enhanced - node/compiled.txt +++ b/packages/process/tests/processor/images - enhanced - node/compiled.txt @@ -1 +1 @@ -

\ No newline at end of file +

\ No newline at end of file