Module: TTY::Markdown
- Defined in:
- lib/tty/markdown.rb,
lib/tty/markdown/version.rb,
lib/tty/markdown/converter.rb,
lib/tty/markdown/syntax_highlighter.rb
Overview
Responsible for converting Markdown to the terminal output
Defined Under Namespace
Modules: SyntaxHighliter Classes: Converter
Constant Summary collapse
- SYMBOLS =
{ arrow: "»", bullet: "●", bar: "┃", diamond: "◈", pipe: "│", line: "─", hellip: "…", laquo: "«", laquo_space: "« ", raquo: "»", raquo_space: " »", ndash: "-", mdash: "\u2014", lsquo: "‘", rsquo: "’", ldquo: "“", rdquo: "”", top_left: "┌", top_right: "┐", top_center: "┬", mid_left: "├", mid_right: "┤", mid_center: "┼", bottom_right: "┘", bottom_left: "└", bottom_center: "┴", paren_left: "(", paren_right: ")", bracket_left: "[", bracket_right: "]", hash: "#", delete: "\u0336" }.freeze
- ASCII_SYMBOLS =
{ arrow: "->", bullet: "*", diamond: "*", bar: "│", pipe: "|", line: "-", hellip: "...", laquo: "<<", laquo_space: "<< ", raquo: ">>", raquo_space: " >>", ndash: "-", mdash: "--", lsquo: "\"", rsquo: "\"", ldquo: "\"", rdquo: "\"", top_left: "+", top_right: "+", top_center: "+", mid_left: "+", mid_right: "+", mid_center: "+", bottom_right: "+", bottom_left: "+", bottom_center: "+", paren_left: "(", paren_right: ")", bracket_left: "[", bracket_right: "]", hash: "#", delete: "\u0336" }.freeze
- THEME =
{ em: :yellow, header: %i[cyan bold], hr: :yellow, link: %i[yellow underline], list: :yellow, strong: %i[yellow bold], table: :yellow, quote: :yellow, image: :bright_black, note: :yellow, comment: :bright_black }.freeze
- VERSION =
"0.7.2"
Class Method Summary collapse
-
.parse(source, color: :auto, indent: 2, mode: TTY::Color.mode, symbols: {}, theme: {}, width: TTY::Screen.width, **doc_opts) ⇒ String
Parse a markdown string.
-
.parse_file(path, **options) ⇒ String
Parse a markdown document.
Class Method Details
.parse(source, color: :auto, indent: 2, mode: TTY::Color.mode, symbols: {}, theme: {}, width: TTY::Screen.width, **doc_opts) ⇒ String
Parse a markdown string
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/tty/markdown.rb', line 126 def parse(source, color: :auto, indent: 2, mode: TTY::Color.mode, symbols: {}, theme: {}, width: TTY::Screen.width, **doc_opts) = { enabled: color_enabled(color), indent: indent, input: "KramdownExt", mode: mode, symbols: build_symbols(symbols), theme: build_theme(theme), width: width } doc = Kramdown::Document.new(source, .merge(doc_opts)) Converter.convert(doc.root, doc.).join end |
.parse_file(path, **options) ⇒ String
Parse a markdown document
162 163 164 |
# File 'lib/tty/markdown.rb', line 162 def parse_file(path, **) parse(::File.read(path), **) end |