markdiff 0.5.4 → 0.6.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
- SHA1:
3
- metadata.gz: 253f738465580e885b9b7724ed900dbf171c90e3
4
- data.tar.gz: b9b941d9fc3b4169e309750ee952698f40d4c60d
2
+ SHA256:
3
+ metadata.gz: 720d3daa84f7b4c40f555ef52f2e9912e1d8170a120be554069679beab0d1954
4
+ data.tar.gz: 5b9a4631de297e8fa20e615d423c827075f0664b706f763334b65459bd8618a4
5
5
  SHA512:
6
- metadata.gz: f3cc15598bf1ff8a2915a05b78fb9e0fce660edd5557de5f023353c1a355c5fa353b40beeb6c0caf4b81918aeea560b302e02c8f6c371c7f5d4a6810e482c9d8
7
- data.tar.gz: 662a972f514dce5543a8b1f2a0107a8e05411751bef87bc7bef63c63b97ac6831d65fd1620b57534192b6aa5c1e9716ce52c989566df69399f4ddb59cfab2757
6
+ metadata.gz: 8d26e5b8cb610502f323eb8f7084c17c43a5879112b978a6faaae193d96d5534ff2254a6cac6af26988f44cc2be163130fc242667c0d591e8073fc5b6b3fb5cb
7
+ data.tar.gz: 945860da782918d04fbb6d38c61e4ae447aa1c3e448e2ec422617c3c52a5bc2ce904e14d3c8aaec43c1ab325a3fcf8c4880329d63303e679eeda66acfbbd4e47
@@ -1,30 +1,60 @@
1
+ ## 0.6.3
2
+
3
+ - Support diff-lcs v1.4+.
4
+
5
+ ## 0.6.2
6
+
7
+ - Support tr.added and tr.deleted.
8
+
9
+ ## 0.6.1
10
+
11
+ - Fix patch order bug by making sort stable.
12
+
13
+ ## 0.6.0
14
+
15
+ - Add .del class to all del elements.
16
+
17
+ ## 0.5.5
18
+
19
+ - Preserve classes on adding new class (e.g. .added).
20
+
1
21
  ## 0.5.4
2
- - Fix bug on patch operations order
22
+
23
+ - Fix bug on patch operations order.
3
24
 
4
25
  ## 0.5.3
5
- - Fix bug on comparing nodes
26
+
27
+ - Fix bug on comparing nodes.
6
28
 
7
29
  ## 0.5.2
8
- - Fix bug on comparing attributes and text nodes
30
+
31
+ - Fix bug on comparing attributes and text nodes.
9
32
 
10
33
  ## 0.5.1
11
- - Fix bug on text-diff operation
34
+
35
+ - Fix bug on text-diff operation.
12
36
 
13
37
  ## 0.5.0
14
- - Wrap changed nodes by div.changed
38
+
39
+ - Wrap changed nodes by div.changed.
15
40
 
16
41
  ## 0.4.0
17
- - Chanage .changed specs
18
- - Fix bugs on text diff
42
+
43
+ - Chanage .changed specs.
44
+ - Fix bugs on text diff.
19
45
 
20
46
  ## 0.3.0
21
- - Support partial text diff
47
+
48
+ - Support partial text diff.
22
49
 
23
50
  ## 0.2.1
24
- - Support li.added and li.removed
51
+
52
+ - Support li.added and li.removed.
25
53
 
26
54
  ## 0.2.0
27
- - Support div.changed and li.changed
55
+
56
+ - Support div.changed and li.changed.
28
57
 
29
58
  ## 0.1.0
30
- - 1st Release
59
+
60
+ - 1st Release.
@@ -14,34 +14,35 @@ module Markdiff
14
14
  # @param [Nokogiri::XML::Node] node
15
15
  # @return [Nokogiri::XML::Node] Converted node
16
16
  def apply_patch(operations, node)
17
- operations.sort_by {|operation| -operation.priority }.each do |operation|
17
+ i = 0
18
+ operations.sort_by {|operation| i += 1; [-operation.priority, i] }.each do |operation|
18
19
  case operation
19
20
  when ::Markdiff::Operations::AddChildOperation
20
21
  operation.target_node.add_child(operation.inserted_node)
21
- mark_li_as_changed(operation.target_node)
22
+ mark_li_or_tr_as_changed(operation.target_node)
22
23
  mark_top_level_node_as_changed(operation.target_node)
23
24
  when ::Markdiff::Operations::AddDataBeforeHrefOperation
24
25
  operation.target_node["data-before-href"] = operation.target_node["href"]
25
26
  operation.target_node["href"] = operation.after_href
26
- mark_li_as_changed(operation.target_node)
27
+ mark_li_or_tr_as_changed(operation.target_node)
27
28
  mark_top_level_node_as_changed(operation.target_node)
28
29
  when ::Markdiff::Operations::AddDataBeforeTagNameOperation
29
30
  operation.target_node["data-before-tag-name"] = operation.target_node.name
30
31
  operation.target_node.name = operation.after_tag_name
31
- mark_li_as_changed(operation.target_node)
32
+ mark_li_or_tr_as_changed(operation.target_node)
32
33
  mark_top_level_node_as_changed(operation.target_node)
