Skip to content

Commit

Permalink
fix: duplicate improted attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
TorstenDittmann committed Jan 4, 2024
1 parent 7115e67 commit cc32217
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/process/package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
25 changes: 14 additions & 11 deletions packages/process/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
<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 comments on commit cc32217

Please sign in to comment.