#compdef html-to-markdown

autoload -U is-at-least

_html-to-markdown() {
    typeset -A opt_args
    typeset -a _arguments_options
    local ret=1

    if is-at-least 5.2; then
        _arguments_options=(-s -S -C)
    else
        _arguments_options=(-s -C)
    fi

    local context curcontext="$curcontext" state line
    _arguments "${_arguments_options[@]}" : \
'()--url=[Fetch HTML from a URL (alternative to file/stdin)]:URL:_default' \
'--user-agent=[User-Agent header when fetching via --url (default mimics a real browser)]:UA:_default' \
'-o+[Output file (default\: stdout)]:FILE:_files' \
'--output=[Output file (default\: stdout)]:FILE:_files' \
'--generate-completion=[Generate shell completion script]:SHELL:(bash zsh fish power-shell elvish)' \
'--heading-style=[Heading style]:STYLE:((atx\:"ATX style\: # for h1, ## for h2 (default)"
underlined\:"Underlined\: === for h1, --- for h2"
atx-closed\:"ATX closed\: # Title #"))' \
'--list-indent-type=[List indentation type]:TYPE:((spaces\:"Use spaces for indentation"
tabs\:"Use tabs for indentation"))' \
'--list-indent-width=[Spaces per list indent level]:N:_default' \
'-b+[Bullet characters for unordered lists]:CHARS:_default' \
'--bullets=[Bullet characters for unordered lists]:CHARS:_default' \
'--strong-em-symbol=[Symbol for bold and italic]:CHAR:_default' \
'--sub-symbol=[Symbol to wrap subscript text]:SYMBOL:_default' \
'--sup-symbol=[Symbol to wrap superscript text]:SYMBOL:_default' \
'--newline-style=[Line break style]:STYLE:((spaces\:"Two spaces at end of line (default)"
backslash\:"Backslash at end of line"))' \
'--code-block-style=[Code block style]:STYLE:((indented\:"Indented code blocks\: 4 spaces"
backticks\:"Fenced code blocks (backtick style) (default)"
tildes\:"Fenced code blocks\: ~~~"))' \
'-l+[Default language for code blocks]:LANG:_default' \
'--code-language=[Default language for code blocks]:LANG:_default' \
'--link-style=[Link rendering style]:STYLE:((inline\:"Inline links\: \[text\](url) (default)"
reference\:"Reference-style links\: \[text\]\[1\] with definitions at end"))' \
'--url-escape-style=[URL escaping style for link and image destinations]:STYLE:((angle\:"Wrap destinations containing spaces or newlines in angle brackets (default)"
percent\:"Percent-encode all characters that are not RFC 3986 unreserved or \`/\`"))' \
'*--keep-inline-images-in=[Keep inline images in specific elements]:ELEMENTS:_default' \
'--max-image-size=[Maximum decoded image size in bytes]:BYTES:_default' \
'--highlight-style=[Style for \`<mark>\` elements]:STYLE:((double-equal\:"==text== (default)"
html\:"<mark>text</mark>"
bold\:"**text**"
none\:"Plain text"))' \
'--whitespace-mode=[Whitespace handling mode]:MODE:((normalized\:"Normalize whitespace (default)"
strict\:"Preserve whitespace as-is"))' \
'--wrap-width=[Wrap width in columns]:N:_default' \
'*--strip-tags=[HTML tags to strip]:TAGS:_default' \
'*--preserve-tags=[HTML tags to preserve verbatim]:TAGS:_default' \
'*--exclude-selectors=[CSS selectors for elements to exclude entirely]:SELECTORS:_default' \
'--max-depth=[Maximum DOM traversal depth]:N:_default' \
'--preset=[Preprocessing aggressiveness preset]:LEVEL:((minimal\:"Basic cleanup"
standard\:"Balanced cleaning (default)"
aggressive\:"Maximum cleaning"))' \
'--tier-strategy=[Conversion tier strategy]:STRATEGY:((auto\:"Automatically pick the best conversion tier for the input (default)"
tier2\:"Always use the Tier-2 (DOM-walk) path, skipping Tier-1"))' \
'-e+[Input character encoding]:ENCODING:_default' \
'--encoding=[Input character encoding]:ENCODING:_default' \
'-f+[Output format (markdown or djot)]:FORMAT:((markdown\:"Standard Markdown (\`CommonMark\` compatible)"
djot\:"Djot lightweight markup language"
plain\:"Plain text (no markup)"))' \
'--output-format=[Output format (markdown or djot)]:FORMAT:((markdown\:"Standard Markdown (\`CommonMark\` compatible)"
djot\:"Djot lightweight markup language"
plain\:"Plain text (no markup)"))' \
'--generate-man[Generate man page]' \
'--escape-asterisks[Escape asterisk (*) characters]' \
'--escape-underscores[Escape underscore (_) characters]' \
'--escape-misc[Escape misc Markdown characters]' \
'--escape-ascii[Escape all ASCII punctuation]' \
'--no-autolinks[Disable autolink conversion]' \
'--default-title[Add default title to links]' \
'--capture-svg[Capture inline \`<svg>\` elements as images]' \
'--no-infer-dimensions[Disable image dimension inference]' \
'--br-in-tables[Use <br> in table cells]' \
'--compact-tables[Emit compact (unpadded) GFM tables]' \
'--extract-metadata[Extract metadata from HTML]' \
'--json[Output full \`ConversionResult\` as JSON instead of markdown text]' \
'--include-structure[Include structured document tree in output]' \
'--extract-inline-images[Extract inline images from data URIs and SVGs]' \
'--show-warnings[Emit one WARN-level tracing event per conversion warning]' \
'--no-content[Null out the "content" field in JSON output]' \
'--strip-newlines[Strip newlines from input]' \
'-w[Enable text wrapping]' \
'--wrap[Enable text wrapping]' \
'--convert-as-inline[Treat block elements as inline]' \
'--skip-images[Skip image elements]' \
'-p[Enable HTML preprocessing]' \
'--preprocess[Enable HTML preprocessing]' \
'--keep-navigation[Keep navigation elements]' \
'--keep-forms[Keep form elements]' \
'--debug[Enable debug mode]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
'::input -- Input HTML file (use \"-\" or omit for stdin):_default' \
":: :_html-to-markdown_commands" \
"*::: :->html-to-markdown" \
&& ret=0
    case $state in
    (html-to-markdown)
        words=($line[2] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:html-to-markdown-command-$line[2]:"
        case $line[2] in
            (mcp)
_arguments "${_arguments_options[@]}" : \
'--transport=[Transport mode\: "stdio" (default) or "http"]:TRANSPORT:_default' \
'--host=[HTTP host (only used with --transport http)]:HOST:_default' \
'--port=[HTTP port (only used with --transport http)]:PORT:_default' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_html-to-markdown__subcmd__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:html-to-markdown-help-command-$line[1]:"
        case $line[1] in
            (mcp)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_html-to-markdown_commands] )) ||
_html-to-markdown_commands() {
    local commands; commands=(
'mcp:Run as an MCP (Model Context Protocol) server' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'html-to-markdown commands' commands "$@"
}
(( $+functions[_html-to-markdown__subcmd__help_commands] )) ||
_html-to-markdown__subcmd__help_commands() {
    local commands; commands=(
'mcp:Run as an MCP (Model Context Protocol) server' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'html-to-markdown help commands' commands "$@"
}
(( $+functions[_html-to-markdown__subcmd__help__subcmd__help_commands] )) ||
_html-to-markdown__subcmd__help__subcmd__help_commands() {
    local commands; commands=()
    _describe -t commands 'html-to-markdown help help commands' commands "$@"
}
(( $+functions[_html-to-markdown__subcmd__help__subcmd__mcp_commands] )) ||
_html-to-markdown__subcmd__help__subcmd__mcp_commands() {
    local commands; commands=()
    _describe -t commands 'html-to-markdown help mcp commands' commands "$@"
}
(( $+functions[_html-to-markdown__subcmd__mcp_commands] )) ||
_html-to-markdown__subcmd__mcp_commands() {
    local commands; commands=()
    _describe -t commands 'html-to-markdown mcp commands' commands "$@"
}

if [ "$funcstack[1]" = "_html-to-markdown" ]; then
    _html-to-markdown "$@"
else
    compdef _html-to-markdown html-to-markdown
fi
