Module: Markly

Defined in:
lib/markly/flags.rb,
lib/markly.rb,
lib/markly/node.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, 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
PARSE_FLAGS =
{
  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 ‘\n` as hardbreaks (by adding `<br/>`).

1 << 2
NO_BREAKS =

Translate ‘\n` in 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 style insted of align for 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.15.2"

Class Method Summary collapse

Class Method Details

.extensionsObject



1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
# File 'ext/markly/markly.c', line 1148

VALUE rb_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

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 parser 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

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.



44
45
46
47
48
# File 'lib/markly.rb', line 44

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