'use strict'; var utilExtractor = require('@flatfile/util-extractor'); var nodeHtmlParser = require('node-html-parser'); function f(n,e){e.debug&&console.log("Parsing buffer...");let l=n.toString("utf-8"),c=x(l,e),t={};return c.forEach((r,a)=>{let o=`Table_${a+1}`;t[o]={headers:r.headers,data:r.rows.map(g=>{let h={};return g.forEach((s,u)=>{u{let a=[],o=[];e.debug&&console.log(`Processing table ${r+1}`),t.querySelectorAll("th").forEach(g=>{a.push(g.text.trim());}),e.debug&&console.log("Extracted headers:",a),t.querySelectorAll("tr").forEach((g,h)=>{let s=[];g.querySelectorAll("td").forEach((u,b)=>{let i=u.text.trim();if(e.handleColspan&&u.getAttribute("colspan")){let m=parseInt(u.getAttribute("colspan")||"1",10);for(let d=0;d0&&o.push(s);}),e.handleRowspan&&w(o),c.push({headers:a,rows:o}),e.debug&&console.log(`Extracted table ${r+1}:`,{headers:a,rows:o});}),e.debug&&console.log(`Extraction complete. Found ${c.length} tables.`),c}function w(n){let e={};n.forEach((l,c)=>{Object.keys(e).forEach(t=>{let r=parseInt(t,10);e[r].rowspan>0&&(l.splice(r,0,e[r].value),e[r].rowspan--);}),l.forEach((t,r)=>{let a=nodeHtmlParser.parse(`${t}`).querySelector("td");if(a&&a.getAttribute("rowspan")){let o=parseInt(a.getAttribute("rowspan")||"1",10)-1;o>0&&(e[r]={value:t,rowspan:o});}});});}var S=(n={})=>utilExtractor.Extractor("html","html-tables",f,n),$=f; exports.HTMLTableExtractor = S; exports.htmlTableParser = $; //# sourceMappingURL=index.cjs.map //# sourceMappingURL=index.cjs.map