Class: Forspell::Loaders::Markdown::FilteredHash

Inherits:
Object
  • Object
show all
Defined in:
lib/forspell/loaders/markdown.rb

Constant Summary collapse

PERMITTED_TYPES =
%i[
  text
  smart_quote
].freeze

Instance Method Summary collapse

Instance Method Details

#convert(el, options) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/forspell/loaders/markdown.rb', line 16

def convert(el, options)
  return if !PERMITTED_TYPES.include?(el.type) && el.children.empty?

  hash = { type: el.type }
  hash[:attr] = el.attr unless el.attr.empty?
  hash[:value] = el.value unless el.value.nil?
  hash[:location] = el.options[:location]
  unless el.children.empty?
    hash[:children] = []
    el.children.each { |child| hash[:children] << convert(child, options) }
  end
  hash
end