//! The `comrak` binary. use std::env; use std::error::Error; use std::fs; use std::io::Read; use std::path::PathBuf; use std::process; use std::{boxed::Box, io::BufWriter}; use clap::{Parser, ValueEnum}; use comrak::options; use comrak::{Arena, Options}; #[cfg(feature = "syntect")] use comrak::{adapters::SyntaxHighlighterAdapter, plugins::syntect::SyntectAdapter}; const EXIT_SUCCESS: i32 = 0; const EXIT_PARSE_CONFIG: i32 = 2; const EXIT_READ_INPUT: i32 = 3; const EXIT_CHECK_FILE_NUM: i32 = 4; #[derive(Debug, Parser)] #[command(about, author, version)] #[command(after_help = "\ By default, Comrak will attempt to read command-line options from a config file specified by \ --config-file. This behaviour can be disabled by passing --config-file none. It is not an error \ if the file does not exist.\ ")] struct Cli { /// CommonMark file(s) to parse; or standard input if none passed #[arg(value_name = "FILE")] files: Option>, /// Path to config file containing command-line arguments, or 'none' #[arg(short, long, value_name = "PATH", default_value = get_default_config_path())] config_file: String, /// Reformat CommonMark files in-place #[arg(short, long, conflicts_with_all(["format", "output"]))] inplace: bool, /// Treat newlines as hard line breaks #[arg(long)] hardbreaks: bool, /// Replace punctuation like "this" with smart punctuation like โ€œthisโ€ #[arg(long)] smart: bool, /// Use GitHub-style "
" for code blocks
    #[arg(long)]
    github_pre_lang: bool,

    /// Include words following the code block info string in a data-meta attribute
    #[arg(long)]
    full_info_string: bool,

    /// Enable GitHub-flavored markdown extensions: strikethrough, tagfilter,
    /// table, autolink, and tasklist. Also enables --github-pre-lang and
    /// --gfm-quirks.
    #[arg(long)]
    gfm: bool,

    /// Use GFM-style quirks in output HTML, such as not nesting 
    /// tags, which otherwise breaks CommonMark compatibility.
    #[arg(long)]
    gfm_quirks: bool,

    /// Permit any character inside a tasklist item, not just " ", "x" or "X"
    #[arg(long)]
    relaxed_tasklist_character: bool,

    /// Relax autolink parsing: allows links to be recognised when in brackets,
    /// permits all URL schemes, and permits domains without a TLD (like "http://localhost")
    #[arg(long)]
    relaxed_autolinks: bool,

    /// Include "task-list-item" and "task-list-item-checkbox" classes on
    // tasklist "
  • " and "" elements respectively #[arg(long)] tasklist_classes: bool, /// Default value for fenced code block's info strings if none is given #[arg(long, value_name = "INFO")] default_info_string: Option, /// Allow inline and block HTML (unless --escape is given), and permit // dangerous URLs (like "javascript:" and non-image "data:" URLs) #[arg(long = "unsafe")] r#unsafe: bool, /// Translate gemoji like ":thumbsup:" into Unicode emoji like "๐Ÿ‘" #[arg(long)] #[cfg(feature = "shortcodes")] gemoji: bool, /// Escape raw HTML, instead of clobbering it; takes precedence over --unsafe #[arg(long)] escape: bool, /// Wrap escaped Markdown characters in "" in HTML #[arg(long)] escaped_char_spans: bool, /// Specify extensions to use /// /// Multiple extensions can be delimited with ",", e.g. '--extension /// strikethrough,table', or you can pass --extension/-e multiple times #[arg( short, long = "extension", value_name = "EXTENSION", value_delimiter = ',', value_enum )] extensions: Vec, /// Specify output format #[arg(short = 't', long = "to", value_enum, default_value_t = Format::Html)] format: Format, /// Write output to FILE instead of stdout #[arg(short, long, value_name = "FILE")] output: Option, /// Specify wrap width for output CommonMark, or '0' to disable wrapping #[arg(long, default_value_t = 0)] width: usize, /// Use the Comrak header IDs extension, with the given ID prefix #[arg(long, value_name = "PREFIX", required = false)] header_id_prefix: Option, /// Apply the header ID prefix to the href anchor as well #[arg(long)] header_id_prefix_in_href: bool, /// Detect frontmatter that starts and ends with the given string, and do /// not include it in the resulting document #[arg(long, value_name = "DELIMITER", allow_hyphen_values = true)] front_matter_delimiter: Option, /// Syntax highlighting for fenced code blocks; 'css' for CSS classes (default), /// a theme name for inline styles, or 'none' to disable #[arg(long, value_name = "THEME", default_value = "css")] #[cfg(feature = "syntect")] syntax_highlighting: String, /// Specify bullet character for lists ("-", "+", "*") in CommonMark output #[arg(long, value_enum, default_value_t = ListStyle::Dash)] list_style: ListStyle, /// Specify alert style (
    vs