Module: Commonmarker

Defined in:
lib/commonmarker.rb,
lib/commonmarker/node.rb,
lib/commonmarker/utils.rb,
lib/commonmarker/config.rb,
lib/commonmarker/version.rb,
lib/commonmarker/node/ast.rb,
lib/commonmarker/renderer.rb,
lib/commonmarker/constants.rb,
lib/commonmarker/node/inspect.rb

Defined Under Namespace

Modules: Config, Constants, Utils Classes: Node, Renderer

Constant Summary collapse

VERSION =
"1.1.5"

Class Method Summary collapse

Class Method Details

.parse(text, options: Commonmarker::Config::OPTIONS) ⇒ Object

Public: Parses a CommonMark string into an HTML string.

text - A String of text options - A Hash of render, parse, and extension options to transform the text.

Returns the ‘parser` node.

Raises:

  • (TypeError)


19
20
21
22
23
24
25
26
27
# File 'lib/commonmarker.rb', line 19

def parse(text, options: Commonmarker::Config::OPTIONS)
  raise TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String)
  raise TypeError, "text must be UTF-8 encoded; got #{text.encoding}!" unless text.encoding.name == "UTF-8"
  raise TypeError, "options must be a Hash; got a #{options.class}!" unless options.is_a?(Hash)

  opts = Config.process_options(options)

  commonmark_parse(text, options: opts)
end

.to_html(text, options: Commonmarker::Config::OPTIONS, plugins: Commonmarker::Config::PLUGINS) ⇒ Object

Public: Parses a CommonMark string into an HTML string.

text - A String of text options - A Hash of render, parse, and extension options to transform the text. plugins - A Hash of additional plugins.

Returns a String of converted HTML.

Raises:

  • (TypeError)


36
37
38
39
40
41
42
43
44
45
# File 'lib/commonmarker.rb', line 36

def to_html(text, options: Commonmarker::Config::OPTIONS, plugins: Commonmarker::Config::PLUGINS)
  raise TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String)
  raise TypeError, "text must be UTF-8 encoded; got #{text.encoding}!" unless text.encoding.name == "UTF-8"
  raise TypeError, "options must be a Hash; got a #{options.class}!" unless options.is_a?(Hash)

  opts = Config.process_options(options)
  plugins = Config.process_plugins(plugins)

  commonmark_to_html(text, options: opts, plugins: plugins)
end