Module: PageHub::Markdown::ToC
- Defined in:
- lib/pagehub-markdown/processors/toc_generator.rb
Defined Under Namespace
Classes: Heading
Constant Summary collapse
- FENCED_CODE_BLOCKS =
/```[^`]+```/xm
Class Method Summary collapse
-
.from_markdown(markdown, threshold = 6) ⇒ Object
Builds a tree of headings from a given block of Markdown text, the returned list can be turned into HTML using ToC::to_html().
-
.to_html(toc) ⇒ Object
renders a table of content using nested <ol> list nodes from a given list of Heading objects produced by ToC::from_markdown().
Class Method Details
.from_markdown(markdown, threshold = 6) ⇒ Object
Builds a tree of headings from a given block of Markdown text, the returned list can be turned into HTML using ToC::to_html()
9 10 11 |
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 9 def self.from_markdown(markdown, threshold = 6) self.from_content(/(#+)\s([^\n]+)/, lambda { |l, t| return l.length, t }, markdown, threshold) end |
.to_html(toc) ⇒ Object
renders a table of content using nested <ol> list nodes from a given list of Heading objects produced by ToC::from_markdown()
15 16 17 18 19 20 |
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 15 def self.to_html(toc) html = "<ol class=\"table-of-contents\">" toc.each { |heading| html << heading.to_html } html << "</ol>" html end |