himekami-markdown 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f2d02acfe4a57b376f17b1ac8555d412cf8c2aa
4
- data.tar.gz: 43c861f7ce6368a392f2b7f1e2ad7b2430be70dd
3
+ metadata.gz: '094e47b827689d146bfd8eb9962fc69c15d287ac'
4
+ data.tar.gz: 3965a4adcf0060587375c15e9b8d242e73aadad5
5
5
  SHA512:
6
- metadata.gz: b4c77af2f1798de8cd32ea9ba4bde47a4717f3c6c463023148b055e667d1b25a14d561da5a5558b8203c1fed8ddba31983835978805b564d8a524fee6d894a18
7
- data.tar.gz: 6f603dbda440e9b25c86729bf33de19acd8b4fb7efc29ad95d5c2bf3f19740aea38b4b02d6467e76f3c519dcee9f79c789bd1360afc56689dac5d774a910a5ca
6
+ metadata.gz: 5813f9714f8b3b1c35df4a9e022160d189970410e2422a8a3dc49c7b09e7bd2deeae910b9b02c77c08a9979a6c7cf318bad07f1c5f70d9f104e73be59ca785d6
7
+ data.tar.gz: 37d3ee27a32ae8b7dda9f94330fcbc432b8c04b531cdbe4e34058a29c653daf1322a9fd337c380e6448cb5a1f3f518e3d7458d5f2167ab8d40f6c16aae7707fb
@@ -4,7 +4,10 @@ module Himekami
4
4
  class Checkbox < HTML::Pipeline::Filter
5
5
  def call
6
6
  doc.search("li").each do |li|
7
- List.new(li).convert! if List.has_checkbox?(li)
7
+ if List.has_checkbox?(li)
8
+ li = List.new(li)
9
+ li.convert!
10
+ end
8
11
  end
9
12
  doc
10
13
  end
@@ -32,24 +35,31 @@ module Himekami
32
35
 
33
36
  def convert!
34
37
  add_css_class
38
+ text_node
35
39
  add_checkbox_html
36
40
  end
37
41
 
38
42
  private
39
43
 
44
+ def text_node
45
+ return @node.children.find { |node| node.name == 'p' }.children.first if @node.children.any? { |node| node.name == 'p' }
46
+
47
+ @node.children.first
48
+ end
49
+
40
50
  def add_css_class
41
51
  @node['class'] = LI_ATTR_CLASS if @node['class'].nil? || !@node['class'].include?(LI_ATTR_CLASS)
42
52
  end
43
53
 
44
54
  def remove_md
45
- @node.children.first.content = @node.children.first.content.sub(CHECKBOX_PATTERN, '').strip
55
+ text_node.content = text_node.content.sub(CHECKBOX_PATTERN, '').strip
46
56
  end
47
57
 
48
58
  def add_checkbox_html
49
59
  html = open_checkbox? ? render_open_checkbox_html : render_closed_checkbox_html
50
60
 
51
61
  remove_md
52
- @node.children.first.add_previous_sibling(html)
62
+ text_node.add_previous_sibling(html)
53
63
  end
54
64
 
55
65
  def render_open_checkbox_html
@@ -61,7 +71,7 @@ module Himekami
61
71
  end
62
72
 
63
73
  def open_checkbox?
64
- @node.children.first.content.include?(CHECKBOX_OPEN)
74
+ text_node.content.include?(CHECKBOX_OPEN)
65
75
  end
66
76
  end
67
77
  end
@@ -1,5 +1,5 @@
1
1
  module Himekami
2
2
  module Markdown
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: himekami-markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - otukutun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-31 00:00:00.000000000 Z
11
+ date: 2017-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler