#![allow(missing_docs)]
#![allow(clippy::struct_excessive_bools)]
use crate::validators::{
CliCodeBlockStyle, CliHeadingStyle, CliHighlightStyle, CliLinkStyle, CliListIndentType, CliNewlineStyle,
CliOutputFormat, CliPreprocessingPreset, CliWhitespaceMode, validate_bullets, validate_strong_em_symbol,
};
use clap::{Parser, ValueEnum};
use std::path::PathBuf;
#[derive(Parser)]
#[command(name = "html-to-markdown")]
#[command(version)]
#[command(about, long_about = None)]
#[command(after_help = "EXAMPLES:
# Basic conversion from stdin
echo '<h1>Title</h1><p>Content</p>' | html-to-markdown
# Convert file to stdout
html-to-markdown input.html
# Convert and save to file
html-to-markdown input.html -o output.md
# Generate shell completions
html-to-markdown --generate-completion bash > html-to-markdown.bash
html-to-markdown --generate-completion zsh > _html-to-markdown
# Generate man page
html-to-markdown --generate-man > html-to-markdown.1
# Web scraping with preprocessing
html-to-markdown page.html --preprocess --preset aggressive
# Fetch remote HTML and convert
html-to-markdown --url https://example.com > output.md
# Discord/Slack-friendly (2-space indents)
html-to-markdown input.html --list-indent-width 2
# Custom heading and list styles
html-to-markdown input.html \\
--heading-style atx \\
--bullets '*' \\
--list-indent-width 2
For more information: https://github.com/kreuzberg-dev/html-to-markdown
")]
pub struct Cli {
#[arg(value_name = "FILE")]
pub input: Option<String>,
#[arg(long, value_name = "URL", conflicts_with = "input")]
pub url: Option<String>,
#[arg(long = "user-agent", value_name = "UA", requires = "url")]
pub user_agent: Option<String>,
#[arg(short = 'o', long = "output", value_name = "FILE")]
pub output: Option<PathBuf>,
#[arg(long = "generate-completion", value_name = "SHELL", value_enum)]
pub generate_completion: Option<Shell>,
#[arg(long = "generate-man")]
pub generate_man: bool,
#[arg(long, value_name = "STYLE")]
#[arg(help_heading = "Heading Options")]
pub heading_style: Option<CliHeadingStyle>,
#[arg(long, value_name = "TYPE")]
#[arg(help_heading = "List Options")]
pub list_indent_type: Option<CliListIndentType>,
#[arg(long, value_name = "N", value_parser = clap::value_parser!(u8).range(1..=8))]
#[arg(help_heading = "List Options")]
pub list_indent_width: Option<u8>,
#[arg(short = 'b', long, value_name = "CHARS")]
#[arg(help_heading = "List Options")]
#[arg(value_parser = validate_bullets)]
pub bullets: Option<String>,
#[arg(long, value_name = "CHAR")]
#[arg(help_heading = "Text Formatting")]
#[arg(value_parser = validate_strong_em_symbol)]
pub strong_em_symbol: Option<char>,
#[arg(long)]
#[arg(help_heading = "Text Formatting")]
pub escape_asterisks: bool,
#[arg(long)]
#[arg(help_heading = "Text Formatting")]
pub escape_underscores: bool,
#[arg(long)]
#[arg(help_heading = "Text Formatting")]
pub escape_misc: bool,
#[arg(long)]
#[arg(help_heading = "Text Formatting")]
pub escape_ascii: bool,
#[arg(long, value_name = "SYMBOL")]
#[arg(help_heading = "Text Formatting")]
pub sub_symbol: Option<String>,
#[arg(long, value_name = "SYMBOL")]
#[arg(help_heading = "Text Formatting")]
pub sup_symbol: Option<String>,
#[arg(long, value_name = "STYLE")]
#[arg(help_heading = "Text Formatting")]
pub newline_style: Option<CliNewlineStyle>,
#[arg(long, value_name = "STYLE")]
#[arg(help_heading = "Code Blocks")]
pub code_block_style: Option<CliCodeBlockStyle>,
#[arg(short = 'l', long, value_name = "LANG")]
#[arg(help_heading = "Code Blocks")]
pub code_language: Option<String>,
#[arg(long = "no-autolinks")]
#[arg(help_heading = "Links")]
pub no_autolinks: bool,
#[arg(long, value_name = "STYLE")]
#[arg(help_heading = "Links")]
pub link_style: Option<CliLinkStyle>,
#[arg(long)]
#[arg(help_heading = "Links")]
pub default_title: bool,
#[arg(long, value_name = "ELEMENTS", value_delimiter = ',')]
#[arg(help_heading = "Images")]
pub keep_inline_images_in: Option<Vec<String>>,
#[arg(long)]
#[arg(help_heading = "Tables")]
pub br_in_tables: bool,
#[arg(long)]
#[arg(help_heading = "Tables")]
pub compact_tables: bool,
#[arg(long, value_name = "STYLE")]
#[arg(help_heading = "Highlighting")]
pub highlight_style: Option<CliHighlightStyle>,
#[arg(long)]
#[arg(help_heading = "Metadata")]
pub extract_metadata: bool,
#[arg(long)]
#[arg(help_heading = "JSON Output")]
pub json: bool,
#[arg(long)]
#[arg(help_heading = "JSON Output")]
#[arg(requires = "json")]
pub include_structure: bool,
#[arg(long)]
#[arg(help_heading = "JSON Output")]
#[arg(requires = "json")]
pub extract_inline_images: bool,
#[arg(long)]
#[arg(help_heading = "JSON Output")]
pub show_warnings: bool,
#[arg(long)]
#[arg(help_heading = "JSON Output")]
#[arg(requires = "json")]
pub no_content: bool,
#[arg(long, value_name = "MODE")]
#[arg(help_heading = "Whitespace")]
pub whitespace_mode: Option<CliWhitespaceMode>,
#[arg(long)]
#[arg(help_heading = "Whitespace")]
pub strip_newlines: bool,
#[arg(short = 'w', long)]
#[arg(help_heading = "Wrapping")]
pub wrap: bool,
#[arg(long, value_name = "N", value_parser = clap::value_parser!(u16).range(20..=500))]
#[arg(help_heading = "Wrapping")]
pub wrap_width: Option<u16>,
#[arg(long)]
#[arg(help_heading = "Element Handling")]
pub convert_as_inline: bool,
#[arg(long, value_name = "TAGS", value_delimiter = ',')]
#[arg(help_heading = "Element Handling")]
pub strip_tags: Option<Vec<String>>,
#[arg(long, value_name = "TAGS", value_delimiter = ',')]
#[arg(help_heading = "Element Handling")]
pub preserve_tags: Option<Vec<String>>,
#[arg(long)]
#[arg(help_heading = "Element Handling")]
pub skip_images: bool,
#[arg(long, value_name = "N")]
#[arg(help_heading = "Element Handling")]
pub max_depth: Option<usize>,
#[arg(short = 'p', long)]
#[arg(help_heading = "Preprocessing")]
pub preprocess: bool,
#[arg(long, value_name = "LEVEL")]
#[arg(help_heading = "Preprocessing")]
#[arg(requires = "preprocess")]
pub preset: Option<CliPreprocessingPreset>,
#[arg(long)]
#[arg(help_heading = "Preprocessing")]
#[arg(requires = "preprocess")]
pub keep_navigation: bool,
#[arg(long)]
#[arg(help_heading = "Preprocessing")]
#[arg(requires = "preprocess")]
pub keep_forms: bool,
#[arg(short = 'e', long, value_name = "ENCODING", default_value = "utf-8")]
#[arg(help_heading = "Parsing")]
pub encoding: String,
#[arg(long)]
#[arg(help_heading = "Debugging")]
pub debug: bool,
#[arg(short = 'f', long = "output-format", value_name = "FORMAT")]
#[arg(help_heading = "Output Format")]
pub output_format: Option<CliOutputFormat>,
}
#[derive(Copy, Clone, PartialEq, Eq, ValueEnum)]
#[allow(clippy::enum_variant_names)]
pub enum Shell {
Bash,
Zsh,
Fish,
PowerShell,
Elvish,
}