Module: CommonMarker

Defined in:
lib/commonmarker.rb,
lib/commonmarker/node.rb,
lib/commonmarker/config.rb,
lib/commonmarker/version.rb,
lib/commonmarker/renderer.rb,
lib/commonmarker/renderer/html_renderer.rb,
ext/commonmarker/commonmarker.c

Defined Under Namespace

Modules: Config Classes: HtmlRenderer, Node, NodeError, Renderer

Constant Summary collapse

VERSION =
'0.9.2'.freeze

Class Method Summary collapse

Class Method Details

.render_doc(text, options = :default) ⇒ Object

Public: Parses a Markdown string into a ‘document` node.

string - String to be parsed option - A Symbol or of Symbols indicating the parse options

Returns the ‘document` node.



34
35
36
37
38
39
# File 'lib/commonmarker.rb', line 34

def self.render_doc(text, options = :default)
  fail TypeError, 'text must be a string!' unless text.is_a?(String)
  opts = Config.process_options(options, :parse)
  text = text.encode('UTF-8')
  Node.parse_document(text, text.bytesize, opts)
end

.render_html(text, options = :default) ⇒ Object

Public: Parses a Markdown string into an HTML string.

text - A String of text option - Either a Symbol or of Symbols indicating the render options

Returns a String of converted HTML.



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

def self.render_html(text, options = :default)
  fail TypeError, 'text must be a string!' unless text.is_a?(String)
  opts = Config.process_options(options, :render)
  text = text.encode('UTF-8')
  html = Node.markdown_to_html(text, opts)
  html.force_encoding('UTF-8')
end