in jekyll/plugins/toc_builder_hook.rb [74:108]
def extract_item(li_node, parent_id)
item = {}
item[:parent_id] = parent_id unless parent_id.nil?
p = li_node.children[0]
case p.children[0].type
when :text
title = p.children[0].value.strip
item[:id] = title.gsub(' ', '_')
item[:title] = title
item[:type] = :placeholder
when :a
a = p.children[0]
href = a.attr['href']
is_external = href.start_with?('http://', 'https://', 'ftp://', '//')
if not is_external then
basename = href.chomp(File.extname(href)).sub(/^\//,'')
href = basename + '.html'
end
item[:id] = basename
item[:title] = get_text(a.children)
item[:url] = href
item[:path] = a.attr['href']
item[:is_external] = true if is_external
end
li_node.children.drop(1).each do |child|
pages = extract_items(child, item[:id]) if child.type == :ul
item[:pages] = pages if pages != nil
end
return item
end