* Parses a fenced code block metadata string into a JavaScript object. * @param {string} meta - The metadata string from a Markdown code fence. * @returns {Record } An object representing the metadata.
(meta)
| 19 | * @returns {Record<string, string|boolean>} An object representing the metadata. |
| 20 | */ |
| 21 | function parseMeta(meta) { |
| 22 | const obj = { __raw: meta }; |
| 23 | |
| 24 | if (!meta) { |
| 25 | return obj; |
| 26 | } |
| 27 | |
| 28 | let match; |
| 29 | |
| 30 | while ((match = rMeta.exec(meta)) !== null) { |
| 31 | obj[match[1]] = match[2] ?? match[3] ?? true; |
| 32 | } |
| 33 | |
| 34 | return obj; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * @typedef {import('unist').Node} Node |