From 8f1cce88d2b065d8070f112d4ff51a59f9f4b98b Mon Sep 17 00:00:00 2001 From: Rolaka Date: Sun, 5 Feb 2023 12:52:21 +0800 Subject: [PATCH] (fix) refine attributeRegex Fix attributeRegex that correctly match attributes that are not enclosed in quotes. fix #344 --- src/lib/extractAttributes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/extractAttributes.ts b/src/lib/extractAttributes.ts index bd5208a8..7fbbb41c 100644 --- a/src/lib/extractAttributes.ts +++ b/src/lib/extractAttributes.ts @@ -2,7 +2,7 @@ import { AttributeNode, TextNode } from '../print/nodes'; export function extractAttributes(html: string): AttributeNode[] { const extractAttributesRegex = /<[a-z]+[\s\n]*([\s\S]*?)>/im; - const attributeRegex = /([^\s=]+)(?:=("|')([\s\S]*?)\2)?/gim; + const attributeRegex = /([^\s=]+)(?:=("|')([\s\S]*?)\2)?(?:[ >]|$)/gim; const [, attributesString] = html.match(extractAttributesRegex)!;