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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e49f17b9acfed092397a0802104a99b6b29b82a
4
- data.tar.gz: 614efe0f44dba5c6fb62796a45e99c9e580a3d7e
3
+ metadata.gz: dc5276d66e3a92675f67df003904b6af4e11e07a
4
+ data.tar.gz: 6f87e774e011a747c1d0ca04d3c03aa254ace843
5
5
  SHA512:
6
- metadata.gz: ada905b91769facabbd99b9afaa5a05a623701d8520322ac781727640214b01a184bcb6803167901c66cfe1a59cf3659787a3105de03a9d59e99ebdcefda59c7
7
- data.tar.gz: 477f06da5d70286baec743f843e6c6476fb0d47cf7d1c10e9d194968e6ac213ff57a191f379a409695e0540d8e0b24c269356f28102e77983e69962f142872b9
6
+ metadata.gz: 0875b2ed67d13d30eb534b9c791a2157f99da480815b8c2f92ab039defa67fdb70afcf2d1bafb78862771c38db7118df5e6ffea4cfe77e051589824eff370d91
7
+ data.tar.gz: 04d03b94cd96f994a7e752988ce33ba0117231ff7269a2efc17c6403c59e97d38899968a589d2e9d7ee56b8a7d0ee2a117837a875e990fcf51f9b8839c05bbe6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.5.3
2
+ - Fix bug on comparing nodes
3
+
1
4
  ## 0.5.2
2
5
  - Fix bug on comparing attributes and text nodes
3
6
 
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
@@ -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
- # Exactly matching with index
106
- before_node.children.each_with_index do |before_child, before_index|
107
- after_child = after_node.children[before_index]
108
- if !after_child.nil? && check_exact_match(before_child, after_child)
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]
@@ -1,3 +1,3 @@
1
1
  module Markdiff
2
- VERSION = "0.5.2"
2
+ VERSION = "0.5.3"
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.2
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-14 00:00:00.000000000 Z
11
+ date: 2015-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler