Class: LLM::Shell::Markdown Private

Inherits:
Redcarpet::Render::Base
  • Object
show all
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.

See Also:

  • https://github.com/vmg/redcarpet/blob/master/ext/redcarpet/markdown.h#L69-L110

API:

  • private

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.optionsObject

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.

API:

  • private



37
38
39
40
41
42
43
44
# File 'lib/llm/shell/markdown.rb', line 37

def self.options
  {
    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.

Returns:

  • String

API:

  • private



14
15
16
17
# File 'lib/llm/shell/markdown.rb', line 14

def self.render(text)
  renderer = Redcarpet::Markdown.new(self, options)
  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.

API:

  • private



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.

API:

  • private



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.

API:

  • private



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.

API:

  • private



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.

API:

  • private



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.

API:

  • private



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.

API:

  • private



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

#linebreakObject

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.

API:

  • private



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.

API:

  • private



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.

API:

  • private



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.

API:

  • private



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.

API:

  • private



57
# File 'lib/llm/shell/markdown.rb', line 57

def paragraph(p) = "#{p.strip}\n\n"