|
@@ -2,24 +2,31 @@
|
|
|
export let token;
|
|
|
export let onClick: Function = () => {};
|
|
|
|
|
|
- let id = '';
|
|
|
- function extractDataAttribute(input) {
|
|
|
- // Use a regular expression to extract the value of the `data` attribute
|
|
|
- const match = input.match(/data="([^"]*)"/);
|
|
|
- // Check if a match was found and return the first captured group
|
|
|
- return match ? match[1] : null;
|
|
|
+ let attributes: Record<string, string> = {};
|
|
|
+
|
|
|
+ function extractAttributes(input: string): Record<string, string> {
|
|
|
+ const regex = /(\w+)="([^"]*)"/g;
|
|
|
+ let match;
|
|
|
+ let attrs: Record<string, string> = {};
|
|
|
+
|
|
|
+ // Loop through all matches and populate the attributes object
|
|
|
+ while ((match = regex.exec(input)) !== null) {
|
|
|
+ attrs[match[1]] = match[2];
|
|
|
+ }
|
|
|
+
|
|
|
+ return attrs;
|
|
|
}
|
|
|
|
|
|
- $: id = extractDataAttribute(token.text);
|
|
|
+ $: attributes = extractAttributes(token.text);
|
|
|
</script>
|
|
|
|
|
|
<button
|
|
|
class="text-xs font-medium w-fit translate-y-[2px] px-2 py-0.5 dark:bg-white/5 dark:text-white/60 dark:hover:text-white bg-gray-50 text-black/60 hover:text-black transition rounded-lg"
|
|
|
on:click={() => {
|
|
|
- onClick(id);
|
|
|
+ onClick(attributes.data);
|
|
|
}}
|
|
|
>
|
|
|
<span class="line-clamp-1">
|
|
|
- {id}
|
|
|
+ {attributes.title}
|
|
|
</span>
|
|
|
</button>
|