const quantity = require("./native-quantity.cjs"); function rowParser(text) { const superscripts = new Set( [...text.matchAll(/]*\bnr=(\d+)[^>]*>/gi)] .filter((match) => (Number(match[0].match(/CharStyleON:(\d+)/)?.[1] || 0) & 16) !== 0) .map((match) => match[1]), ); const tags = new Map(); for (const match of text.matchAll(/]*\bTag=(\d+)[^>]*>/gi)) { if (quantity.entities(match[0]).match(/Name:["']([^"']+)["']/)) tags.set(match[1], match[0]); } return (div) => { const ids = new Set([...div.matchAll(/\bTag=(\d+)/gi)].map((match) => match[1])); const declarations = [...ids].map((id) => tags.get(id) || "").join(""); const styles = [...new Set([...div.matchAll(//gi)].map((m) => m[1]))] .filter((id) => superscripts.has(id)) .map((id) => ``) .join(""); return quantity.fromWpt("", "", styles + declarations + div, [], {}).rows; }; } module.exports = { rowParser };