class Kmarkdown
Markdonw is a wrapper over Kramdown::Document that
-
translate my atom.io “` code block to kramdown ~~~ code block
-
and provides
toc
Take care of two things about config - it must:
-
have one empty line before any table;
-
have one empty line before any code block;
-
have one empty line befora any list;
-
char “|”, even escaped as “|” can bring some problem;
-
have two space indentation in lists.
Usage:
md = Markdown.new(File.read("document.md")) File.write("document.html", md.toc << "\n" << md.html)
Constants
- DEFAULT_OPTIONS
Public Class Methods
new(text, options = {})
click to toggle source
Calls superclass method
# File lib/minireq/site/kmarkdown.rb, line 25 def initialize(text, options = {}) to_kramdown!(text) options.merge! DEFAULT_OPTIONS super(text, options) end
Public Instance Methods
html()
click to toggle source
# File lib/minireq/site/kmarkdown.rb, line 31 def html to_html end
toc()
click to toggle source
# File lib/minireq/site/kmarkdown.rb, line 35 def toc build_toc(to_toc) end
Protected Instance Methods
build_link(toc)
click to toggle source
# File lib/minireq/site/kmarkdown.rb, line 59 def build_link(toc) id = toc.attr[:id] text = toc.value.options[:raw_text] "<a href=\"##{id}\">#{text}</a>" end
build_toc(toc, html = nil)
click to toggle source
syntax_highlighter: :rouge, syntax_highlighter_opts: { line_numbers: false }
# File lib/minireq/site/kmarkdown.rb, line 48 def build_toc(toc, html = nil) html ||= "" html << "<ul>\n" toc.children.inject(html) do |s, h| s << "<li>" << build_link(h) build_toc(h, s) unless h.children.empty? s << "</li>\n" end html << "</ul>\n" end