Module: Markly
- Defined in:
- lib/markly.rb,
lib/markly/node.rb,
lib/markly/flags.rb,
lib/markly/version.rb,
lib/markly/node/inspect.rb,
lib/markly/renderer/html.rb,
lib/markly/renderer/generic.rb,
lib/markly/renderer/headings.rb,
ext/markly/markly.c
Overview
Released under the MIT License. Copyright, 2025-2026, by Samuel Williams.
Defined Under Namespace
Modules: Renderer Classes: Error, Node, Parser
Constant Summary collapse
- DEFAULT =
The default parsing system.
0- VALIDATE_UTF8 =
Replace illegal sequences with the replacement character
U+FFFD. 1 << 9
- SMART =
Use smart punctuation (curly quotes, etc.).
1 << 10
- LIBERAL_HTML_TAG =
Support liberal parsing of inline HTML tags.
1 << 12
- FOOTNOTES =
Parse footnotes.
1 << 13
- STRIKETHROUGH_DOUBLE_TILDE =
Support strikethrough using double tildes.
1 << 14
- UNSAFE =
Allow raw/custom HTML and unsafe links.
1 << 17
- FRONT_MATTER =
Parse front matter ("---" delimited block at start of document). The raw content is available via node.string_content and the optional format hint (e.g. "yaml", "toml") via node.code_info; interpretation is left to the caller.
1 << 18
- INLINE_CODE_INFO =
Parse language prefixes on inline code spans, e.g. ruby:
Object.new. 1 << 19
- PARSE_FLAGS =
{ front_matter: FRONT_MATTER, inline_code_info: INLINE_CODE_INFO, validate_utf8: VALIDATE_UTF8, smart_quotes: SMART, liberal_html_tags: LIBERAL_HTML_TAG, footnotes: FOOTNOTES, strikethrough_double_tilde: STRIKETHROUGH_DOUBLE_TILDE, unsafe: UNSAFE, }
- SOURCE_POSITION =
Include source position in rendered HTML.
1 << 1
- HARD_BREAKS =
Treat
\nas hardbreaks (by adding<br/>). 1 << 2
- NO_BREAKS =
Translate
\nin the source to a single whitespace. 1 << 4
- GITHUB_PRE_LANG =
Use GitHub-style
<pre lang>for fenced code blocks. 1 << 11
- TABLE_PREFER_STYLE_ATTRIBUTES =
Use
styleinsted ofalignfor table cells. 1 << 15
- FULL_INFO_STRING =
Include full info strings of code blocks in separate attribute.
1 << 16
- RENDER_FLAGS =
{ source_position: SOURCE_POSITION, hard_breaks: HARD_BREAKS, no_breaks: NO_BREAKS, pre_lang: GITHUB_PRE_LANG, table_prefer_style_attributes: TABLE_PREFER_STYLE_ATTRIBUTES, full_info_string: FULL_INFO_STRING, unsafe: UNSAFE, }
- VERSION =
"0.17.0"
Class Method Summary collapse
- .extensions ⇒ Object
-
.parse(text, flags: DEFAULT, extensions: nil) ⇒ Object
Parse a Markdown string into a document node.
-
.render_html(text, flags: DEFAULT, parse_flags: flags, render_flags: flags, extensions: []) ⇒ Object
Parse a Markdown string and render it as HTML.
Class Method Details
.extensions ⇒ Object
1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 |
# File 'ext/markly/markly.c', line 1223
static VALUE Markly_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;
}
|
.parse(text, flags: DEFAULT, extensions: nil) ⇒ Object
Parse a Markdown string into a document node.
27 28 29 30 31 32 33 34 35 |
# File 'lib/markly.rb', line 27 def self.parse(text, flags: DEFAULT, extensions: nil) parser = Parser.new(flags) extensions&.each do |extension| parser.enable(extension) end return parser.parse(text.encode(Encoding::UTF_8)) end |
.render_html(text, flags: DEFAULT, parse_flags: flags, render_flags: flags, extensions: []) ⇒ Object
Parse a Markdown string and render it as HTML.
45 46 47 48 49 |
# File 'lib/markly.rb', line 45 def self.render_html(text, flags: DEFAULT, parse_flags: flags, render_flags: flags, extensions: []) root = self.parse(text, flags: parse_flags, extensions: extensions) return root.to_html(flags: render_flags, extensions: extensions) end |