hamdown_core 0.5.1 → 0.5.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e09fb9def3ca4225b54b91fdf00fd78deb1c89c0b066e3a70c97e31e99a0c91
4
- data.tar.gz: 902d448c467dc0978c588a6d847a2a4ff8644f6dd8ec66e0a9950c2bdd22dcaf
3
+ metadata.gz: 6795f7bf5f3a006d7b20f07596503d70e3912b567aceb7179164335405752fb2
4
+ data.tar.gz: b9f66727409c5fff800a8db0a19d16f9b5d3d073470e78f699b81caad917f198
5
5
  SHA512:
6
- metadata.gz: ce384aa4492c9ccffddbaae57dedc083557a8e33511ac548211d6187e832966d41ac3e67c3c077b37d98cd2e412c4d7d2798dfdaccc3f1415048f5c6e93b1cf4
7
- data.tar.gz: 87877b212812dfa8b235de83bf7dec76613fe65a7e26db7c02b7b67b93cdc22a3b30a7d44b91f04f71936b14fccfaf00cb24ae97489f967cdfb7dabef8ac7746
6
+ metadata.gz: 9905f6d3da2e838fc073ab52c8ece27d064a426bb51cfb77bbc4c134e37d49f0cc8475a0ff28a3f7fe2bf372c72002037c5310e5e051be93b19d972f3cd4f56b
7
+ data.tar.gz: d57d27a4ae097f7ee0dda7fb96f553121dc4298062fa5c9bf701650a91d106a490e93a36b5c297bbfca754c0e12549e8af62938fd6965fc284f05f6b653bda90
data/README.md CHANGED
@@ -62,3 +62,4 @@ The gem is available as open source under the terms of the [MIT License](http://
62
62
 
63
63
  - Fix code by Rubocop
64
64
  - To write tests
65
+ - add code markdown block feature
data/input.hd CHANGED
@@ -1,30 +1,18 @@
1
- %div.container
2
- = "first"
3
- # HamdownCore or hamdown_core
4
1
 
5
- %div.container2
6
- = "first.2"
7
- # Helo sdf sdf
8
- sdf sdf sdfs df %sd sdf %sdfsdfs
9
- asd sdf sdf sdf sdfs dfsf
10
2
 
3
+ <h3 id="and-some-lists">And some lists</h3>
4
+ <h4 id="unordered-list">Unordered list</h4>
11
5
 
6
+ <ul>
7
+ <li>ULItem 1</li>
8
+ <li>ULItem 2</li>
9
+ </ul>
12
10
 
13
- = "second"
14
- <!--This means we can use HTML elements in Markdown, such as the comment
15
- element, and they won't be affected by a markdown parser. However, if you
16
- create an HTML element in your markdown file, you cannot use markdown syntax
17
- within that element's contents.-->
11
+ <ol>
12
+ <li>OLItem 1</li>
13
+ <li>OLItem 2</li>
14
+ </ol>
18
15
 
19
- = "third"
20
- # This is an <h1>
21
16
 
22
- ## This is an <h2>
17
+ <h4 id="ordered-list">Ordered list</h4>
23
18
 
24
- = 'and just test'
25
- hello it is just text
26
-
27
- text text text
28
- text text
29
-
30
- lololo
@@ -134,7 +134,7 @@ module HamdownCore
134
134
  end
135
135
  end
136
136
 
137
- Text = Struct.new(:text, :escape_html, :filename, :lineno) do
137
+ BaseText = Struct.new(:text, :escape_html, :filename, :lineno) do
138
138
  def initialize(*)
139
139
  super
140
140
  if escape_html.nil?
@@ -151,6 +151,9 @@ module HamdownCore
151
151
  end
152
152
  end
153
153
 
154
+ class Text < BaseText; end
155
+
156
+ # markdown
154
157
  class MdHeader < Text; end
155
158
  class MdList < Text; end
156
159
  class MdQuote < Text; end
@@ -159,6 +162,72 @@ module HamdownCore
159
162
  class MdLinkTitle < Text; end
160
163
  class MdLink < Text; end
161
164
 
165
+ # html
166
+ HtmlList = Struct.new(:children, :text, :filename, :lineno) do
167
+ include HasChildren
168
+
169
+ def to_h
170
+ super.merge(type: 'html_list')
171
+ end
172
+ end
173
+ class HtmlOlList < HtmlList
174
+ def ol_list?
175
+ true
176
+ end
177
+ def html_list?
178
+ true
179
+ end
180
+ end
181
+ class HtmlUlList < HtmlList
182
+ def ol_list?
183
+ false
184
+ end
185
+ def html_list?
186
+ true
187
+ end
188
+ end
189
+
190
+ class HtmlListItem < BaseText
191
+ def html_list_item?
192
+ true
193
+ end
194
+ def markdownable?
195
+ false
196
+ end
197
+ def to_ol_list_item!
198
+ node = HtmlOlListItem.new
199
+ node.filename = filename
200
+ node.lineno = lineno
201
+ node.text = text
202
+ node
203
+ end
204
+ def to_ul_list_item!
205
+ node = HtmlUlListItem.new
206
+ node.filename = filename
207
+ node.lineno = lineno
208
+ node.text = text
209
+ node
210
+ end
211
+ end
212
+ class HtmlOlListItem < HtmlListItem
213
+ def text
214
+ str = super.gsub('<li>', '').gsub('</li>', '')
215
+ "1. #{str}"
216
+ end
217
+ end
218
+ class HtmlUlListItem < HtmlListItem
219
+ def text
220
+ str = super.gsub('<li>', '').gsub('</li>', '')
221
+ "* #{str}"
222
+ end
223
+ end
224
+
225
+ class HtmlListEnd < BaseText
226
+ def markdownable?
227
+ false
228
+ end
229
+ end
230
+
162
231
  Filter = Struct.new(:name, :texts, :filename, :lineno) do
163
232
  def initialize(*)
164
233
  super
@@ -8,7 +8,6 @@ require_relative 'line_parser'
8
8
  require_relative 'ruby_multiline'
9
9
  require_relative 'script_parser'
10
10
  require_relative 'utils'
11
- require 'pry'
12
11
 
13
12
  module HamdownCore
14
13
  class Parser
@@ -76,8 +75,13 @@ module HamdownCore
76
75
  'link_with_title' => /^[^!]\[[^\[\]]*?\]\([^\s]*\s\".*\"\)/
77
76
  # codeblock # nesting within plain text is illegal
78
77
  }
79
- # bold, italic, b_italic, monospace
80
- # paragraphs !
78
+
79
+ HTML = {
80
+ 'list_ol_root' => /^ *<ol>/,
81
+ 'list_ul_root' => /^ *<ul>/,
82
+ 'list_end' => /^ *<\/(ul|ol)>/,
83
+ 'list_item' => /^ *<li>.*<\/li>$/
84
+ }
81
85
 
82
86
  def parse_line(line)
83
87
  text, indent = @indent_tracker.process(line, @line_parser.lineno)
@@ -107,6 +111,14 @@ module HamdownCore
107
111
  parse_md_link(text)
108
112
  when MARKDOWN['link_title']
109
113
  parse_md_link(text, true)
114
+ when HTML['list_ol_root']
115
+ parse_html_list(text, :ol)
116
+ when HTML['list_ul_root']
117
+ parse_html_list(text, :ul)
118
+ when HTML['list_end']
119
+ parse_html_list_end(text)
120
+ when HTML['list_item']
121
+ parse_html_list_item(text)
110
122
  else
111
123
  std_parse_line(text, indent)
112
124
  end
@@ -180,6 +192,24 @@ module HamdownCore
180
192
  @ast << create_node(Ast::MdList) { |t| t.text = text }
181
193
  end
182
194
 
195
+ def parse_html_list(text, type)
196
+ if type == :ol
197
+ @ast << create_node(Ast::HtmlOlList) { |t| t.text = text }
198
+ elsif type == :ul
199
+ @ast << create_node(Ast::HtmlUlList) { |t| t.text = text }
200
+ else
201
+ raise 'undefined html list type'
202
+ end
203
+ end
204
+
205
+ def parse_html_list_item(text)
206
+ @ast << create_node(Ast::HtmlListItem) { |t| t.text = text }
207
+ end
208
+
209
+ def parse_html_list_end(text)
210
+ @ast << create_node(Ast::HtmlListEnd) { |t| t.text = text }
211
+ end
212
+
183
213
  def parse_md_quote(text)
184
214
  @ast << create_node(Ast::MdQuote) { |t| t.text = text }
185
215
  end
@@ -29,8 +29,18 @@ module HamdownCore
29
29
  node = transform(node)
30
30
  end
31
31
 
32
+ if node.respond_to?(:html_list?) and node.html_list?
33
+ filter = if node.ol_list?
34
+ create_filter(node.children.map(&:to_ol_list_item!))
35
+ else
36
+ create_filter(node.children.map(&:to_ul_list_item!))
37
+ end
38
+ node = filter
39
+ end
40
+
32
41
  new_root_node << node
33
42
  end
43
+
34
44
  if collected_nodes.size > 0
35
45
  filter = create_filter(collected_nodes)
36
46
  collected_nodes = []
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module HamdownCore
3
- VERSION = '0.5.1'
3
+ VERSION = '0.5.3'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hamdown_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kohei Suzuki
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-03-09 00:00:00.000000000 Z
12
+ date: 2019-05-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: benchmark-ips