markdiff 0.5.1 → 0.5.2

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: d21040c507d42a274d28a00d208d8f8870326697
4
- data.tar.gz: d2530960295fac137bb42865a97f237b59b640bd
3
+ metadata.gz: 8e49f17b9acfed092397a0802104a99b6b29b82a
4
+ data.tar.gz: 614efe0f44dba5c6fb62796a45e99c9e580a3d7e
5
5
  SHA512:
6
- metadata.gz: 0d0210b09bff8321cac16ff7e2aa9e1d918bcf1fcc827d0fe024e799a2a1fa16e8cd14ea387f1bf6222dae6e783b3c488a735bf3960a5e5a57fb142f3b675693
7
- data.tar.gz: 82f349441e1760e223fbdcf760a6e008cac624f9470d5ca67946bc18695601f2ab9289f75e6f718530cc48b3665d2dd0de77b7fe0be6715800f028a9cf0ba975
6
+ metadata.gz: ada905b91769facabbd99b9afaa5a05a623701d8520322ac781727640214b01a184bcb6803167901c66cfe1a59cf3659787a3105de03a9d59e99ebdcefda59c7
7
+ data.tar.gz: 477f06da5d70286baec743f843e6c6476fb0d47cf7d1c10e9d194968e6ac213ff57a191f379a409695e0540d8e0b24c269356f28102e77983e69962f142872b9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.5.2
2
+ - Fix bug on comparing attributes and text nodes
3
+
1
4
  ## 0.5.1
2
5
  - Fix bug on text-diff operation
3
6
 
@@ -72,6 +72,21 @@ module Markdiff
72
72
 
73
73
  private
74
74
 
75
+ # @param [Nokogiri::XML::Node] node1
76
+ # @param [Nokogiri::XML::Node] node2
77
+ # @return [false, true] True if given two nodes can be treated as same
78
+ def check_exact_match(node1, node2)
79
+ if node1.text?
80
+ if node2.text?
81
+ node1.to_s == node2.to_s
82
+ else
83
+ false
84
+ end
85
+ else
86
+ node1.to_html.gsub("\n", "") == node2.to_html.gsub("\n", "")
87
+ end
88
+ end
89
+
75
90
  # 1. Create identity map and collect patches from descendants
76
91
  # 1-1. Detect exact-matched nodes
77
92
  # 1-2. Detect partial-matched nodes and recursively walk through its children
@@ -90,7 +105,7 @@ module Markdiff
90
105
  # Exactly matching with index
91
106
  before_node.children.each_with_index do |before_child, before_index|
92
107
  after_child = after_node.children[before_index]
93
- if !after_child.nil? && before_child.to_html.gsub("\n", "") == after_child.to_html.gsub("\n", "")
108
+ if !after_child.nil? && check_exact_match(before_child, after_child)
94
109
  identity_map[before_child] = after_child
95
110
  inverted_identity_map[after_child] = before_child
96
111
  end
@@ -104,7 +119,7 @@ module Markdiff
104
119
  when identity_map[before_child]
105
120
  break
106
121
  when inverted_identity_map[after_child]
107
- when before_child.to_html.gsub("\n", "") == after_child.to_html.gsub("\n", "")
122
+ when check_exact_match(before_child, after_child)
108
123
  identity_map[before_child] = after_child
109
124
  inverted_identity_map[after_child] = before_child
110
125
  end
@@ -128,12 +143,16 @@ module Markdiff
128
143
  operations << ::Markdiff::Operations::TextDiffOperation.new(target_node: before_child, after_node: after_child)
129
144
  end
130
145
  when before_child.name == after_child.name
131
- if detect_href_difference(before_child, after_child)
146
+ if before_child.attributes == after_child.attributes
147
+ identity_map[before_child] = after_child
148
+ inverted_identity_map[after_child] = before_child
149
+ operations += create_patch(before_child, after_child)
150
+ elsif detect_href_difference(before_child, after_child)
132
151
  operations << ::Markdiff::Operations::AddDataBeforeHrefOperation.new(after_href: after_child["href"], target_node: before_child)
152
+ identity_map[before_child] = after_child
153
+ inverted_identity_map[after_child] = before_child
154
+ operations += create_patch(before_child, after_child)
133
155
  end
134
- identity_map[before_child] = after_child
135
- inverted_identity_map[after_child] = before_child
136
- operations += create_patch(before_child, after_child)
137
156
  when detect_heading_level_difference(before_child, after_child)
138
157
  operations << ::Markdiff::Operations::AddDataBeforeTagNameOperation.new(after_tag_name: after_child.name, target_node: before_child)
139
158
  identity_map[before_child] = after_child
@@ -1,3 +1,3 @@
1
1
  module Markdiff
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdiff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-10 00:00:00.000000000 Z
11
+ date: 2015-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler