Class: Markdown::String

Inherits:
String
  • Object
show all
Defined in:
lib/sixarm_ruby_markdown_table_of_contents/markdown/string.rb

Instance Method Summary collapse

Instance Method Details

#generate_tocObject



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_tocObject



16
17
18
# File 'lib/sixarm_ruby_markdown_table_of_contents/markdown/string.rb', line 16

def match_toc
  /(^ *\* \[.*?\]\(#.*?\) *\n)+/m
end

#refresh_tocObject



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