### 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 "

Test

" | markout - ``` -------------------------------- ### Install Markout as a Library (Crystal) Source: https://github.com/amscotti/markout/blob/main/README.md This snippet shows how to add the Markout dependency to your Crystal project's shard.yml file and install it using the 'shards install' command. ```yaml dependencies: markout: github: amscotti/markout ``` ```bash shards install ``` -------------------------------- ### Execute Build and Development Commands Source: https://github.com/amscotti/markout/blob/main/llms.txt Standard shell commands for managing the Crystal project lifecycle, including dependency installation, testing, linting, and documentation generation. ```bash shards install # Install dependencies crystal spec # Run tests crystal tool format # Format code bin/ameba # Run linter crystal docs # Generate documentation ``` -------------------------------- ### Convert HTML with Options (Crystal) Source: https://github.com/amscotti/markout/blob/main/README.md Shows how to customize the Markdown output using `Markout::Options`. This example sets Setext-style headings and asterisk bullets for the conversion. ```crystal require "markout" html = "

Title

" # Use Setext-style headings and asterisk bullets options = Markout::Options.new options.heading_style = Markout::Options::HeadingStyle::Setext options.bullet_char = '*' puts Markout.convert(html, options) # Output: # Title # ===== # # * Item ``` -------------------------------- ### Basic HTML to Markdown Conversion (Crystal) Source: https://github.com/amscotti/markout/blob/main/README.md A simple example of using the Markout library in Crystal to convert a basic HTML string into Markdown. It demonstrates the core `Markout.convert` method. ```crystal require "markout" html = "

Hello

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 "

Test

" | docker run --rm -i ghcr.io/amscotti/markout --bullet-char="*" ``` -------------------------------- ### Apply CLI Customization Options Source: https://context7.com/amscotti/markout/llms.txt Demonstrates how to use command-line flags to customize output formatting, such as heading styles, bullet characters, and link styles. ```bash markout --heading-style=setext --bullet-char="*" article.html markout --link-style=referenced document.html -o output.md markout --no-strip-document input.html markout --version markout --help ``` -------------------------------- ### Convert Web Content Programmatically Source: https://context7.com/amscotti/markout/llms.txt Shows how to use the Markout Crystal library to fetch a web page and convert its HTML content into clean Markdown. ```crystal require "markout" require "http/client" response = HTTP::Client.get("https://example.com/article") markdown = Markout.convert(response.body) File.write("article.md", markdown) ``` -------------------------------- ### Reference Available Conversion Options in Crystal Source: https://context7.com/amscotti/markout/llms.txt A comprehensive reference of all configuration properties available in the Markout::Options class, including defaults for styles, characters, and processing behaviors. ```crystal require "markout" options = Markout::Options.new options.heading_style = Markout::Options::HeadingStyle::ATX options.bullet_char = '-' options.emphasis_char = '*' options.strong_char = "**" options.code_fence = "```" options.hr_style = "---" options.link_style = Markout::Options::LinkStyle::Inline options.autolinks = true options.strip_document = true options.ignore_links = false options.ignore_images = false ``` -------------------------------- ### Create Reusable Converter Instance (Crystal) Source: https://github.com/amscotti/markout/blob/main/README.md Illustrates how to create a reusable `Markout::Converter` instance with specific options, allowing for efficient conversion of multiple HTML documents with consistent settings. ```crystal require "markout" # Create a converter instance for multiple documents options = Markout::Options.new options.code_fence = "~~~" converter = Markout::Converter.new(options) docs = ["

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("

Title

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 = <<-HTML

Visit 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 # Use when text matches href property ignore_links : Bool = false # Strip link formatting, keep text property default_link_title : Bool = false ``` -------------------------------- ### Convert Complex HTML Structures in Crystal Source: https://context7.com/amscotti/markout/llms.txt Demonstrates the conversion of rich HTML content including nested lists, tables, code blocks, and blockquotes. Markout handles these complex elements to produce valid, structured Markdown. ```crystal require "markout" html = <<-HTML

Documentation

Here is a link and some inline code.

Features

This is a quoted block.

def hello
  puts "world"
end
NameValue
Alpha1
Beta2
HTML puts Markout.convert(html) ``` -------------------------------- ### Implement Custom Handler in Crystal Source: https://github.com/amscotti/markout/blob/main/llms.txt Defines the structure for creating a new tag handler in Markout. It requires including the Handler module, implementing the handles and convert methods, and registering the instance. ```crystal module Markout::Handlers class MyHandler include Handler def handles : Array(Symbol) [:mytag] end def convert(node : Lexbor::Node, ctx : Context, converter : Converter) : String content = converter.process_children(node, ctx) converter.options.some_option ctx.some_state "formatted #{content}" end end Handlers.register(MyHandler.new) end ``` -------------------------------- ### Use Reusable Converter Instance in Crystal Source: https://context7.com/amscotti/markout/llms.txt Instantiate a persistent Converter object to process multiple documents efficiently with shared configuration settings. This approach is ideal for batch processing tasks. ```crystal require "markout" options = Markout::Options.new options.code_fence = "~~~" options.emphasis_char = '_' converter = Markout::Converter.new(options) docs = ["

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 = "

Title

" options = Markout::Options.new options.heading_style = Markout::Options::HeadingStyle::Setext options.bullet_char = '*' puts Markout.convert(html, options) ``` -------------------------------- ### Configure Reference-Style Links in Crystal Source: https://context7.com/amscotti/markout/llms.txt Set the link style to referenced mode to collect all URLs at the end of the document. This is useful for cleaner document readability in long-form content. ```crystal require "markout" html = <<-HTML

Visit Example and Test for more info.

HTML options = Markout::Options.new options.link_style = Markout::Options::LinkStyle::Referenced puts Markout.convert(html, options) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.