### Install and Use Markout CLI Source: https://github.com/amscotti/markout/blob/main/llms.txt Instructions for installing the Markout CLI tool using 'shards build --production' and examples of its usage for converting HTML from standard input or files to Markdown. It also shows how to customize heading styles and bullet characters. ```bash # Install shards build --production # or download from releases # Usage curl -s https://example.com | markout # stdin to stdout markout input.html -o output.md # file to file markout --heading-style=setext --bullet-char="*" file.html ``` -------------------------------- ### Markout CLI Examples (Bash) Source: https://github.com/amscotti/markout/blob/main/README.md Provides practical examples of using the Markout CLI, such as fetching a web page and converting it, or applying specific formatting options like Setext headings and asterisk bullets. ```bash # Fetch HN article and convert curl -sL https://amplifying.ai/research/claude-code-picks | markout # Use Setext headings and asterisk bullets markout --heading-style=setext --bullet-char="*" article.html ``` -------------------------------- ### Install Markout CLI Binary (Bash) Source: https://github.com/amscotti/markout/blob/main/README.md Instructions for installing the Markout command-line interface by downloading pre-built binaries from the releases page or building from source using 'shards build --production'. ```bash shards build --production # Binary will be at bin/markout ``` ```bash docker pull ghcr.io/amscotti/markout:latest ``` -------------------------------- ### Execute Markout via CLI Source: https://context7.com/amscotti/markout/llms.txt Examples of using the Markout command-line interface for file conversion, piping data, and chaining with other Unix tools. ```bash curl -s https://example.com | markout > article.md markout input.html markout input.html -o output.md cat page.html | markout | grep "^#" > headings.txt echo "
This is bold text.
" markdown = Markout.convert(html) # => "# Hello\n\nThis is **bold** text." ``` -------------------------------- ### Process Web Pages with Markout (Crystal) Source: https://github.com/amscotti/markout/blob/main/README.md An example of fetching HTML content from a URL using `HTTP::Client` and then converting it to Markdown with Markout. It highlights that navigation, scripts, and styles are automatically stripped. ```crystal require "markout" require "http/client" # Fetch and convert a web page response = HTTP::Client.get("https://example.com/article") markdown = Markout.convert(response.body) # Navigation, scripts, and styles are automatically stripped # Only the article content remains ``` -------------------------------- ### Implementing a Custom HTML Element Handler in Crystal Source: https://github.com/amscotti/markout/blob/main/llms.txt Provides an example of how to implement a custom handler for HTML elements within the Markout library. This involves defining a class that includes the `Handler` module, specifying the elements it handles, and implementing the `convert` method to generate Markdown output. ```crystal module Markout::Handlers class HeadingsHandler include Handler def handles : Array(Symbol) [:h1, :h2, :h3, :h4, :h5, :h6] end def convert(node : Lexbor::Node, ctx : Context, converter : Converter) : String level = heading_level(node) text = converter.process_children(node, ctx).strip "#" * level + " #{text}" end end Handlers.register(HeadingsHandler.new) end ``` -------------------------------- ### Docker Usage and Build Commands Source: https://github.com/amscotti/markout/blob/main/README.md Instructions for pulling, running, and building the Markout Docker image. It demonstrates how to convert local files or pipe web content through the container. ```bash # Pull from GitHub Container Registry docker pull ghcr.io/amscotti/markout:latest # Convert a file docker run --rm -v $(pwd):/data ghcr.io/amscotti/markout /data/input.html -o /data/output.md # Pipe through docker curl -s https://example.com | docker run --rm -i ghcr.io/amscotti/markout # Building the Image docker build -t markout . ``` -------------------------------- ### Configure Markout Options Source: https://context7.com/amscotti/markout/llms.txt Demonstrates how to configure global settings for the Markout library, such as emphasis handling, image rendering, and newline styles. ```crystal options.ignore_emphasis = false options.images_as_html = false options.strikethrough_char = "~~" options.newline_style = Markout::Options::NewlineStyle::Spaces ``` -------------------------------- ### Run Markout with Docker Source: https://context7.com/amscotti/markout/llms.txt Instructions for running Markout in a containerized environment, including file volume mounting and piping data through the container. ```bash docker pull ghcr.io/amscotti/markout:latest docker run --rm -v $(pwd):/data ghcr.io/amscotti/markout /data/input.html -o /data/output.md curl -s https://example.com | docker run --rm -i ghcr.io/amscotti/markout echo "Doc 1
", "Doc 2
", "Doc 3
"] results = docs.map { |html| converter.convert(html) } ``` -------------------------------- ### Basic and Configurable HTML to Markdown Conversion in Crystal Source: https://github.com/amscotti/markout/blob/main/llms.txt Demonstrates how to use the Markout library in Crystal for basic HTML to Markdown conversion. It shows how to perform a simple conversion and how to configure options like heading style for more advanced use cases. It also illustrates creating a reusable converter instance. ```crystal require "markout" # Basic conversion markdown = Markout.convert("Content
") # => "# Title\n\nContent" # With options options = Markout::Options.new options.heading_style = Markout::Options::HeadingStyle::Setext markdown = Markout.convert(html, options) # Reusable converter converter = Markout::Converter.new(options) result = converter.convert(html) ``` -------------------------------- ### Convert HTML to Markdown using Markout CLI (Bash) Source: https://github.com/amscotti/markout/blob/main/README.md Demonstrates common command-line usage patterns for the Markout CLI, including piping HTML from stdin, converting files to stdout, and redirecting output to a file. It also shows chaining with other Unix tools. ```bash # Convert from stdin (pipe) curl -s https://example.com | markout > article.md # Convert file to stdout markout input.html # Convert file to file markout input.html -o output.md # Chain with other tools cat page.html | markout | grep "^#" > headings.txt ``` -------------------------------- ### Reference-Style Links Conversion (Crystal) Source: https://github.com/amscotti/markout/blob/main/README.md Demonstrates how to configure Markout to generate reference-style Markdown links. This is useful for managing links in longer documents. ```crystal require "markout" html = <<-HTMLVisit Example and Test for more info.
HTML options = Markout::Options.new options.link_style = Markout::Options::LinkStyle::Referenced puts Markout.convert(html, options) # Output: # Visit [Example][1] and [Test][2] for more info. # # [1]: https://example.com # [2]: https://test.com ``` -------------------------------- ### Configuring Markout Options in Crystal Source: https://github.com/amscotti/markout/blob/main/llms.txt Illustrates how to configure various options for the Markout HTML to Markdown converter in Crystal. This includes setting heading styles, list bullet characters, emphasis characters, code fences, horizontal rule styles, and link handling preferences. ```crystal # Heading style property heading_style : HeadingStyle = HeadingStyle::ATX # or Setext # List formatting property bullet_char : Char = '-' # or '*' # Emphasis formatting property emphasis_char : Char = '*' # or '_' property strong_char : String = "**" # or "__" # Code formatting property code_fence : String = "```" # or "~~~" # Horizontal rules property hr_style : String = "---" # or "***" or "___" # Link handling property link_style : LinkStyle = LinkStyle::Inline # or Referenced property autolinks : Bool = true # UseHere is a link and some inline code.
This is a quoted block.
def hello
puts "world"
end
| Name | Value |
|---|---|
| Alpha | 1 |
| Beta | 2 |
Doc 1
", "Doc 2
", "Doc 3
"] results = docs.map { |html| converter.convert(html) } ``` -------------------------------- ### Customize Markdown Output Options in Crystal Source: https://context7.com/amscotti/markout/llms.txt Configure the output format by modifying the Markout::Options object. This allows users to change heading styles, bullet characters, and link formats to suit specific requirements. ```crystal require "markout" html = "