Module: CommonMarker

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

Defined Under Namespace

Classes: Config, HtmlRenderer, Node, Renderer

Constant Summary collapse

VERSION =
'0.3.0'

Class Method Summary collapse

Class Method Details

.render_doc(text, option = :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.


30
31
32
33
34
# File 'lib/commonmarker.rb', line 30

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

.render_html(text, option = :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 parse options

Returns a String of converted HTML.


19
20
21
22
# File 'lib/commonmarker.rb', line 19

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