Sha256: d7760553d2f773651640e1064823ee44429c12c76a42f00ef861934c6c6c0850
Contents?: true
Size: 1.03 KB
Versions: 34
Compression:
Stored size: 1.03 KB
Contents
module Govspeak Header = Struct.new(:text, :level, :id) class HeaderExtractor < Kramdown::Converter::Base def convert(doc) headers = [] doc.root.children.each do |el| if el.type == :header headers << build_header(el) next end headers << find_headers(el) if el.type == :html_element end headers.flatten.compact end private def id(element) element.attr.fetch("id", generate_id(element.options[:raw_text])) end def build_header(element) Header.new(element.options[:raw_text], element.options[:level], id(element)) end def find_headers(parent) headers = [] case parent.type when :header headers << build_header(parent) when :html_element parent.children.each do |child| if child.type == :header headers << build_header(child) elsif !child.children.empty? headers << find_headers(child) end end end headers end end end
Version data entries
34 entries across 34 versions & 1 rubygems