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 +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/markdiff/differ.rb +25 -6
- data/lib/markdiff/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e49f17b9acfed092397a0802104a99b6b29b82a
|
4
|
+
data.tar.gz: 614efe0f44dba5c6fb62796a45e99c9e580a3d7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ada905b91769facabbd99b9afaa5a05a623701d8520322ac781727640214b01a184bcb6803167901c66cfe1a59cf3659787a3105de03a9d59e99ebdcefda59c7
|
7
|
+
data.tar.gz: 477f06da5d70286baec743f843e6c6476fb0d47cf7d1c10e9d194968e6ac213ff57a191f379a409695e0540d8e0b24c269356f28102e77983e69962f142872b9
|
data/CHANGELOG.md
CHANGED
data/lib/markdiff/differ.rb
CHANGED
@@ -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
|
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
|
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
|
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
|
data/lib/markdiff/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2015-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|