markdiff 0.7.0 → 0.8.1

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
  SHA256:
3
- metadata.gz: f86c8ef911af47d5d4271365f2a576564b2425424f1bedc8fc66cda39186ce3a
4
- data.tar.gz: 7c059f14e29a4b0496b9412f481ced9f10d4742e43d3cab31ade9b85f551b7df
3
+ metadata.gz: bcbedaaac5248f5ca65457efc285d8b931083379d9459fefd1633d6ba0074e6f
4
+ data.tar.gz: b32ed85a69e42c9ccd57dc2f5c2fd8c3835274b5a07e7629a5766a5fecd0bd97
5
5
  SHA512:
6
- metadata.gz: aa74b28c0589094b03defb2ccfadbba23572530fca2ec07e1fe73f0e810dbc8eba019257a119ea929736ca54c04c3721960e74d41037b07395b92495dbad2736
7
- data.tar.gz: 8a6a633604eaa4fdb221a779133adae4e4489e98258ef1e39e81b44c73d0fd3215b9d3bb6b1aceffb850517c21f3f2bc3ec7153f7d19e84367e0791e068c95c2
6
+ metadata.gz: 3fab67dd051cbebacdfd8cefd270b1ef4375c9cdec915f5ab06351a4504d2cbbed9970835f794c7c509394d36ceb86410719bed969f3d69ac7001e2a529570cd
7
+ data.tar.gz: febf67a5e7eb49412789f3cfb519f3e2de5daa8e42ac311c99373066cf96041a7d650d24e72337a9ffdca0fdbe1bbd403d204d18a82e143049d78fdcf8ba02e9
@@ -12,7 +12,8 @@ jobs:
12
12
  strategy:
13
13
  matrix:
14
14
  ruby:
15
- - 2.7.2
15
+ - 2.7.3
16
+ - 3.1.3
16
17
  steps:
17
18
  - uses: actions/checkout@v2
18
19
  - uses: ruby/setup-ruby@v1
data/CHANGELOG.md CHANGED
@@ -2,65 +2,119 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.8.1
6
+
7
+ ### Fixed
8
+
9
+ - Fix issue with diffs between blocks of matches.
10
+
11
+ ## 0.8.0
12
+
13
+ ### Changed
14
+
15
+ - Add class attributes to ins element: `.ins.ins-before` or `.ins.ins-after`.
16
+
17
+ ### Fixed
18
+
19
+ - Fix issue on insertion and deletion on same position.
20
+ - Fix issue with long sentences.
21
+
22
+ ## 0.7.0
23
+
24
+ ### Fixed
25
+
5
26
  - Fixed replaces shown wrongly.
6
27
 
7
28
  ## 0.6.3
8
29
 
30
+ ### Fixed
31
+
9
32
  - Support diff-lcs v1.4+.
10
33
 
11
34
  ## 0.6.2
12
35
 
36
+ ### Changed
37
+
13
38
  - Support tr.added and tr.deleted.
14
39
 
15
40
  ## 0.6.1
16
41
 
42
+ ### Changed
43
+
17
44
  - Fix patch order bug by making sort stable.
18
45
 
19
46
  ## 0.6.0
20
47
 
48
+ ### Changed
49
+
21
50
  - Add .del class to all del elements.
22
51
 
23
52
  ## 0.5.5
24
53
 
54
+ ### Fixed
55
+
25
56
  - Preserve classes on adding new class (e.g. .added).
26
57
 
27
58
  ## 0.5.4
28
59
 
60
+ ### Fixed
61
+
29
62
  - Fix bug on patch operations order.
30
63
 
31
64
  ## 0.5.3
32
65
 
66
+ ### Fixed
67
+
33
68
  - Fix bug on comparing nodes.
34
69
 
35
70
  ## 0.5.2
36
71
 
72
+ ### Fixed
73
+
37
74
  - Fix bug on comparing attributes and text nodes.
38
75
 
