module Luce
Overview
Parses text in a Markdown-like format building an AST tree that can then be rendered to HTML.
If you are only interested in rendering Markdown to HTML, please refer
to the README which explains the use of Luce.to_html.
The main entrypoint to the library is the Document which encapsulates the
parsing process converting a Markdown text into a tree of Node (Array(Node)).
Two main parsing mechanics are used:
- Blocks, representing top level elements like: headers, paragraphs, blockquotes,
code blocks, ... implemented via
BlockSyntaxsubclasses. - Inlines, representing chunks of test within a block with special meaning, like:
links, emphasis, inlined code, ... implemented via
InlineSyntaxsubclasses.
Looking closely at Document.new() a few other concepts merit a mention:
ExtensionSetthat provides configurations for common Markdown flavorsResolverwhich aid in resolving links and images.
If you are looking at extending the library to support custom formatting what you may want is to:
- Implement your own
InlineSyntaxsubclasses - Implement your own
BlockSyntaxsubclasses - Instruct the library to use those by:
- Creating a new
ExtensionSetfrom one of the existing flavors adding your syntaxes - Passing your syntaxes to
DocumentorLuce.to_htmlas parameters.
- Creating a new
Defined in:
luce.crluce/ast.cr
luce/block_parser.cr
luce/document.cr
luce/emojis.cr
luce/extension_set.cr
luce/html_renderer.cr
luce/inline_parser.cr
luce/util.cr
Constant Summary
-
VERSION =
"0.2.0"
Class Method Summary
-
.render_html(nodes : Array(Node)) : String
Render nodes to HTML.
-
.to_html(markdown : String, block_syntaxes = Array(BlockSyntax).new, inline_syntaxes = Array(InlineSyntax).new, extension_set : ExtensionSet | Nil = nil, link_resolver : Resolver | Nil = nil, image_link_resolver : Resolver | Nil = nil, inline_only : Bool = false, encode_html : Bool = true, with_default_block_syntaxes : Bool = true, with_default_inline_syntaxes : Bool = true) : String
Converts the given string of Markdown to HTML
Class Method Detail
def self.to_html(markdown : String, block_syntaxes = Array(BlockSyntax).new, inline_syntaxes = Array(InlineSyntax).new, extension_set : ExtensionSet | Nil = nil, link_resolver : Resolver | Nil = nil, image_link_resolver : Resolver | Nil = nil, inline_only : Bool = false, encode_html : Bool = true, with_default_block_syntaxes : Bool = true, with_default_inline_syntaxes : Bool = true) : String
#
Converts the given string of Markdown to HTML