Class: LLM::Shell::Markdown Private
- Inherits:
-
Redcarpet::Render::Base
- Object
- Redcarpet::Render::Base
- LLM::Shell::Markdown
- Defined in:
- lib/llm/shell/markdown.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Class Method Summary collapse
- .options ⇒ Object private
-
.render(text) ⇒ String
private
Renders markdown text to a terminal-friendly format.
- .wrap(p:, width: 80) ⇒ Object private
Instance Method Summary collapse
- #block_code(code, lang) ⇒ Object private
- #block_quote(quote) ⇒ Object private
- #codespan(code) ⇒ Object private
- #double_emphasis(text) ⇒ Object private
- #emphasis(text) ⇒ Object private
- #header(text, level) ⇒ Object private
- #linebreak ⇒ Object private
- #list(items, _type) ⇒ Object private
- #list_item(item, _type) ⇒ Object private
- #normal_text(text) ⇒ Object private
- #paragraph(p) ⇒ Object private
Class Method Details
.options ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
37 38 39 40 41 42 43 44 |
# File 'lib/llm/shell/markdown.rb', line 37 def self. { autolink: false, no_intra_emphasis: true, fenced_code_blocks: true, lax_spacing: true, strikethrough: true, superscript: true, tables: true, with_toc_data: true } end |
.render(text) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Renders markdown text to a terminal-friendly format.
14 15 16 17 |
# File 'lib/llm/shell/markdown.rb', line 14 def self.render(text) renderer = Redcarpet::Markdown.new(self, ) renderer.render(wrap(p: text)).strip end |
.wrap(p:, width: 80) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/llm/shell/markdown.rb', line 21 def self.wrap(p:, width: 80) in_code = false p.lines.map do |line| if line =~ /^(\s*)(```|~~~)/ in_code = !in_code line elsif in_code || line =~ /^\s{4}/ line else line.gsub(/(.{1,#{width}})(\s+|\Z)/, "\\1\n") end end.join.strip + "\n" end |
Instance Method Details
#block_code(code, lang) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
46 47 48 49 50 |
# File 'lib/llm/shell/markdown.rb', line 46 def block_code(code, lang) ["\n", Paint["#{lang}:", :blue, :bold], "\n", coderay(code, lang), "\n"].join end |
#block_quote(quote) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
63 |
# File 'lib/llm/shell/markdown.rb', line 63 def block_quote(quote) = Paint[quote, :italic] |
#codespan(code) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
62 |
# File 'lib/llm/shell/markdown.rb', line 62 def codespan(code) = Paint[code, :yellow, :underline] |
#double_emphasis(text) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
61 |
# File 'lib/llm/shell/markdown.rb', line 61 def double_emphasis(text) = Paint[text, :bold] |
#emphasis(text) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
60 |
# File 'lib/llm/shell/markdown.rb', line 60 def emphasis(text) = Paint[text, :italic] |
#header(text, level) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
52 53 54 55 |
# File 'lib/llm/shell/markdown.rb', line 52 def header(text, level) color = levels.fetch(level, :white) "\n" + Paint[("#" * level) + " " + text, color] + "\n" end |
#linebreak ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
65 |
# File 'lib/llm/shell/markdown.rb', line 65 def linebreak = "\n" |
#list(items, _type) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
58 |
# File 'lib/llm/shell/markdown.rb', line 58 def list(items, _type) = items |
#list_item(item, _type) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
59 |
# File 'lib/llm/shell/markdown.rb', line 59 def list_item(item, _type) = "\n• #{item.strip}\n" |
#normal_text(text) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
64 |
# File 'lib/llm/shell/markdown.rb', line 64 def normal_text(text) = text |
#paragraph(p) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
57 |
# File 'lib/llm/shell/markdown.rb', line 57 def paragraph(p) = "#{p.strip}\n\n" |