markdiff 0.7.0 → 0.8.0

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: 50d045a93d1bcd80cd9013959fac8d671c856e298a4d0834b0b1c97b1c920143
4
+ data.tar.gz: 16c0aad8bfdc01e84406ac9fd0201c65851429dc505f5519c23aac20221e5ebb
5
5
  SHA512:
6
- metadata.gz: aa74b28c0589094b03defb2ccfadbba23572530fca2ec07e1fe73f0e810dbc8eba019257a119ea929736ca54c04c3721960e74d41037b07395b92495dbad2736
7
- data.tar.gz: 8a6a633604eaa4fdb221a779133adae4e4489e98258ef1e39e81b44c73d0fd3215b9d3bb6b1aceffb850517c21f3f2bc3ec7153f7d19e84367e0791e068c95c2
6
+ metadata.gz: 402f46556ab43370f244cd6adeb9ddd538d0dbc0a9668fa12ba25cf244b27b561c254ea9fb9173991c464d6d5775766f0d37a742209290cdda742d48bbed1fc7
7
+ data.tar.gz: 1c1e45375255e2a13ec0dffd193a06574abe0aff60154256ec0254d0c6b4bee6766404e9de108a4a1b470b75d5338195c9bf1d3505d00e1fee901f3119c6d755
@@ -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,113 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.8.0
6
+
7
+ ### Changed
8
+
9
+ - Add class attributes to ins element: `.ins.ins-before` or `.ins.ins-after`.
10
+
11
+ ### Fixed
12
+
13
+ - Fix issue on insertion and deletion on same position.
14
+ - Fix issue with long sentences.
15
+
16
+ ## 0.7.0
17
+
18
+ ### Fixed
19
+
5
20
  - Fixed replaces shown wrongly.
6
21
 
7
22
  ## 0.6.3
8
23
 
24
+ ### Fixed
25
+
9
26
  - Support diff-lcs v1.4+.
10
27
 
11
28
  ## 0.6.2
12
29
 
30
+ ### Changed
31
+
13
32
  - Support tr.added and tr.deleted.
14
33
 
15
34
  ## 0.6.1
16
35
 
36
+ ### Changed
37
+
17
38
  - Fix patch order bug by making sort stable.
18
39
 
19
40
  ## 0.6.0
20
41
 
42
+ ### Changed
43
+
21
44
  - Add .del class to all del elements.
22
45
 
23
46
  ## 0.5.5
24
47
 
48
+ ### Fixed
49
+
25
50
  - Preserve classes on adding new class (e.g. .added).
26
51
 
27
52
  ## 0.5.4
28
53
 
54
+ ### Fixed
55
+
29
56
  - Fix bug on patch operations order.
30
57
 
31
58
  ## 0.5.3
32
59
 
60
+ ### Fixed
61
+
33
62
  - Fix bug on comparing nodes.
34
63
 
35
64
  ## 0.5.2
36
65
 
66
+ ### Fixed
67
+
37
68
  - Fix bug on comparing attributes and text nodes.
38
69
 
39
70
  ## 0.5.1
40
71
 
72
+ ### Fixed
73
+
41
74
  - Fix bug on text-diff operation.
42
75
 
43
76
  ## 0.5.0
44
77
 
78
+ ### Changed
79
+
45
80
  - Wrap changed nodes by div.changed.
46
81
 
47
82
  ## 0.4.0
48
83
 
84
+ ### Changed
85
+
49
86
  - Chanage .changed specs.
87
+
88
+ ### Fixed
89
+
50
90
  - Fix bugs on text diff.
51
91
 
52
92
  ## 0.3.0
53
93
 
94
+ ### Changed
95
+
54
96
  - Support partial text diff.
55
97
 
56
98
  ## 0.2.1
57
99
 
100
+ ### Changed
101
+
58
102
  - Support li.added and li.removed.
59
103
 
60
104
  ## 0.2.0
61
105
 
106
+ ### Changed
107
+
62
108
  - Support div.changed and li.changed.
63
109
 
64
110
  ## 0.1.0
65
111
 
112
+ ### Added
113
+
66
114
  - 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.0)
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.14.2-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.6.2)
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
@@ -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.0"
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.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-29 00:00:00.000000000 Z
11
+ date: 2023-03-09 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
@@ -94,7 +94,7 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- description:
97
+ description:
98
98
  email:
99
99
  - r7kamura@gmail.com
100
100
  executables: []
@@ -127,7 +127,7 @@ homepage: https://github.com/r7kamura/markdiff
127
127
  licenses:
128
128
  - MIT
129
129
  metadata: {}
130
- post_install_message:
130
+ post_install_message:
131
131
  rdoc_options: []
132
132
  require_paths:
133
133
  - lib
@@ -142,8 +142,8 @@ 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
146
- signing_key:
145
+ rubygems_version: 3.3.26
146
+ signing_key:
147
147
  specification_version: 4
148
148
  summary: Rendered Markdown differ.
149
149
  test_files: []