fix(markdown): keep hyphenated block attribute keys
The key pattern \w+ could not cross a hyphen, so data-config=foo was parsed as config=foo and the data- prefix was lost. Allow hyphens in keys, matching parseDirectiveAttrs.
This commit is contained in:
@@ -14,10 +14,16 @@ export interface BlockAttrs {
|
||||
extra: Record<string, string>;
|
||||
}
|
||||
|
||||
/** Parse key="value" and key=value pairs from an attribute string. */
|
||||
/**
|
||||
* Parse key="value" and key=value pairs from an attribute string.
|
||||
*
|
||||
* Keys may contain hyphens (e.g. `data-config=...`); the key must start with a
|
||||
* letter or underscore so a leading `-` is treated as part of a value, not a
|
||||
* key.
|
||||
*/
|
||||
export function parseBlockAttrs(info: string): BlockAttrs {
|
||||
const attrs: Record<string, string> = {};
|
||||
const re = /(\w+)\s*=\s*("[^"]*"|\S+)/g;
|
||||
const re = /([A-Za-z_][\w-]*)\s*=\s*("[^"]*"|\S+)/g;
|
||||
let m: RegExpExecArray | null;
|
||||
while ((m = re.exec(info)) !== null) {
|
||||
attrs[m[1]] = m[2].replace(/^"|"$/g, "");
|
||||
|
||||
Reference in New Issue
Block a user