import{a as c,b as u,c as h}from"./chunk-74CEPOFO.js";import"./chunk-DXB73IDG.js";import f from"turndown";var p={name:"html-to-markdown",summary:"convert HTML to Markdown (BashEnv extension)",usage:"html-to-markdown [OPTION]... [FILE]",description:["Convert HTML content to Markdown format using the turndown library.","This is a non-standard BashEnv extension command, not available in regular bash.","","Read HTML from FILE or standard input and output Markdown to standard output.","Commonly used with curl to convert web pages:","  curl -s https://example.com | html-to-markdown","","Supported HTML elements:","  - Headings (h1-h6) \u2192 # Markdown headings","  - Paragraphs (p) \u2192 Plain text with blank lines","  - Links (a) \u2192 [text](url)","  - Images (img) \u2192 ![alt](src)","  - Bold/Strong \u2192 **text**","  - Italic/Em \u2192 _text_","  - Code (code, pre) \u2192 `inline` or fenced blocks","  - Lists (ul, ol, li) \u2192 - or 1. items","  - Blockquotes \u2192 > quoted text","  - Horizontal rules (hr) \u2192 ---"],options:["-b, --bullet=CHAR     bullet character for unordered lists (-, +, or *)","-c, --code=FENCE      fence style for code blocks (``` or ~~~)","-r, --hr=STRING       string for horizontal rules (default: ---)","    --heading-style=STYLE","                      heading style: 'atx' for # headings (default),","                      'setext' for underlined headings (h1/h2 only)","    --help            display this help and exit"],examples:["echo '<h1>Hello</h1><p>World</p>' | html-to-markdown","html-to-markdown page.html","curl -s https://example.com | html-to-markdown > page.md"]},g={name:"html-to-markdown",async execute(r,n){if(u(r))return c(p);let s="-",a="```",i="---",m="atx",o=[];for(let t=0;t<r.length;t++){let e=r[t];if(e==="-b"||e==="--bullet")s=r[++t]??"-";else if(e.startsWith("--bullet="))s=e.slice(9);else if(e==="-c"||e==="--code")a=r[++t]??"```";else if(e.startsWith("--code="))a=e.slice(7);else if(e==="-r"||e==="--hr")i=r[++t]??"---";else if(e.startsWith("--hr="))i=e.slice(5);else if(e.startsWith("--heading-style=")){let d=e.slice(16);(d==="setext"||d==="atx")&&(m=d)}else if(e==="-")o.push("-");else{if(e.startsWith("--"))return h("html-to-markdown",e);if(e.startsWith("-"))return h("html-to-markdown",e);o.push(e)}}let l;if(o.length===0||o.length===1&&o[0]==="-")l=n.stdin;else try{let t=n.fs.resolvePath(n.cwd,o[0]);l=await n.fs.readFile(t)}catch{return{stdout:"",stderr:`html-to-markdown: ${o[0]}: No such file or directory
`,exitCode:1}}if(!l.trim())return{stdout:"",stderr:"",exitCode:0};try{let t=new f({bulletListMarker:s,codeBlockStyle:"fenced",fence:a,hr:i,headingStyle:m});return t.remove(["script","style","footer"]),{stdout:`${t.turndown(l).trim()}
`,stderr:"",exitCode:0}}catch(t){return{stdout:"",stderr:`html-to-markdown: conversion error: ${t.message}
`,exitCode:1}}}};export{g as htmlToMarkdownCommand};
