Class: LLM::Repl::Markdown
- Inherits:
-
Object
- Object
- LLM::Repl::Markdown
- Includes:
- Table
- Defined in:
- lib/llm/repl/markdown.rb,
lib/llm/repl/markdown/table.rb
Overview
This class is designed to represent a markdown string (typically from a model's response) as a tree of objects where each object contains a piece of text, and also optional style information for that text (eg bold, underscore, ...)
Defined Under Namespace
Modules: Table
Instance Method Summary collapse
Methods included from Table
Constructor Details
#initialize(text, width) ⇒ LLM::Repl::Markdown
18 19 20 21 22 |
# File 'lib/llm/repl/markdown.rb', line 18 def initialize(text, width) @doc = Kramdown::Document.new(text) @width = width @ast = [] end |
Instance Method Details
#ast ⇒ Array<Hash>
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/llm/repl/markdown.rb', line 26 def ast @ast.tap do ## # Recurisvely travels the markdown document and # populates the `@ast` variable along the way. # The AST is composed of structured data that # carries both text and styling information that # is applied by the UI thread. walk(@doc.root) ## # This is required because the AST collects # empty nodes towards the end of the tree. # If we don't pop them we end up with excessive # amount of newlines between turns. last = @ast.last while last and last[:text].to_s.strip.empty? @ast.pop last = @ast.last end end end |