Class: Charming::Components::Markdown

Inherits:
Charming::Component show all
Defined in:
lib/charming/presentation/components/markdown.rb

Overview

Markdown renders CommonMark/GFM source as ANSI-styled terminal text.

Instance Method Summary collapse

Methods inherited from View

#focused?, #layout_assigns

Constructor Details

#initialize(content:, width: nil, theme: nil, syntax_highlighting: true, style: :dark, base_url: nil) ⇒ Markdown

Returns a new instance of Markdown.



7
8
9
10
11
12
13
14
# File 'lib/charming/presentation/components/markdown.rb', line 7

def initialize(content:, width: nil, theme: nil, syntax_highlighting: true, style: :dark, base_url: nil)
  super(theme: theme)
  @content = content
  @width = width
  @syntax_highlighting = syntax_highlighting
  @style = style
  @base_url = base_url
end

Instance Method Details

#renderObject

Renders the Markdown body to a styled, terminal-safe string.



17
18
19
20
21
22
23
24
25
26
# File 'lib/charming/presentation/components/markdown.rb', line 17

def render
  Charming::Markdown::Renderer.new(
    content: @content,
    width: @width,
    theme: theme,
    syntax_highlighting: @syntax_highlighting,
    style: @style,
    base_url: @base_url
  ).render
end