39
76
  ## 0.5.1
40
77
 
78
+ ### Fixed
79
+
41
80
  - Fix bug on text-diff operation.
42
81
 
43
82
  ## 0.5.0
44
83
 
84
+ ### Changed
85
+
45
86
  - Wrap changed nodes by div.changed.
46
87
 
47
88
  ## 0.4.0
48
89
 
90
+ ### Changed
91
+
49
92
  - Chanage .changed specs.
93
+
94
+ ### Fixed
95
+
50
96
  - Fix bugs on text diff.
51
97
 
52
98
  ## 0.3.0
53
99
 
100
+ ### Changed
101
+
54
102
  - Support partial text diff.
55
103
 
56
104
  ## 0.2.1
57
105
 
106
+ ### Changed
107
+
58
108
  - Support li.added and li.removed.
59
109
 
60
110
  ## 0.2.0
61
111
 
112
+ ### Changed
113
+
62
114
  - Support div.changed and li.changed.
63
115
 
64
116
  ## 0.1.0
65
117
 
118
+ ### Added
119
+
66
120
  - 1st Release.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- markdiff (0.6.3)
4
+ markdiff (0.8.1)
5
5
  diff-lcs
6
6
  nokogiri
7
7
 
@@ -9,24 +9,24 @@ GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
11
  diff-lcs (1.5.0)
12
- nokogiri (1.13.1-x86_64-linux)
12
+ nokogiri (1.15.4-x86_64-linux)
13
13
  racc (~> 1.4)
14
- racc (1.6.0)
15
- rake (10.5.0)
16
- redcarpet (3.3.3)
17
- rspec (3.4.0)
18
- rspec-core (~> 3.4.0)
19
- rspec-expectations (~> 3.4.0)
20
- rspec-mocks (~> 3.4.0)
21
- rspec-core (3.4.4)
22
- rspec-support (~> 3.4.0)
23
- rspec-expectations (3.4.0)
14
+ racc (1.7.1)
15
+ rake (13.0.6)
16
+ redcarpet (3.6.0)
17
+ rspec (3.12.0)
18
+ rspec-core (~> 3.12.0)
19
+ rspec-expectations (~> 3.12.0)
20
+ rspec-mocks (~> 3.12.0)
21
+ rspec-core (3.12.1)
22
+ rspec-support (~> 3.12.0)
23
+ rspec-expectations (3.12.2)
24
24
  diff-lcs (>= 1.2.0, < 2.0)
25
- rspec-support (~> 3.4.0)
26
- rspec-mocks (3.4.1)
25
+ rspec-support (~> 3.12.0)
26
+ rspec-mocks (3.12.3)
27
27
  diff-lcs (>= 1.2.0, < 2.0)
28
- rspec-support (~> 3.4.0)
29
- rspec-support (3.4.1)
28
+ rspec-support (~> 3.12.0)
29
+ rspec-support (3.12.0)
30
30
 
31
31
  PLATFORMS
32
32
  x86_64-linux
@@ -34,9 +34,9 @@ PLATFORMS
34
34
  DEPENDENCIES
35
35
  bundler
36
36
  markdiff!
37
- rake (~> 10.0)
38
- redcarpet (= 3.3.3)
39
- rspec (= 3.4.0)
37
+ rake
38
+ redcarpet
39
+ rspec
40
40
 
41
41
  BUNDLED WITH
42
42
  2.3.6
@@ -100,14 +100,17 @@ module Markdiff
100
100
  end
101
101
 
102
102
  # Partial matching
103
- before_node.children.each do |before_child|
104
- if identity_map[before_child]
105
- next
106
- end
103
+ before_node.children.each_with_index do |before_child, index|
104
+ next if identity_map[before_child]
105
+
106
+ next_match = before_node.children[index..].find { |child| identity_map[child] }
107
+
107
108
  after_node.children.each do |after_child|
108
109
  case
109
110
  when identity_map[before_child]
110
111
  break