33
34
  when ::Markdiff::Operations::AddPreviousSiblingOperation
34
35
  operation.target_node.add_previous_sibling(operation.inserted_node)
35
- mark_li_as_changed(operation.target_node) if operation.target_node.name != "li"
36
+ mark_li_or_tr_as_changed(operation.target_node) if operation.target_node.name != "li" && operation.target_node.name != "tr"
36
37
  mark_top_level_node_as_changed(operation.target_node.parent)
37
38
  when ::Markdiff::Operations::RemoveOperation
38
39
  operation.target_node.replace(operation.inserted_node) if operation.target_node != operation.inserted_node
39
- mark_li_as_changed(operation.target_node)
40
+ mark_li_or_tr_as_changed(operation.target_node)
40
41
  mark_top_level_node_as_changed(operation.target_node)
41
42
  when ::Markdiff::Operations::TextDiffOperation
42
43
  parent = operation.target_node.parent
43
44
  operation.target_node.replace(operation.inserted_node)
44
- mark_li_as_changed(parent)
45
+ mark_li_or_tr_as_changed(parent)
45
46
  mark_top_level_node_as_changed(parent)
46
47
  end
47
48
  end
@@ -181,10 +182,13 @@ module Markdiff
181
182
  end
182
183
 
183
184
  # @param [Nokogiri::XML::Node] node
184
- def mark_li_as_changed(node)
185
+ def mark_li_or_tr_as_changed(node)
185
186
  until node.parent.nil? || node.parent.fragment?
186
- if node.name == "li" && node["class"].nil?
187
- node["class"] = "changed"
187
+ if node.name == "li" || node.name == "tr"
188
+ classes = node["class"].to_s.split(/\s/)
189
+ unless classes.include?("added") || classes.include?("changed") || classes.include?("removed")
190
+ node["class"] = (classes + ["changed"]).join(" ")
191
+ end
188
192
  end
189
193
  node = node.parent
190
194
  end
@@ -5,8 +5,8 @@ module Markdiff
5
5
  class AddChildOperation < Base
6
6
  # @return [String]
7
7
  def inserted_node
8
- if @inserted_node.name == "li"
9
- @inserted_node["class"] = "added"
8
+ if @inserted_node.name == "li" || @inserted_node.name == "tr"
9
+ @inserted_node["class"] = (@inserted_node["class"].to_s.split(/\s/) + ["added"]).join(" ")
10
10
  @inserted_node.inner_html = "<ins>#{@inserted_node.inner_html}</ins>"
11
11
  @inserted_node
12
12
  else
@@ -5,9 +5,9 @@ module Markdiff
5
5
  class AddPreviousSiblingOperation < Base
6
6
  # @return [String]
7
7
  def inserted_node
8
- if @inserted_node.name == "li"
8
+ if @inserted_node.name == "li" || @inserted_node.name == "tr"
9
9
  node = @inserted_node.clone
10
- node["class"] = "added"
10
+ node["class"] = (node["class"].to_s.split(/\s/) + ["added"]).join(" ")
11
11
  node.inner_html = "<ins>#{@inserted_node.inner_html}</ins>"
12
12
  node
13
13
  else
@@ -5,12 +5,12 @@ module Markdiff
5
5
  class RemoveOperation < Base
6
6
  # @return [String]
7
7
  def inserted_node
8
- if target_node.name == "li"
8
+ if target_node.name == "li" || target_node.name == "tr"
9
9
  target_node["class"] = "removed"
10
- target_node.inner_html = "<del>#{target_node.inner_html}</del>"
10
+ target_node.inner_html = %(<del class="del">#{target_node.inner_html}</del>)
11
11
  target_node
12
12
  else
13
- "<del>#{target_node}</del>"
13
+ %(<del class="del">#{target_node}</del>)
14
14
  end
15
15
  end
16
16
 
@@ -15,10 +15,10 @@ module Markdiff
15
15
  def inserted_node
16
16
  before_elements = target_node.to_s.split(" ")
17
17
  after_elements = @after_node.to_s.split(" ")
18
- ::Diff::LCS.diff(before_elements, after_elements).flatten.each do |operation|
18
+ ::Diff::LCS.diff(before_elements, after_elements).flatten(1).each do |operation|
19
19
  type, position, element = *operation
20
20
  if type == "-"
21
- before_elements[position] = "<del>#{element}</del>"
21
+ before_elements[position] = %(<del class="del">#{element}</del>)
22
22
  else
23
23
  before_elements[position] = "#{before_elements[position]}<ins>#{element}</ins>"
24
24
  end
@@ -1,3 +1,3 @@
1
1
  module Markdiff
2
- VERSION = "0.5.4"
2
+ VERSION = "0.6.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.4
4
+ version: 0.6.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-15 00:00:00.000000000 Z
11
+ date: 2020-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -155,10 +155,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  - !ruby/object:Gem::Version
156
156
  version: '0'
157
157
  requirements: []
158
- rubyforge_project:
159
- rubygems_version: 2.4.5
158
+ rubygems_version: 3.1.4
160
159
  signing_key:
161
160
  specification_version: 4
162
161
  summary: Rendered Markdown differ.
163
162
  test_files: []
164
- has_rdoc: