module Markly
Nested
Definitions
DEFAULT = 0
The default parsing system.
VALIDATE_UTF8 = 1 << 9
Replace illegal sequences with the replacement character U+FFFD
.
SMART = 1 << 10
Use smart punctuation (curly quotes, etc.).
LIBERAL_HTML_TAG = 1 << 12
Support liberal parsing of inline HTML tags.
FOOTNOTES = 1 << 13
Parse footnotes.
STRIKETHROUGH_DOUBLE_TILDE = 1 << 14
Support strikethrough using double tildes.
UNSAFE = 1 << 17
Allow raw/custom HTML and unsafe links.
SOURCE_POSITION = 1 << 1
Include source position in rendered HTML.
HARD_BREAKS = 1 << 2
Treat \n
as hardbreaks (by adding <br/>
).
NO_BREAKS = 1 << 4
Translate \n
in the source to a single whitespace.
GITHUB_PRE_LANG = 1 << 11
Use GitHub-style <pre lang>
for fenced code blocks.
TABLE_PREFER_STYLE_ATTRIBUTES = 1 << 15
Use style
insted of align
for table cells.
FULL_INFO_STRING = 1 << 16
Include full info strings of code blocks in separate attribute.
def self.parse(text, flags: DEFAULT, extensions: nil)
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 parser
node.
Implementation
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
def self.render_html(text, flags: DEFAULT, parse_flags: flags, render_flags: flags, extensions: [])
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.
Implementation
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