112
+ when next_match && inverted_identity_map[after_child] == next_match
113
+ break
111
114
  when inverted_identity_map[after_child]
112
115
  when before_child.text?
113
116
  if after_child.text?
@@ -13,30 +13,37 @@ module Markdiff
13
13
 
14
14
  # @return [Nokogiri::XML::Node]
15
15
  def inserted_node
16
- before_elements = target_node.to_s.split(" ")
17
- after_elements = @after_node.to_s.split(" ")
18
- last_deleted_pos = nil
16
+ before_elements = target_node.to_s.split(' ')
17
+ after_elements = @after_node.to_s.split(' ')
18
+ last_operation = nil
19
19
 
20
- ::Diff::LCS.diff(before_elements, after_elements).flatten(1).each do |operation|
21
- type, position, element = *operation
20
+ groupings = ::Diff::LCS.sdiff(before_elements, after_elements)
21
+ .slice_when { |prev, cur| prev.action != cur.action }
22
22
 
23
- if type == "-"
24
- before_elements[position] = %(<del class="del">#{element}</del>)
25
- last_deleted_pos = position
26
- elsif type == "+"
27
- insert = "<ins>#{element}</ins>"
23
+ output = groupings.map do |grouping|
24
+ action = grouping.first.action
28
25
 
29
- if last_deleted_pos == position
30
- before_elements[position] = "#{before_elements[position]}#{insert}"
26
+ response = case action
27
+ when "="
28
+ grouping.map(&:new_element).join(" ")
29
+ when "-"
30
+ %(<del class="del">#{grouping.map(&:old_element).join(" ")}</del>)
31
+ when "+"
32
+ %(<ins class="ins ins-before">#{grouping.map(&:new_element).join(" ")}</ins>)
33
+ when "!"
34
+ %(<del class="del">#{grouping.map(&:old_element).join(" ")}</del><ins class="ins ins-after">#{grouping.map(&:new_element).join(" ")}</ins>)
31
35
  else
32
- before_elements[position] = "#{insert}#{before_elements[position]}"
33
- end
34
- else
35
- raise "Unhandled type: #{type}"
36
+ raise "Unknown action #{action}"
36
37
  end
38
+
39
+ response = " #{response}" if last_operation && last_operation != '+'
40
+
41
+ last_operation = action
42
+
43
+ response
37
44
  end
38
45
 
39
- ::Nokogiri::HTML.fragment(before_elements.join(" "))
46
+ ::Nokogiri::HTML.fragment(output.join(''))
40
47
  end
41
48
 
42
49
  def priority
@@ -1,3 +1,3 @@
1
1
  module Markdiff
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.1"
3
3
  end
data/markdiff.gemspec CHANGED
@@ -14,9 +14,9 @@ Gem::Specification.new do |spec|
14
14
  spec.require_paths = ["lib"]
15
15
 
16
16
  spec.add_development_dependency "bundler"
17
- spec.add_development_dependency "rake", "~> 10.0"
18
- spec.add_development_dependency "redcarpet", "3.3.3"
19
- spec.add_development_dependency "rspec", "3.4.0"
17
+ spec.add_development_dependency "rake"
18
+ spec.add_development_dependency "redcarpet"
19
+ spec.add_development_dependency "rspec"
20
20
  spec.add_runtime_dependency "diff-lcs"
21
21
  spec.add_runtime_dependency "nokogiri"
22
22
  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.7.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-29 00:00:00.000000000 Z
11
+ date: 2023-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,44 +28,44 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: redcarpet
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 3.3.3
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 3.3.3
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 3.4.0
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 3.4.0
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: diff-lcs
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -142,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
142
  - !ruby/object:Gem::Version
143
143
  version: '0'
144
144
  requirements: []
145
- rubygems_version: 3.1.4
145
+ rubygems_version: 3.3.26
146
146
  signing_key:
147
147
  specification_version: 4
148
148
  summary: Rendered Markdown differ.