Skip to content

Commit cc32217

Browse files
fix: duplicate improted attribute
1 parent 7115e67 commit cc32217

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

packages/process/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "svelte-markdoc-preprocess",
3-
"version": "2.0.0-rc.2",
3+
"version": "2.0.0-rc.3",
44
"description": "A Svelte preprocessor that allows you to use Markdoc.",
55
"type": "commonjs",
66
"keywords": [

packages/process/src/renderer.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,23 @@ export function render_html(
5050
*/
5151
let output = `<${name}`;
5252
for (const [key, value] of Object.entries(attributes ?? {})) {
53-
const is_imported_image = key === 'src' && is_relative_path(value);
53+
const is_src_key = key === 'src';
54+
const is_imported_image = is_src_key && is_relative_path(value);
5455
if (is_svelte) {
5556
switch (name.toLowerCase()) {
5657
case `${NODES_IMPORT}.image`.toLowerCase():
57-
if (is_imported_image) {
58-
const unique_name = `${IMAGE_PREFIX}${dependencies.size}`;
59-
dependencies.set(unique_name, String(value));
60-
output += ` imported={true} ${key.toLowerCase()}=${generate_svelte_attribute_value(
61-
unique_name,
62-
'import',
63-
)}`;
64-
break;
65-
} else {
66-
output += ` imported={false}`;
58+
if (is_src_key) {
59+
if (is_imported_image) {
60+
const unique_name = `${IMAGE_PREFIX}${dependencies.size}`;
61+
dependencies.set(unique_name, String(value));
62+
output += ` imported={true} ${key.toLowerCase()}=${generate_svelte_attribute_value(
63+
unique_name,
64+
'import',
65+
)}`;
66+
break;
67+
} else {
68+
output += ` imported={false}`;
69+
}
6770
}
6871

6972
default:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<script>import * as INTERNAL__NODES from 'tests/nodes/module.svelte';import IMAGE__1 from './image.jpeg';import IMAGE__2 from '../images/image.jpeg';</script><article><p><INTERNAL__NODES.Image imported={true} src={IMAGE__1} imported={false} alt=""></INTERNAL__NODES.Image> <INTERNAL__NODES.Image imported={true} src={IMAGE__2} imported={false} alt=""></INTERNAL__NODES.Image> <INTERNAL__NODES.Image imported={false} src="image.jpeg" imported={false} alt=""></INTERNAL__NODES.Image> <INTERNAL__NODES.Image imported={false} src="/image.jpeg" imported={false} alt=""></INTERNAL__NODES.Image> <INTERNAL__NODES.Image imported={false} src="https://github.com/logo.jpeg" imported={false} alt=""></INTERNAL__NODES.Image></p></article>
1+
<script>import * as INTERNAL__NODES from 'tests/nodes/module.svelte';import IMAGE__1 from './image.jpeg';import IMAGE__2 from '../images/image.jpeg';</script><article><p><INTERNAL__NODES.Image imported={true} src={IMAGE__1} alt=""></INTERNAL__NODES.Image> <INTERNAL__NODES.Image imported={true} src={IMAGE__2} alt=""></INTERNAL__NODES.Image> <INTERNAL__NODES.Image imported={false} src="image.jpeg" alt=""></INTERNAL__NODES.Image> <INTERNAL__NODES.Image imported={false} src="/image.jpeg" alt=""></INTERNAL__NODES.Image> <INTERNAL__NODES.Image imported={false} src="https://github.com/logo.jpeg" alt=""></INTERNAL__NODES.Image></p></article>

0 commit comments

Comments
 (0)