hexp-kramdown 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7019211ad6d4b939567b0cc4d9724e62d2fd39fd
4
+ data.tar.gz: 7f8ba23d23692467ae04e351be9ea4f1545d9a29
5
+ SHA512:
6
+ metadata.gz: ca44230d3aaad1cd2f59fddc840505b70bb6fb564a8c27d2dd9fac831b3271d20e2c58d1dc41697bd2f72c5d14754d32394a6ab8fa36e27c39c22e1aca0f4de0
7
+ data.tar.gz: 89ddc7e5d1464dfdef4d439087135e4fc93d3e1251b82c6d7f1220c2169f8934f6b7bf82e200ab4ee7058446f710ecfdc2b68760ee7dfb1b6ca7487aa98ae209
data/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # Hexp::Kramdown
2
+
3
+ Convert a Kramdown document to Hexp.
4
+
5
+ ``` ruby
6
+ doc = Kramdown::Document.parse(source)
7
+ hexp = Hexp::Kramdown.convert(doc)
8
+ ```
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = 'hexp-kramdown'
5
+ gem.version = "0.9.0"
6
+ gem.authors = [ 'Arne Brasseur' ]
7
+ gem.email = [ 'arne@arnebrasseur.net' ]
8
+ gem.description = 'Parse Markdown/Kramdown with YAML metadata'
9
+ gem.summary = gem.description
10
+ gem.homepage = 'https://github.com/plexus/hexp-kramdown'
11
+ gem.license = 'MIT'
12
+
13
+ gem.require_paths = %w[lib]
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.test_files = `git ls-files -- spec`.split($/)
16
+ gem.extra_rdoc_files = %w[README.md]
17
+
18
+ gem.add_runtime_dependency 'hexp', '>= 0.3'
19
+ gem.add_runtime_dependency 'kramdown', '>= 1.4'
20
+ end
@@ -0,0 +1,128 @@
1
+ # coding: utf-8
2
+ module Hexp
3
+ module Kramdown
4
+ class Converter
5
+ attr_accessor :type, :value, :attr, :children, :options
6
+ undef_method :p
7
+
8
+ # Convert a Kramdown syntax tree into Hexp.
9
+ #
10
+ # @example
11
+ # markdown = "# Hello!\n\nChunky *bacon*!\n"
12
+ # document = Kramdown::Document.new(markdown)
13
+ # hexp = converter.convert(document.root)
14
+ #
15
+ # @param el [Kramdown::Element] The root element to convert
16
+ # @return [Hexp::Node]
17
+ # @api public
18
+ #
19
+ def convert(el)
20
+ #Kernel.p el ; exit
21
+ @type, @value, @attr, @children, @options =
22
+ el.type, el.value, el.attr, el.children, el.options
23
+ send(type)
24
+ end
25
+
26
+ # Process a Kramdown :root type element
27
+ #
28
+ # @return [Hexp::Node]
29
+ # @api semipublic
30
+ #
31
+ def root
32
+ H[:html, [H[:head], tag!(:body)]]
33
+ end
34
+
35
+ # Process a Kramdown :header type element
36
+ #
37
+ # @return [Hexp::Node]
38
+ # @api semipublic
39
+ #
40
+ def header
41
+ tag! "h#{options[:level]}".intern
42
+ end
43
+
44
+ # Process a Kramdown :codeblock type element
45
+ #
46
+ # @return [Hexp::Node]
47
+ # @api semipublic
48
+ #
49
+ def codeblock
50
+ H[:pre, attr, H[:code, value]]
51
+ end
52
+
53
+ def smart_quote
54
+ {
55
+ :lsquo => '‘',
56
+ :rsquo => '’',
57
+ :ldquo => '“',
58
+ :rdquo => '”',
59
+ }[value]
60
+ end
61
+
62
+ def typographic_sym
63
+ {
64
+ :hellip => '…',
65
+ :mdash => '—',
66
+ :ndash => '–',
67
+ :laquo => '«',
68
+ :raquo => '»',
69
+ :laquo_space => '« ',
70
+ :raquo_space => ' »',
71
+ }[value]
72
+ end
73
+
74
+ def html_element
75
+ H[value.to_sym, attr, convert_children]
76
+ end
77
+
78
+ def entity
79
+ value.char
80
+ end
81
+
82
+ def codespan
83
+ H[:code, value]
84
+ end
85
+
86
+ def xml_comment; end
87
+
88
+ # Create a Hexp::Node from the current element
89
+ #
90
+ # Helper for when you want to turn the Kramdown element straight into a
91
+ # Hexp::Node with the same attributes, and a one-to-one mapping of the child
92
+ # elements.
93
+ #
94
+ # @param tag [Symbol] The HTML tag to generate
95
+ # @return [Hexp::Node]
96
+ # @api semipublic
97
+ #
98
+ def tag!(tag)
99
+ H[tag, attr, convert_children]
100
+ end
101
+
102
+ [:text, :blank, :raw].each do |sym|
103
+ define_method sym do
104
+ Hexp::TextNode.new(value)
105
+ end
106
+ end
107
+
108
+ [:p, :blockquote, :ul, :li, :ol,
109
+ :dl, :dt, :dd, :em, :strong, :img, :a, :hr, :br].each do |sym|
110
+ define_method sym do
111
+ tag! type
112
+ end
113
+ end
114
+
115
+ # Convert the children of the Kramdown element to Hexps
116
+ #
117
+ # In other words, recurse down the tree. This will pass each
118
+ # child element into the converter.
119
+ #
120
+ # @return [Array<Hexp::Node>]
121
+ # @api private
122
+ #
123
+ def convert_children
124
+ children.map {|ch| convert ch }.compact
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,16 @@
1
+ require 'hexp'
2
+ require 'kramdown'
3
+
4
+ module Hexp
5
+ module Kramdown
6
+ def convert(document_or_element)
7
+ Hexp::Kramdown::Converter.new.convert(
8
+ if document_or_element.is_a? Kramdown::Document
9
+ document_or_element.root
10
+ else
11
+ document_or_element
12
+ end
13
+ ).to_hexp
14
+ end
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hexp-kramdown
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Arne Brasseur
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hexp
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: kramdown
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '1.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '1.4'
41
+ description: Parse Markdown/Kramdown with YAML metadata
42
+ email:
43
+ - arne@arnebrasseur.net
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files:
47
+ - README.md
48
+ files:
49
+ - README.md
50
+ - hexp-kramdown.gemspec
51
+ - lib/hexp/kramdown.rb
52
+ - lib/hexp/kramdown/converter.rb
53
+ homepage: https://github.com/plexus/hexp-kramdown
54
+ licenses:
55
+ - MIT
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 2.4.2
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Parse Markdown/Kramdown with YAML metadata
77
+ test_files: []