module Riffer::Rig::Terminal::Markdown
Constants
- BULLET
- COLUMN_LIMIT
-
Every row is padded to the header, so without a ceiling one wide header costs a cell per column on every row. A rowβs pipes bound its cells.
- CONTROL
-
Tabs and newlines are the only control characters that survive: the source is model output, and anything else here could drive the terminal.
- FLUSH_ITEM
- NESTING_LIMIT
-
Quotes and lists render by recursion, so without a ceiling a single line of quote marks could exhaust the stack.
- RULE_WIDTH
- TAB
Public Instance Methods
(String source, theme: Riffer::Rig::Terminal::Theme, width: Integer?) → String
Source
# File lib/riffer/rig/terminal/markdown.rb, line 30 def render(source, theme:, width:) text = source.encode(Encoding::UTF_8, invalid: :replace, undef: :replace) source_lines = text.gsub(/\r\n?/, "\n").gsub(CONTROL, '').gsub("\t", TAB).lines(chomp: true) rows = lines(source_lines, theme: theme, width: narrow(width, 0), depth: 0) body = rows.join("\n").gsub(/\A\n+|\n+\z/, '') body.empty? ? body : "#{body}\n" end
@rbs source: String @rbs theme: Riffer::Rig::Terminal::Theme @rbs width: Integer? @rbs return: String