import{c}from"./chunk-AH77CRWX.js";import{a as u,b as f,c as h}from"./chunk-74CEPOFO.js";import p from"turndown";var w={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"]},y={name:"html-to-markdown",async execute(r,n){if(f(r))return u(w);let s="-",a="```",i="---",m="atx",o=[];for(let e=0;e<r.length;e++){let t=r[e];if(t==="-b"||t==="--bullet")s=r[++e]??"-";else if(t.startsWith("--bullet="))s=t.slice(9);else if(t==="-c"||t==="--code")a=r[++e]??"```";else if(t.startsWith("--code="))a=t.slice(7);else if(t==="-r"||t==="--hr")i=r[++e]??"---";else if(t.startsWith("--hr="))i=t.slice(5);else if(t.startsWith("--heading-style=")){let d=t.slice(16);(d==="setext"||d==="atx")&&(m=d)}else if(t==="-")o.push("-");else{if(t.startsWith("--"))return h("html-to-markdown",t);if(t.startsWith("-"))return h("html-to-markdown",t);o.push(t)}}let l;if(o.length===0||o.length===1&&o[0]==="-")l=c(n.stdin);else try{let e=n.fs.resolvePath(n.cwd,o[0]);l=await n.fs.readFile(e)}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 e=new p({bulletListMarker:s,codeBlockStyle:"fenced",fence:a,hr:i,headingStyle:m});return e.remove(["script","style","footer"]),{stdout:`${e.turndown(l).trim()}
`,stderr:"",exitCode:0}}catch(e){return{stdout:"",stderr:`html-to-markdown: conversion error: ${e.message}
`,exitCode:1}}}},b={name:"html-to-markdown",flags:[],stdinType:"text"};export{y as a,b};
