module TTY::Markdown
def build_symbols(symbols)
- Api: - private
Returns:
-
(Hash{Symbol => String})
-
Parameters:
-
symbols
(Hash, String, Symbol, nil
) --
def build_symbols(symbols) case symbols when String, Symbol select_symbols(symbols) when Hash base_symbols = select_symbols(symbols[:base]) base_symbols.merge(symbols[:override].to_h) else SYMBOLS end end
def build_theme(theme)
- Api: - private
Returns:
-
(Hash{Symbol => Array
-})
Parameters:
-
theme
(Hash{Symbol => Array, String, Symbol}, nil
) --
def build_theme(theme) THEME.merge(theme.to_h) do |*, new_style| Array(new_style).map(&:to_sym) end end
def color_enabled(color)
- Api: - private
Returns:
-
(Boolean, nil)
-
Parameters:
-
color
(String, Symbol
) --
def color_enabled(color) case color.to_s when "always" then true when "never" then false end end
def parse(source,
- Api: - public
Returns:
-
(String)
-
Parameters:
-
doc_opts
(Hash
) -- -
width
(Integer
) -- -
theme
(Hash{Symbol => Array, String, Symbol}, nil
) -- -
symbols
(Hash, String, Symbol, nil
) -- -
mode
(Integer
) -- -
indent
(Integer
) -- -
color
(String, Symbol
) -- -
source
(String
) --
def parse(source, color: :auto, indent: 2, mode: TTY::Color.mode, symbols: {}, theme: {}, width: TTY::Screen.width, **doc_opts) converter_options = { 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, converter_options.merge(doc_opts)) Converter.convert(doc.root, doc.options).join end
def parse_file(path, **options)
- Api: - public
Returns:
-
(String)
-
Parameters:
-
options
(Hash
) -- -
path
(String
) --
def parse_file(path, **options) parse(::File.read(path), **options) end
def select_symbols(name)
- Api: - private
Returns:
-
(Hash{Symbol => String})
-
Parameters:
-
name
(String, Symbol, nil
) --
def select_symbols(name) name.to_s == "ascii" ? ASCII_SYMBOLS : SYMBOLS end