module CommonMarker

Constants

VERSION

Public Class Methods

extensions() click to toggle source
VALUE rb_extensions(VALUE self) {
  cmark_llist *exts, *it;
  cmark_syntax_extension *ext;
  VALUE ary = rb_ary_new();

  cmark_mem *mem = cmark_get_default_mem_allocator();
  exts = cmark_list_syntax_extensions(mem);
  for (it = exts; it; it = it->next) {
    ext = it->data;
    rb_ary_push(ary, rb_str_new2(ext->name));
  }
  cmark_llist_free(mem, exts);

  return ary;
}
render_doc(text, options = :DEFAULT, extensions = []) click to toggle source

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

string - {String} to be parsed option - A {Symbol} or {Array of Symbol}s indicating the parse options extensions - An {Array of Symbol}s indicating the extensions to use

Returns the `document` node.

# File lib/commonmarker.rb, line 36
def self.render_doc(text, options = :DEFAULT, extensions = [])
  fail TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String)
  opts = Config.process_options(options, :parse)
  text = text.encode('UTF-8')
  Node.parse_document(text, text.bytesize, opts, extensions)
end
render_html(text, options = :DEFAULT, extensions = []) click to toggle source

Public: Parses a Markdown string into an HTML string.

text - A {String} of text option - Either a {Symbol} or {Array of Symbol}s indicating the render options extensions - An {Array of Symbol}s indicating the extensions to use

Returns a {String} of converted HTML.

# File lib/commonmarker.rb, line 21
def self.render_html(text, options = :DEFAULT, extensions = [])
  fail TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String)
  opts = Config.process_options(options, :render)
  text = text.encode('UTF-8')
  html = Node.markdown_to_html(text, opts, extensions)
  html.force_encoding('UTF-8')
end