class MarkdownIncluder::Heading
Attributes
level[RW]
title[RW]
Public Class Methods
new(level, title)
click to toggle source
# File lib/markdown_helper/markdown_includer.rb, line 216 def initialize(level, title) self.level = level self.title = title end
parse(line)
click to toggle source
# File lib/markdown_helper/markdown_includer.rb, line 221 def self.parse(line) # Four leading spaces not allowed (but three are allowed). return nil if line.start_with?(' ' * 4) stripped_line = line.sub(/^ */, '') # Now must begin with hash marks and space. return nil unless stripped_line.match(/^#+ /) hash_marks, title = stripped_line.split(' ', 2) level = hash_marks.size # Seventh level heading not allowed. return nil if level > 6 self.new(level, title) end
Public Instance Methods
link(anchor_counts = Hash.new(0))
click to toggle source
# File lib/markdown_helper/markdown_includer.rb, line 235 def link(anchor_counts = Hash.new(0)) anchor = title.downcase anchor.gsub!(/[^\p{Word}\- ]/u, '') # remove punctuation anchor.gsub!(' ', '-') # replace spaces with dash anchor_count = anchor_counts[anchor] anchor_counts[anchor] += 1 suffix = (anchor_count == 0) ? '' : "-#{anchor_count}" "[#{title}](##{anchor}#{suffix})" end