Module: Crimson::Formatter
- Defined in:
- lib/crimson/formatter.rb
Overview
ANSI-markdown formatter for rendering Markdown-formatted text with terminal colors.
Class Method Summary collapse
-
.format_line(line) ⇒ String
Format a single line of Markdown text with ANSI styling.
-
.in_code_block? ⇒ Boolean
Whether currently inside a code block.
-
.reset ⇒ void
Reset the code block tracking state.
Class Method Details
.format_line(line) ⇒ String
Format a single line of Markdown text with ANSI styling.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/crimson/formatter.rb', line 21 def format_line(line) return "" if line.nil? if @in_code_block if line.start_with?("```") @in_code_block = false @pastel.dim("```") else line end elsif line.start_with?("```") @in_code_block = true lang = line.sub(/^```\s*/, "").strip lang.empty? ? @pastel.dim("```") : @pastel.dim("``` #{lang}") else style_inline(line) end end |
.in_code_block? ⇒ Boolean
Returns whether currently inside a code block.
41 42 43 |
# File 'lib/crimson/formatter.rb', line 41 def in_code_block? @in_code_block end |
.reset ⇒ void
This method returns an undefined value.
Reset the code block tracking state.
14 15 16 |
# File 'lib/crimson/formatter.rb', line 14 def reset @in_code_block = false end |