Class: Markdown::String
- Inherits:
-
String
- Object
- String
- Markdown::String
- Defined in:
- lib/sixarm_ruby_markdown_table_of_contents/markdown/string.rb
Instance Method Summary collapse
Instance Method Details
#generate_toc ⇒ Object
10 11 12 13 14 |
# File 'lib/sixarm_ruby_markdown_table_of_contents/markdown/string.rb', line 10 def generate_toc return scan(/^(##+) +(.+)\n/).map{|level, text| Headline.new(level: level.length, text: text).to_markdown }.join end |
#match_toc ⇒ Object
16 17 18 |
# File 'lib/sixarm_ruby_markdown_table_of_contents/markdown/string.rb', line 16 def match_toc /(^ *\* \[.*?\]\(#.*?\) *\n)+/m end |
#refresh_toc ⇒ Object
20 21 22 23 |
# File 'lib/sixarm_ruby_markdown_table_of_contents/markdown/string.rb', line 20 def refresh_toc m = match(match_toc) return m ? m.pre_match + generate_toc + m.post_match : nil end |