Skip to content

Commit

Permalink
feat: data-attribute-remover (#1023)
Browse files Browse the repository at this point in the history
  • Loading branch information
Scooter1337 authored Apr 18, 2024
1 parent 1f320b4 commit 4fc051f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion apps/www/src/lib/components/docs/block-copy-code-button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
hasCopied = false;
}, 2000);
}
function copyToClipboard() {
// Remove data-x-chunk-name and data-x-chunk-description attributes from the code
const re = /<([a-zA-Z0-9.]+)([^>]*)data-x-chunk-name="[^"]*"([^>]*)>/g;
const result = code.replace(re, (_all, elementName, p2, p3) => {
// remove data-x-chunk-description from p2, leaves only the other attributes (scattered in p2 and p3)
const otherAttributes = (p2 + p3)
.replace(/data-x-chunk-description="[^"]*"/, "")
.trim();
return otherAttributes ? `<${elementName} ${otherAttributes}>` : `<${elementName}>`;
});
navigator.clipboard.writeText(result);
}
</script>

<Tooltip.Root>
Expand All @@ -22,7 +37,7 @@
class="h-7 w-7 rounded-[6px] [&_svg]:size-3.5"
builders={[builder]}
on:click={() => {
navigator.clipboard.writeText(code);
copyToClipboard();
hasCopied = true;
}}
{...$$restProps}
Expand Down

0 comments on commit 4fc051f

Please sign in to comment.