Class: RubyRich::Markdown::TerminalConverter
- Inherits:
-
Kramdown::Converter::Base
- Object
- Kramdown::Converter::Base
- RubyRich::Markdown::TerminalConverter
- Defined in:
- lib/ruby_rich/markdown.rb
Defined Under Namespace
Modules: LatexConverter, MermaidRenderer
Instance Method Summary collapse
-
#convert(el, _indent = 0) ⇒ Object
主分发方法 — 根据 AST 元素类型路由到对应处理方法.
-
#initialize(root, options) ⇒ TerminalConverter
constructor
A new instance of TerminalConverter.
- #tbg(key) ⇒ Object
-
#tc(key) ⇒ Object
Shortcut: AnsiCode.color with theme lookup.
- #tfont(key, **overrides) ⇒ Object
Constructor Details
#initialize(root, options) ⇒ TerminalConverter
Returns a new instance of TerminalConverter.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ruby_rich/markdown.rb', line 58 def initialize(root, ) super @width = [:width] || 80 @indent_str = [:indent] || ' ' @table_border_style = [:table_border_style] || :simple @theme = ([:theme] || MarkdownTheme).freeze # 用于有序列表编号 @list_counters = [] @list_types = [] end |
Instance Method Details
#convert(el, _indent = 0) ⇒ Object
主分发方法 — 根据 AST 元素类型路由到对应处理方法
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/ruby_rich/markdown.rb', line 86 def convert(el, _indent = 0) case el.type when :root then convert_children(el) when :blank then "\n" when :text then el.value when :p then convert_p(el) when :header then convert_header(el) when :codeblock then convert_codeblock(el) when :codespan then convert_codespan(el) when :blockquote then convert_blockquote(el) when :ul then convert_list(el) when :ol then convert_list(el) when :li then convert_li(el) when :em then convert_em(el) when :strong then convert_strong(el) when :em_strong then convert_em_strong(el) when :a then convert_link(el) when :img then convert_image(el) when :hr then convert_hr(el) when :br then "\n" when :table then convert_table(el) when :thead then convert_children(el) when :tbody then convert_children(el) when :tr then convert_table_row(el) when :th then convert_table_cell(el) when :td then convert_table_cell(el) when :html_element then convert_html_element(el) when :html_entity then convert_html_entity(el) when :smart_quote then convert_smart_quote(el) when :entity then el.value.to_s when :raw then convert_raw(el) when :comment then '' when :footnote then convert_footnote(el) when :dl then convert_definition_list(el) when :dt then convert_definition_term(el) when :dd then convert_definition_desc(el) when :abbreviation then convert_abbreviation(el) when :math then convert_math(el) else # 未知类型,递归处理子元素 if el.children && !el.children.empty? convert_children(el) else el.value || el.text || '' end end end |
#tbg(key) ⇒ Object
75 76 77 78 |
# File 'lib/ruby_rich/markdown.rb', line 75 def tbg(key) color, bright = @theme[key] AnsiCode.background(color, bright) end |