Skip to content

Instantly share code, notes, and snippets.

@mvanduijker
Created May 29, 2017 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvanduijker/8c2cfdcd066022669e60ac85be8ef75c to your computer and use it in GitHub Desktop.
Save mvanduijker/8c2cfdcd066022669e60ac85be8ef75c to your computer and use it in GitHub Desktop.
CommonMark Html Mini Renderer only renders subset of commonmark. Should be good for stuff like user comments where minimal markup is required / desired
# Proof of concept to use CommonMarker to only render a subset of CommanMark language
# Good if you only want links, em, strong, etc where minimal markup is desired.
# Example: HtmlMiniRenderer.new.render(CommonMarker.render_doc("# Test"))
class HtmlMiniRenderer < CommonMarker::HtmlRenderer
[
:header,
:list,
:list_item,
:blockquote,
:hrule,
:code_block,
:image,
:code,
:table,
:table_header,
:table_row,
:table_cell
].each do |method|
define_method method do |node|
block do
out(node.to_commonmark)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment