Sha256: cd1789ccd1fd9033bc2f839134ce34e9358154b793593fd59c87129b4825b716

Contents?: true

Size: 477 Bytes

Versions: 1

Compression:

Stored size: 477 Bytes

Contents

# -*- coding: utf-8 -*-
=begin rdoc
Markdown::String#refresh_toc
=end

module Markdown

  class String < ::String

    def generate_toc
      return scan(/^(##+) +(.+)\n/).map{|level, text| 
        Headline.new(level: level.length, text: text).to_markdown 
      }.join
    end

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

    def refresh_toc
      m = match(match_toc)
      return m ? m.pre_match + generate_toc + m.post_match : nil
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sixarm_ruby_markdown_table_of_contents-2.1.0 lib/sixarm_ruby_markdown_table_of_contents/markdown/string.rb