Class: TTY::Markdown
- Inherits:
-
Object
- Object
- TTY::Markdown
- Defined in:
- lib/tty/markdown.rb,
lib/tty/markdown/color.rb,
lib/tty/markdown/error.rb,
lib/tty/markdown/theme.rb,
lib/tty/markdown/parser.rb,
lib/tty/markdown/symbols.rb,
lib/tty/markdown/version.rb,
lib/tty/markdown/converter.rb,
lib/tty/markdown/decorator.rb,
lib/tty/markdown/formatter.rb,
lib/tty/markdown/highlighter.rb
Overview
Responsible for converting Markdown to the terminal output
Defined Under Namespace
Classes: Color, Converter, Decorator, Error, Formatter, Highlighter, Parser, Symbols, Theme
Constant Summary collapse
- VERSION =
"0.7.2"
Class Method Summary collapse
-
.parse(content, **options) ⇒ String
Parse Markdown content.
-
.parse_file(path, **options) ⇒ String
Parse a Markdown file.
Instance Method Summary collapse
-
#initialize(color: :auto, indent: 2, mode: TTY::Color.mode, symbols: {}, theme: {}, width: TTY::Screen.width, **document_options) ⇒ Markdown
constructor
Create a Markdown instance.
-
#parse(content) ⇒ String
Parse Markdown content.
-
#parse_file(path) ⇒ String
Parse a Markdown file.
Constructor Details
#initialize(color: :auto, indent: 2, mode: TTY::Color.mode, symbols: {}, theme: {}, width: TTY::Screen.width, **document_options) ⇒ Markdown
Create a TTY::Markdown instance
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/tty/markdown.rb', line 112 def initialize( color: :auto, indent: 2, mode: TTY::Color.mode, symbols: {}, theme: {}, width: TTY::Screen.width, ** ) @converter_options = { enabled: Color.new(color).to_enabled, indent: indent, input: INPUT_PARSER, mode: mode, symbols: Symbols.from(symbols), theme: Theme.from(theme), width: width }.merge() end |
Class Method Details
.parse(content, **options) ⇒ String
Parse Markdown content
49 50 51 |
# File 'lib/tty/markdown.rb', line 49 def self.parse(content, **) new(**).parse(content) end |
.parse_file(path, **options) ⇒ String
Parse a Markdown file
75 76 77 |
# File 'lib/tty/markdown.rb', line 75 def self.parse_file(path, **) new(**).parse_file(path) end |
Instance Method Details
#parse(content) ⇒ String
Parse Markdown content
144 145 146 147 |
# File 'lib/tty/markdown.rb', line 144 def parse(content) document = Kramdown::Document.new(content, @converter_options) Converter.convert(document.root, document.).join end |
#parse_file(path) ⇒ String
Parse a Markdown file
161 162 163 |
# File 'lib/tty/markdown.rb', line 161 def parse_file(path) parse(::File.read(path)) end |