### Install TTY::Markdown Gem Source: https://github.com/piotrmurach/tty-markdown/blob/master/README.md Instructions for installing the TTY::Markdown gem using Bundler or directly via the `gem install` command. ```ruby gem "tty-markdown" ``` ```shell $ bundle ``` ```shell $ gem install tty-markdown ``` -------------------------------- ### Install and Use TTY-Markdown CLI Tool Source: https://context7.com/piotrmurach/tty-markdown/llms.txt This section provides instructions for installing and using the `tty-markdown-cli` gem, which allows you to render Markdown directly from your terminal. It covers installation, parsing local files, and piping Markdown content. ```bash # Install the CLI tool gem install tty-markdown-cli # Parse and display a Markdown file tty-markdown README.md # Pipe Markdown content echo "# Hello\n\nWorld" | tty-markdown ``` -------------------------------- ### Use tty-markdown from the command line (Bash) Source: https://github.com/piotrmurach/tty-markdown/blob/master/README.md Shows how to install and use the `tty-markdown-cli` tool to render a Markdown file directly from the terminal. This requires the `tty-markdown-cli` gem to be installed. ```bash $ tty-markdown README.md ``` -------------------------------- ### Render Markdown with TTY::Markdown (Ruby) Source: https://github.com/piotrmurach/tty-markdown/blob/master/README.md Demonstrates how to use the TTY::Markdown.parse method in Ruby to render Markdown strings. It shows examples of setting the color mode, customizing themes, controlling output width, and adjusting symbols. ```ruby TTY::Markdown.parse(markdown_string, mode: 16) ``` ```ruby TTY::Markdown.parse(markdown_string, theme: {link: :magenta, list: %i[magenta bold]}) ``` ```ruby TTY::Markdown.parse(markdown_string, width: 80) ``` ```ruby TTY::Markdown.parse(markdown_string, symbols: :ascii) ``` ```ruby TTY::Markdown.parse(markdown_string, symbols: {base: :ascii}) ``` ```ruby TTY::Markdown.parse(markdown_string, symbols: {override: {bullet: "x"}}) ``` ```ruby TTY::Markdown.parse(markdown_string, indent: 0) ``` ```ruby TTY::Markdown.parse(markdown_string, color: :always) ``` -------------------------------- ### Render Nested Lists with TTY::Markdown Source: https://github.com/piotrmurach/tty-markdown/blob/master/examples/demo.md Example of how TTY::Markdown handles nested list items. This is essential for displaying hierarchical data in a readable format in the terminal. ```markdown - Item 1 - Item 2 - Item 3 - Item 4 - Item 5 ``` -------------------------------- ### Render Markdown Code Block with Syntax Highlighting Source: https://github.com/piotrmurach/tty-markdown/blob/master/README.md Illustrates how TTY::Markdown renders Markdown code blocks, including syntax highlighting for specified languages like Ruby. The example shows a Ruby class definition within a Markdown code block. ```markdown ```ruby class Greeter def hello(name) puts "Hello #{name}" end end ``` ``` -------------------------------- ### Render Horizontal Rules with TTY-Markdown Source: https://context7.com/piotrmurach/tty-markdown/llms.txt This example shows how tty-markdown renders horizontal rules (`---` or `***`). The rules span the full terminal width and are decorated with diamond symbols at each end. The `width` option can be used to control the rule's length. ```ruby require "tty-markdown" markdown = <<~MD ## Section One Content for the first section. --- ## Section Two Content for the second section. *** ## Section Three Final section content. MD output = TTY::Markdown.parse(markdown, width: 60) puts output # Output shows: ◈────────────────────────────────────────────────────◈ ``` -------------------------------- ### TTY::Markdown Instance API for Reusable Parsing Source: https://context7.com/piotrmurach/tty-markdown/llms.txt Shows how to create a reusable TTY::Markdown parser instance with preset configurations. This is useful for parsing multiple Markdown documents with consistent settings, including both strings and files. ```ruby require "tty-markdown" # Create a configured instance parser = TTY::Markdown.new( width: 80, mode: 256, indent: 2, color: :always, theme: { link: :blue, header: %i[yellow bold] }, symbols: :unicode ) # Parse multiple strings with same configuration doc1 = parser.parse("# First Document\n\nContent here.") doc2 = parser.parse("# Second Document\n\nMore content.") puts doc1 puts doc2 # Parse files with the instance readme = parser.parse_file("README.md") changelog = parser.parse_file("CHANGELOG.md") puts readme puts changelog ``` -------------------------------- ### Render Links with TTY-Markdown Source: https://context7.com/piotrmurach/tty-markdown/llms.txt Shows how to render links, including standard links, links with titles, email links, and reference-style links. The output displays the link text followed by the URL, with URLs underlined and colored. ```ruby require "tty-markdown" markdown = <<~MD ## Links Examples Visit [TTY Toolkit](https://ttytoolkit.org) for more information. Check the [documentation](https://rubydoc.info/gems/tty-markdown "API Docs") here. Contact us at [support@example.com](mailto:support@example.com). Direct URL: [https://github.com](https://github.com) Reference-style [link][ref]. [ref]: https://example.com MD output = TTY::Markdown.parse(markdown) puts output ``` -------------------------------- ### Render Links with TTY::Markdown Source: https://github.com/piotrmurach/tty-markdown/blob/master/examples/demo.md Demonstrates rendering of inline-style markdown links, including those with titles, using TTY::Markdown. This allows for clickable links in terminal output. ```markdown An [inline-style link](https://ttytoolkit.org) An [inline-style link with title](https://ttytoolkit.org "TTY Toolkit Homepage") ``` -------------------------------- ### Render Definition Lists with TTY::Markdown Source: https://github.com/piotrmurach/tty-markdown/blob/master/examples/demo.md Shows the rendering of definition lists in TTY::Markdown. This is useful for creating glossaries or explanations within terminal output. ```markdown **Item 1** : This is the description for Item 1 **Item 2** : This is the description for Item 2 : This is another description for Item 2 ``` -------------------------------- ### Parse Markdown String with TTY::Markdown Source: https://context7.com/piotrmurach/tty-markdown/llms.txt Demonstrates parsing Markdown strings into terminal-formatted output using TTY::Markdown.parse. Covers basic usage, custom width, color modes, themes, symbols, and indentation. ```ruby require "tty-markdown" # Basic usage - parse a simple Markdown string markdown = "# Hello World\n\nThis is **bold** and *italic* text." output = TTY::Markdown.parse(markdown) puts output # Output: Colored header "Hello World" followed by styled text # Parse with custom width markdown = <<~MD # Project Documentation This is a paragraph that will be wrapped to fit within the specified width. - First item in the list - Second item with more content - Third item MD output = TTY::Markdown.parse(markdown, width: 60) puts output # Parse with 16-color mode for limited terminal support output = TTY::Markdown.parse("# Heading\n\n```ruby\nputs 'hello'\n```", mode: 16) puts output # Parse with custom theme colors output = TTY::Markdown.parse( "# Custom Styled\n\n[Link text](https://example.com)", theme: { link: :magenta, header: %i[green bold] } ) puts output # Parse with ASCII symbols instead of Unicode output = TTY::Markdown.parse( "- Item 1\n- Item 2\n- Item 3", symbols: :ascii ) puts output # Uses "*" instead of "●" for bullets # Force color output regardless of terminal detection output = TTY::Markdown.parse("# Always Colored", color: :always) # Disable color output entirely output = TTY::Markdown.parse("# No Color", color: :never) # Custom indentation (default is 2 spaces) output = TTY::Markdown.parse("# Header\n\n## Subheader", indent: 4) puts output ``` -------------------------------- ### Render Table with TTY::Markdown Source: https://github.com/piotrmurach/tty-markdown/blob/master/examples/demo.md Illustrates the rendering of a markdown table into a terminal-friendly format using TTY::Markdown. This is useful for presenting tabular data in a command-line interface. ```markdown | Tables | Are | Cool | |----------|:-------------:|------:| | col 1 is | left-aligned | $1600 | | col 2 is | centered | $12 | | col 3 is | right-aligned | $1 | ``` -------------------------------- ### Render Lists (Ordered, Unordered, Definition) with TTY-Markdown Source: https://context7.com/piotrmurach/tty-markdown/llms.txt Demonstrates how to render ordered, unordered, and definition lists using the TTY-Markdown gem. Supports nested lists and custom Unicode bullet points. The output is styled according to the list theme color. ```ruby require "tty-markdown" # Unordered list with nesting unordered = <<~MD ## Features - Easy to use API - Syntax highlighting - Ruby - Python - JavaScript - Custom themes - Unicode support - Fancy bullets - Box drawing characters MD puts TTY::Markdown.parse(unordered) # Ordered list ordered = <<~MD ## Installation Steps 1. Add gem to Gemfile 2. Run bundle install 3. Require the library 1. In your main file 2. Or in an initializer 4. Start using MD puts TTY::Markdown.parse(ordered) # Definition list definition = <<~MD ## Glossary TTY : Teletypewriter, a terminal device ANSI : American National Standards Institute : Used for terminal color codes Markdown : Lightweight markup language MD puts TTY::Markdown.parse(definition) ``` -------------------------------- ### Render Code Blocks with Syntax Highlighting using TTY-Markdown Source: https://context7.com/piotrmurach/tty-markdown/llms.txt Shows how to render code blocks with syntax highlighting using TTY-Markdown and Rouge. Supports automatic language detection and different color modes (16-color, 256-color, true color). Inline code is also supported. ```ruby require "tty-markdown" markdown = <<~MD ## Ruby Example ```ruby class Greeter def initialize(name) @name = name end def greet puts "Hello #{@name}!" end end greeter = Greeter.new("World") greeter.greet ``` ## JavaScript Example ```javascript function fibonacci(n) { if (n <= 1) return n; return fibonacci(n - 1) + fibonacci(n - 2); } console.log(fibonacci(10)); ``` ## Inline Code Use `require "tty-markdown"` to load the library. MD # Default 256-color highlighting puts TTY::Markdown.parse(markdown) # 16-color mode for basic terminals puts TTY::Markdown.parse(markdown, mode: 16) # True color (24-bit) if supported puts TTY::Markdown.parse(markdown, mode: 16777216) ``` -------------------------------- ### Parse Markdown File with TTY::Markdown Source: https://context7.com/piotrmurach/tty-markdown/llms.txt Demonstrates parsing Markdown files directly from the filesystem into terminal-formatted output using TTY::Markdown.parse_file. Supports the same customization options as the `parse` method. ```ruby require "tty-markdown" # Parse a README file with default settings output = TTY::Markdown.parse_file("README.md") puts output # Parse with custom width and color mode output = TTY::Markdown.parse_file( "documentation.md", width: 80, mode: 256 ) puts output # Parse with full customization output = TTY::Markdown.parse_file( "CHANGELOG.md", width: 100, mode: 256, indent: 2, color: :always, theme: { header: %i[cyan bold underline] }, symbols: :unicode ) puts output ``` -------------------------------- ### Render Images and Math with TTY-Markdown Source: https://context7.com/piotrmurach/tty-markdown/llms.txt This snippet illustrates how tty-markdown handles images and math formulas. Images are displayed with their alt text and source path, while math formulas (using `$$` or inline `$`) are rendered as highlighted code blocks. ```ruby require "tty-markdown" markdown = <<~MD ## Media Examples ![TTY Logo](https://example.com/logo.png) ![](https://example.com/no-alt.jpg) ## Math Formula Inline math: $$E = mc^2$$ Block math: $$ \sum_{i=1}^{n} i = \frac{n(n+1)}{2} $$ MD output = TTY::Markdown.parse(markdown) puts output # Images show: (TTY Logo - https://example.com/logo.png) # Math shows as highlighted code ``` -------------------------------- ### Render Ruby Codeblock with TTY::Markdown Source: https://github.com/piotrmurach/tty-markdown/blob/master/examples/demo.md Demonstrates how to render a Ruby code block using TTY::Markdown. This functionality is useful for displaying code snippets within a terminal application. ```ruby class Greeter def hello(name) puts "Hello #{name}" end end ``` -------------------------------- ### Render Tables with TTY-Markdown Source: https://context7.com/piotrmurach/tty-markdown/llms.txt Illustrates rendering tables with Unicode box-drawing characters and column alignment. Supports headers, footers, and custom width. An ASCII mode is available for compatibility. ```ruby require "tty-markdown" markdown = <<~MD ## Price List | Product | Price | Quantity | |--------------|:-----------:|---------:| | Widget | $9.99 | 100 | | Gadget | $24.99 | 50 | | Doohickey | $4.99 | 200 | ## Table with Footer | Metric | January | February | March | |---------------|:-------:|:--------:|:------:| | Users | 1,000 | 1,500 | 2,100 | | Revenue | $10,000 | $15,000 | $21,000| |===============|=========|==========|========| | **Total Q1** | 4,600 | - | $46,000| MD # Render with custom width output = TTY::Markdown.parse(markdown, width: 60) puts output # ASCII mode for compatibility output = TTY::Markdown.parse(markdown, symbols: :ascii) puts output ``` -------------------------------- ### Render Blockquotes with TTY-Markdown Source: https://context7.com/piotrmurach/tty-markdown/llms.txt Demonstrates rendering blockquotes with a vertical bar prefix and support for inline styling like bold and italic text. Nested content within blockquotes is also handled. ```ruby require "tty-markdown" markdown = <<~MD ## Famous Quote > Human madness is oftentimes a cunning and most feline thing. > When you think it fled, it may have but become transfigured > into some still subtler form. ## Quote with Styling > **Important:** This is a *critical* notice that you should > read carefully before proceeding. ## Nested Content in Quotes > The quick brown fox jumps over the lazy dog. > > This is a second paragraph within the same blockquote. MD output = TTY::Markdown.parse(markdown, width: 70) puts output ``` -------------------------------- ### Render Markdown Headers with TTY::Markdown Source: https://context7.com/piotrmurach/tty-markdown/llms.txt Illustrates how TTY::Markdown renders Markdown headers with hierarchical indentation and distinct styling based on their level. H1 headers are underlined, and subsequent headers are indented progressively. ```ruby require "tty-markdown" markdown = <<~MD # Main Title Introduction paragraph here. ## Section Header Section content goes here. ### Subsection More detailed content. #### Deep Nested Even more specific content. ##### Fifth Level Rarely used but supported. ###### Sixth Level The deepest level. MD output = TTY::Markdown.parse(markdown) puts output # Output shows headers with increasing indentation: # - H1: cyan, bold, underlined, no indent # - H2: cyan, bold, 2-space indent # - H3: cyan, bold, 4-space indent # ... and so on ``` -------------------------------- ### Render Math with TTY::Markdown Source: https://github.com/piotrmurach/tty-markdown/blob/master/examples/demo.md Shows how TTY::Markdown can render mathematical expressions. This feature is valuable for applications that need to display formulas or equations in the terminal. ```markdown $$5+5$$ ``` -------------------------------- ### Parse Markdown File to Terminal Output Source: https://github.com/piotrmurach/tty-markdown/blob/master/README.md Shows how to use the `TTY::Markdown.parse_file` method to read a Markdown file and convert its content into a terminal-formatted string. ```ruby parsed = TTY::Markdown.parse_file('example.md') puts parsed ``` -------------------------------- ### Parse Markdown String to Terminal Output Source: https://github.com/piotrmurach/tty-markdown/blob/master/README.md Demonstrates how to use the `TTY::Markdown.parse` method to convert a Markdown string into a terminal-formatted string. The output includes ANSI escape codes for styling. ```ruby parsed = TTY::Markdown.parse("# Hello") puts parsed # => "\e[36;1mHello\e[0m\n" ``` -------------------------------- ### Render Blockquotes with TTY::Markdown Source: https://github.com/piotrmurach/tty-markdown/blob/master/examples/demo.md Illustrates how TTY::Markdown renders blockquotes. This feature is useful for quoting text or highlighting specific passages in terminal output. ```markdown > Blockquotes are very handy in email to emulate reply text. > This line is part of the same quote. > *Oh*, you can put **Markdown** into a blockquote. ``` -------------------------------- ### Render Markdown Table for Terminal Source: https://github.com/piotrmurach/tty-markdown/blob/master/README.md Demonstrates the rendering of a Markdown table with specified alignment for columns (left, center, right) into a formatted terminal output. ```markdown | Tables | Are | Cool | |----------|:-------------:|------:| | col 1 is | left-aligned | $1600 | | col 2 is | centered | $12 | | col 3 is | right-aligned | $1 | ``` -------------------------------- ### Customize TTY-Markdown Theme for Elements Source: https://context7.com/piotrmurach/tty-markdown/llms.txt This section explains how to customize the appearance of Markdown elements rendered by tty-markdown. You can apply single colors or multiple styles (like bold, italic, underline) to elements such as headers, links, and quotes using Pastel gem syntax. ```ruby require "tty-markdown" # Available theme elements: # :code, :comment, :delete, :em, :header, :heading1, # :hr, :image, :link, :list, :note, :quote, :strong, :table markdown = <<~MD # Custom Theme Demo This has **bold** and *italic* text. > A blockquote with custom styling. - List item one - List item two [A link](https://example.com) MD # Single style per element output = TTY::Markdown.parse(markdown, theme: { header: :green, strong: :red, em: :blue, quote: :magenta, link: :cyan }) puts output # Multiple styles per element (array format) output = TTY::Markdown.parse(markdown, theme: { header: %i[bright_green bold], heading1: %i[bright_white bold underline], strong: %i[red bold], em: %i[blue italic], quote: %i[magenta], link: %i[cyan underline], list: %i[yellow], table: %i[white], code: %i[bright_yellow on_black], comment: %i[bright_black italic] }) puts output # Available colors: # black, red, green, yellow, blue, magenta, cyan, white # bright_black, bright_red, bright_green, bright_yellow, # bright_blue, bright_magenta, bright_cyan, bright_white # # Available attributes: # bold, dim, italic, underline, blink, reverse, hidden, strikethrough ``` -------------------------------- ### Markdown Footnote Syntax Source: https://github.com/piotrmurach/tty-markdown/blob/master/README.md Illustrates the Markdown syntax for creating footnote references and defining the footnote content. This is a standard Markdown feature. ```markdown It is not down on any map[^foo]; true places[^bar] never are. [^foo]: A diagrammatic representation of an area of land or sea. [^bar]: A particular position, point, or area in space; a location. ``` -------------------------------- ### Render Markdown Footnotes with TTY-Markdown Source: https://context7.com/piotrmurach/tty-markdown/llms.txt This snippet demonstrates how to render Markdown content with footnotes using the tty-markdown gem. It shows how footnotes are collected and displayed as a numbered list at the bottom, with references in the text appearing as bracketed numbers. It also handles multiline footnotes. ```ruby require "tty-markdown" markdown = <<~MD ## Research Paper The quick brown fox[^1] jumps over the lazy dog[^2]. According to recent studies[^research], this behavior is common. [^1]: The fox (Vulpes vulpes) is known for agility. [^2]: Dogs are domesticated mammals. [^research]: Smith et al., 2023. "Animal Behavior Studies" ## Multiline Footnotes Complex topics require detailed explanations[^complex]. [^complex]: This footnote has multiple paragraphs. The second paragraph provides additional context. And a third paragraph with `code examples`. MD output = TTY::Markdown.parse(markdown) puts output # Text shows [1], [2], [3] markers # Footnotes listed at bottom as ordered list ``` -------------------------------- ### Render Horizontal Rule with TTY::Markdown Source: https://github.com/piotrmurach/tty-markdown/blob/master/examples/demo.md Demonstrates the rendering of a horizontal line using TTY::Markdown. This is used for visual separation of content in terminal interfaces. ```markdown *** ``` -------------------------------- ### Enable Auto Color with TTY::Markdown Source: https://context7.com/piotrmurach/tty-markdown/llms.txt Enables automatic colorization for TTY::Markdown output based on terminal capabilities. The `:auto` option respects whether the terminal supports colors, preventing color codes from being output on incompatible terminals. This ensures a consistent viewing experience across different environments. ```ruby require 'tty/markdown' markdown = "This text will be **colored** if the terminal supports it." puts TTY::Markdown.parse(markdown, color: :auto) ``` -------------------------------- ### Parse Markdown File with TTY::Markdown Source: https://context7.com/piotrmurach/tty-markdown/llms.txt Parses the content of a Markdown file into formatted terminal output. This is convenient for displaying documentation files like READMEs or changelogs directly in the terminal. Ensure the file path is correct for successful parsing. ```ruby require 'tty/markdown' file_path = 'README.md' puts TTY::Markdown.parse_file(file_path) ``` -------------------------------- ### Configure Terminal Width for TTY::Markdown Source: https://context7.com/piotrmurach/tty-markdown/llms.txt Sets the display width for TTY::Markdown rendering, typically based on the terminal's current width. This ensures that Markdown content is formatted responsively and fits within the available screen space. It uses `TTY::Screen.width` to dynamically determine the width. ```ruby require 'tty/markdown' require 'tty/screen' markdown = "A long line of text that needs to wrap within the terminal width." width = TTY::Screen.width puts TTY::Markdown.parse(markdown, width: width) ``` -------------------------------- ### Parse Markdown String with TTY::Markdown Source: https://context7.com/piotrmurach/tty-markdown/llms.txt Parses a Markdown string into formatted terminal output. This method is useful for rendering dynamic Markdown content directly within your CLI application. It leverages TTY::Markdown's rendering engine to produce colored and styled output. ```ruby require 'tty/markdown' markdown = "# Hello World\n\nThis is **bold** text." puts TTY::Markdown.parse(markdown) ``` -------------------------------- ### Customize TTY-Markdown Symbols for Rendering Source: https://context7.com/piotrmurach/tty-markdown/llms.txt This snippet shows how to customize the symbols used by tty-markdown for rendering lists, quotes, and tables. You can switch between Unicode and ASCII symbol sets or override individual symbols for a personalized look. ```ruby require "tty-markdown" markdown = <<~MD ## Symbol Demo - Bullet point - Another bullet > A quote with bar --- | Col 1 | Col 2 | |-------|-------| | A | B | MD # Use ASCII symbols (compatible with all terminals) output = TTY::Markdown.parse(markdown, symbols: :ascii) puts output # Use Unicode symbols (default, nicer appearance) output = TTY::Markdown.parse(markdown, symbols: :unicode) puts output # Explicit base with hash syntax output = TTY::Markdown.parse(markdown, symbols: { base: :ascii }) puts output # Override specific symbols output = TTY::Markdown.parse(markdown, symbols: { base: :unicode, override: { bullet: "→", bar: "║", diamond: "◆", arrow: "⟹" } }) puts output # Available symbol names to override: # :arrow, :bar, :bullet, :diamond, :hash, :line, :pipe # :top_left, :top_center, :top_right # :mid_left, :mid_center, :mid_right # :bottom_left, :bottom_center, :bottom_right # :bracket_left, :bracket_right, :paren_left, :paren_right # :hellip, :laquo, :raquo, :ldquo, :rdquo, :lsquo, :rsquo # :mdash, :ndash, :laquo_space, :raquo_space ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.