Class: Sourcerer::MarkDownGrade::HeadingWithId
- Inherits:
-
ReverseMarkdown::Converters::Base
- Object
- ReverseMarkdown::Converters::Base
- Sourcerer::MarkDownGrade::HeadingWithId
- Defined in:
- lib/sourcerer/mark_down_grade.rb
Overview
Heading converter: optionally preserve id attribute by emitting an anchor before the heading
Instance Method Summary collapse
Instance Method Details
#convert(node, state = {}) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/sourcerer/mark_down_grade.rb', line 122 def convert node, state={} if node.name == 'h6' && node['class'].to_s.split.include?('block-title') title_text = Sourcerer::MarkDownGrade.format_block_title(treat_children(node, state)) return "#{title_text} \n" end level = node.name[/\d/].to_i prefix = '#' * level heading = "#{prefix} #{treat_children(node, state)}\n" if Sourcerer::MarkDownGrade.config[:preserve_heading_ids] anchor = node['id'].to_s.strip anchor.empty? ? "\n#{heading}" : "\n<a id=\"#{anchor}\"></a>\n#{heading}" else "\n#{heading}" end end |