markdiff 0.5.2 → 0.5.3
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/example/app.rb +2 -0
- data/lib/markdiff/differ.rb +6 -34
- 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: dc5276d66e3a92675f67df003904b6af4e11e07a
|
4
|
+
data.tar.gz: 6f87e774e011a747c1d0ca04d3c03aa254ace843
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0875b2ed67d13d30eb534b9c791a2157f99da480815b8c2f92ab039defa67fdb70afcf2d1bafb78862771c38db7118df5e6ffea4cfe77e051589824eff370d91
|
7
|
+
data.tar.gz: 04d03b94cd96f994a7e752988ce33ba0117231ff7269a2efc17c6403c59e97d38899968a589d2e9d7ee56b8a7d0ee2a117837a875e990fcf51f9b8839c05bbe6
|
data/CHANGELOG.md
CHANGED
data/example/app.rb
CHANGED
@@ -8,6 +8,8 @@ get "/" do
|
|
8
8
|
if params[:before] && params[:after]
|
9
9
|
html_before = markdown.render(params[:before])
|
10
10
|
html_after = markdown.render(params[:after])
|
11
|
+
p html_before
|
12
|
+
p html_after
|
11
13
|
@diff = Markdiff::Differ.new.render(html_before, html_after)
|
12
14
|
end
|
13
15
|
erb :index
|
data/lib/markdiff/differ.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "diff/lcs"
|
1
2
|
require "nokogiri"
|
2
3
|
require "markdiff/operations/add_child_operation"
|
3
4
|
require "markdiff/operations/add_data_before_href_operation"
|
@@ -72,21 +73,6 @@ module Markdiff
|
|
72
73
|
|
73
74
|
private
|
74
75
|
|
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
|
-
|
90
76
|
# 1. Create identity map and collect patches from descendants
|
91
77
|
# 1-1. Detect exact-matched nodes
|
92
78
|
# 1-2. Detect partial-matched nodes and recursively walk through its children
|
@@ -102,30 +88,16 @@ module Markdiff
|
|
102
88
|
identity_map = {}
|
103
89
|
inverted_identity_map = {}
|
104
90
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
91
|
+
::Diff::LCS.sdiff(before_node.children.map(&:to_s), after_node.children.map(&:to_s)).each do |element|
|
92
|
+
type, before, after = *element
|
93
|
+
if type == "="
|
94
|
+
before_child = before_node.children[before[0]]
|
95
|
+
after_child = after_node.children[after[0]]
|
109
96
|
identity_map[before_child] = after_child
|
110
97
|
inverted_identity_map[after_child] = before_child
|
111
98
|
end
|
112
99
|
end
|
113
100
|
|
114
|
-
# Exactly matching
|
115
|
-
before_node.children.each do |before_child|
|
116
|
-
next if identity_map[before_child]
|
117
|
-
after_node.children.each do |after_child|
|
118
|
-
case
|
119
|
-
when identity_map[before_child]
|
120
|
-
break
|
121
|
-
when inverted_identity_map[after_child]
|
122
|
-
when check_exact_match(before_child, after_child)
|
123
|
-
identity_map[before_child] = after_child
|
124
|
-
inverted_identity_map[after_child] = before_child
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
101
|
# Partial matching
|
130
102
|
before_node.children.each do |before_child|
|
131
103
|
if identity_map[before_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.3
|
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-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|