blob: f69d38843eb36a7adfb05998c398f8afdf48190c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# -*- coding: utf-8; frozen_string_literal: true -*-
#
#--
# Copyright (C) 2009-2026 Thomas Leitner <t_leitner@gmx.at>
#
# This file is part of kramdown which is licensed under the MIT.
#++
#
require 'kramdown/parser'
require 'kramdown/converter'
require 'kramdown/utils'
module Kramdown
module Converter
# Converts a Kramdown::Document to a nested hash for further processing or debug output.
class HashAST < Base
def convert(el)
hash = {type: el.type}
hash[:attr] = el.attr unless el.attr.empty?
hash[:value] = el.value unless el.value.nil?
hash[:options] = el.options unless el.options.empty?
unless el.children.empty?
hash[:children] = []
el.children.each {|child| hash[:children] << convert(child) }
end
hash
end
end
HashAst = HashAST
end
end
|