Class: RubyRich::Markdown
- Inherits:
-
Object
- Object
- RubyRich::Markdown
- Defined in:
- lib/ruby_rich/markdown.rb
Defined Under Namespace
Classes: TerminalConverter
Class Method Summary collapse
-
.render(markdown_text, options = {}) ⇒ String
渲染 Markdown 文本为 ANSI 终端输出.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Markdown
constructor
A new instance of Markdown.
- #render(markdown_text) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Markdown
Returns a new instance of Markdown.
404 405 406 |
# File 'lib/ruby_rich/markdown.rb', line 404 def initialize( = {}) @options = end |
Class Method Details
.render(markdown_text, options = {}) ⇒ String
渲染 Markdown 文本为 ANSI 终端输出
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
# File 'lib/ruby_rich/markdown.rb', line 384 def self.render(markdown_text, = {}) = { width: [:width] || 80, indent: [:indent] || ' ', table_border_style: [:table_border_style] || :simple } kramdown_opts = { input: 'GFM', # GitHub Flavored Markdown syntax_highlighter: nil, # 自行处理语法高亮 hard_wrap: false, html_to_native: true, line_width: [:width] }.merge([:kramdown] || {}) doc = Kramdown::Document.new(markdown_text, kramdown_opts) result, _warnings = TerminalConverter.convert(doc.root, ) result end |
Instance Method Details
#render(markdown_text) ⇒ Object
408 409 410 |
# File 'lib/ruby_rich/markdown.rb', line 408 def render(markdown_text) self.class.render(markdown_text, @options) end |