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/node/inspect.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.23.0'
Class Method Summary collapse
- .extensions ⇒ Object
-
.render_doc(text, options = :DEFAULT, extensions = []) ⇒ Object
Public: Parses a Markdown string into a ‘document` node.
-
.render_html(text, options = :DEFAULT, extensions = []) ⇒ Object
Public: Parses a Markdown string into an HTML string.
Class Method Details
.extensions ⇒ Object
1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 |
# File 'ext/commonmarker/commonmarker.c', line 1223
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 = []) ⇒ 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 extensions - An of Symbols indicating the extensions to use
Returns the ‘document` node.
38 39 40 41 42 43 44 |
# File 'lib/commonmarker.rb', line 38 def self.render_doc(text, = :DEFAULT, extensions = []) raise TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String) opts = Config.(, :parse) text = text.encode('UTF-8') Node.parse_document(text, text.bytesize, opts, extensions) end |
.render_html(text, options = :DEFAULT, extensions = []) ⇒ 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 extensions - An of Symbols indicating the extensions to use
Returns a String of converted HTML.
22 23 24 25 26 27 28 29 |
# File 'lib/commonmarker.rb', line 22 def self.render_html(text, = :DEFAULT, extensions = []) raise TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String) opts = Config.(, :render) text = text.encode('UTF-8') html = Node.markdown_to_html(text, opts, extensions) html.force_encoding('UTF-8') end |