Module: TTY::Markdown

Defined in:
lib/tty/markdown.rb,
lib/tty/markdown/parser.rb,
lib/tty/markdown/version.rb,
lib/tty/markdown/syntax_highlighter.rb

Defined Under Namespace

Modules: SyntaxHighliter Classes: Parser

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: '',
}.freeze
WIN_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: '+'
}.freeze
THEME =
{
  em: :yellow,
  header: [:cyan, :bold],
  hr: :yellow,
  link: [:yellow, :underline],
  list: :yellow,
  strong: [:yellow, :bold],
  table: :yellow,
  quote: :yellow,
}.freeze
VERSION =
'0.6.0'

Class Method Summary collapse

Class Method Details

.parse(source, **options) ⇒ Object

Parse a markdown string

Parameters:

  • options (Hash)
  • source (String)

    the source with markdown

Options Hash (**options):

  • :colors (String)

    a number of colors supported

  • :width (String)


90
91
92
93
# File 'lib/tty/markdown.rb', line 90

def parse(source, **options)
  doc = Kramdown::Document.new(source, options)
  Parser.convert(doc.root, doc.options).join
end

.parse_file(path, **options) ⇒ Object

Pase a markdown document



99
100
101
# File 'lib/tty/markdown.rb', line 99

def parse_file(path, **options)
  parse(::File.read(path), options)
end

.symbolsObject



104
105
106
# File 'lib/tty/markdown.rb', line 104

def symbols
  @symbols ||= windows? ? WIN_SYMBOLS : SYMBOLS
end

.windows?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/tty/markdown.rb', line 109

def windows?
  ::File::ALT_SEPARATOR == "\\"
end