Class: Sourcerer::MarkDownGrade::InlineSemanticConverter

Inherits:
ReverseMarkdown::Converters::Base
  • Object
show all
Defined in:
lib/sourcerer/mark_down_grade.rb

Overview

Preserve inline semantic tags when class/role attributes are present.

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, fallback_converter) ⇒ InlineSemanticConverter

Returns a new instance of InlineSemanticConverter.



234
235
236
237
238
# File 'lib/sourcerer/mark_down_grade.rb', line 234

def initialize tag_name, fallback_converter
  super()
  @tag_name = tag_name
  @fallback_converter = fallback_converter
end

Instance Method Details

#convert(node, state = {}) ⇒ Object



240
241
242
243
244
245
246
247
# File 'lib/sourcerer/mark_down_grade.rb', line 240

def convert node, state={}
  return @fallback_converter.convert(node, state) unless preserve_semantic_tag?(node)

  attrs = []
  attrs << %( class="#{node['class']}") if node['class']
  attrs << %( role="#{node['role']}") if node['role']
  "<#{@tag_name}#{attrs.join}>#{treat_children(node, state)}</#{@tag_name}>"
end