markdiff 0.6.0 → 0.7.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
- SHA1:
3
- metadata.gz: f2346464a728f27b53d6e41867c54f6fc98be7b3
4
- data.tar.gz: 39a6911a132f9fdf92d55fe0de403148670c14af
2
+ SHA256:
3
+ metadata.gz: f86c8ef911af47d5d4271365f2a576564b2425424f1bedc8fc66cda39186ce3a
4
+ data.tar.gz: 7c059f14e29a4b0496b9412f481ced9f10d4742e43d3cab31ade9b85f551b7df
5
5
  SHA512:
6
- metadata.gz: d2ee80ab7bedc30ff0eff09a4cff8115fb7200e1433bc5cfb0330a64dafb28a10c351175a3268ee7c7d1115ef19b5df468a51c6837ba135d385ef870e5c27ee7
7
- data.tar.gz: 5ee096c2d67f82ea0434f9c925a821cdf2458bae9942f5c0c34d141a8460f5bb1292afbf7c5fee89246d9926382627140b50175bf01fa73f5a94fede09be563a
6
+ metadata.gz: aa74b28c0589094b03defb2ccfadbba23572530fca2ec07e1fe73f0e810dbc8eba019257a119ea929736ca54c04c3721960e74d41037b07395b92495dbad2736
7
+ data.tar.gz: 8a6a633604eaa4fdb221a779133adae4e4489e98258ef1e39e81b44c73d0fd3215b9d3bb6b1aceffb850517c21f3f2bc3ec7153f7d19e84367e0791e068c95c2
@@ -0,0 +1,22 @@
1
+ name: test
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches:
7
+ - master
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby:
15
+ - 2.7.2
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+ - uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: ${{ matrix.ruby }}
21
+ bundler-cache: true
22
+ - run: bundle exec rake
data/.gitignore CHANGED
@@ -1,6 +1,5 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
4
3
  /_yardoc/
5
4
  /coverage/
6
5
  /doc/
data/CHANGELOG.md CHANGED
@@ -1,36 +1,66 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ - Fixed replaces shown wrongly.
6
+
7
+ ## 0.6.3
8
+
9
+ - Support diff-lcs v1.4+.
10
+
11
+ ## 0.6.2
12
+
13
+ - Support tr.added and tr.deleted.
14
+
15
+ ## 0.6.1
16
+
17
+ - Fix patch order bug by making sort stable.
18
+
1
19
  ## 0.6.0
2
- - Add .del class to all del elements
20
+
21
+ - Add .del class to all del elements.
3
22
 
4
23
  ## 0.5.5
5
- - Preserve classes on adding new class (e.g. .added)
24
+
25
+ - Preserve classes on adding new class (e.g. .added).
6
26
 
7
27
  ## 0.5.4
8
- - Fix bug on patch operations order
28
+
29
+ - Fix bug on patch operations order.
9
30
 
10
31
  ## 0.5.3
11
- - Fix bug on comparing nodes
32
+
33
+ - Fix bug on comparing nodes.
12
34
 
13
35
  ## 0.5.2
14
- - Fix bug on comparing attributes and text nodes
36
+
37
+ - Fix bug on comparing attributes and text nodes.
15
38
 
16
39
  ## 0.5.1
17
- - Fix bug on text-diff operation
40
+
41
+ - Fix bug on text-diff operation.
18
42
 
19
43
  ## 0.5.0
20
- - Wrap changed nodes by div.changed
44
+
45
+ - Wrap changed nodes by div.changed.
21
46
 
22
47
  ## 0.4.0
23
- - Chanage .changed specs
24
- - Fix bugs on text diff
48
+
49
+ - Chanage .changed specs.
50
+ - Fix bugs on text diff.
25
51
 
26
52
  ## 0.3.0
27
- - Support partial text diff
53
+
54
+ - Support partial text diff.
28
55
 
29
56
  ## 0.2.1
30
- - Support li.added and li.removed
57
+
58
+ - Support li.added and li.removed.
31
59
 
32
60
  ## 0.2.0
33
- - Support div.changed and li.changed
61
+
62
+ - Support div.changed and li.changed.
34
63
 
35
64
  ## 0.1.0
36
- - 1st Release
65
+
66
+ - 1st Release.
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ markdiff (0.6.3)
5
+ diff-lcs
6
+ nokogiri
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ diff-lcs (1.5.0)
12
+ nokogiri (1.13.1-x86_64-linux)
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)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.4.0)
26
+ rspec-mocks (3.4.1)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.4.0)
29
+ rspec-support (3.4.1)
30
+
31
+ PLATFORMS
32
+ x86_64-linux
33
+
34
+ DEPENDENCIES
35
+ bundler
36
+ markdiff!
37
+ rake (~> 10.0)
38
+ redcarpet (= 3.3.3)
39
+ rspec (= 3.4.0)
40
+
41
+ BUNDLED WITH
42
+ 2.3.6
data/README.md CHANGED
@@ -1,4 +1,8 @@
1
- # Markdiff [![Build Status](https://travis-ci.org/r7kamura/markdiff.svg)](https://travis-ci.org/r7kamura/markdiff)
1
+ # Markdiff
2
+
3
+ [![test](https://github.com/r7kamura/markdiff/actions/workflows/test.yml/badge.svg)](https://github.com/r7kamura/markdiff/actions/workflows/test.yml)
4
+ [![Gem Version](https://badge.fury.io/rb/markdiff.svg)](https://rubygems.org/gems/markdiff)
5
+
2
6
  Rendered Markdown differ.
3
7
 
4
8
  ## Usage
@@ -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,9 +182,9 @@ 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"
187
+ if node.name == "li" || node.name == "tr"
187
188
  classes = node["class"].to_s.split(/\s/)
188
189
  unless classes.include?("added") || classes.include?("changed") || classes.include?("removed")
189
190
  node["class"] = (classes + ["changed"]).join(" ")
@@ -5,7 +5,7 @@ module Markdiff
5
5
  class AddChildOperation < 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
  @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
@@ -5,7 +5,7 @@ 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
10
  node["class"] = (node["class"].to_s.split(/\s/) + ["added"]).join(" ")
11
11
  node.inner_html = "<ins>#{@inserted_node.inner_html}</ins>"
@@ -5,7 +5,7 @@ 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
10
  target_node.inner_html = %(<del class="del">#{target_node.inner_html}</del>)
11
11
  target_node
@@ -15,14 +15,27 @@ 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
+ last_deleted_pos = nil
19
+
20
+ ::Diff::LCS.diff(before_elements, after_elements).flatten(1).each do |operation|
19
21
  type, position, element = *operation
22
+
20
23
  if type == "-"
21
24
  before_elements[position] = %(<del class="del">#{element}</del>)
25
+ last_deleted_pos = position
26
+ elsif type == "+"
27
+ insert = "<ins>#{element}</ins>"
28
+
29
+ if last_deleted_pos == position
30
+ before_elements[position] = "#{before_elements[position]}#{insert}"
31
+ else
32
+ before_elements[position] = "#{insert}#{before_elements[position]}"
33
+ end
22
34
  else
23
- before_elements[position] = "#{before_elements[position]}<ins>#{element}</ins>"
35
+ raise "Unhandled type: #{type}"
24
36
  end
25
37
  end
38
+
26
39
  ::Nokogiri::HTML.fragment(before_elements.join(" "))
27
40
  end
28
41
 
@@ -1,3 +1,3 @@
1
1
  module Markdiff
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
data/markdiff.gemspec CHANGED
@@ -13,8 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.start_with?("spec/") }
14
14
  spec.require_paths = ["lib"]
15
15
 
16
- spec.add_development_dependency "bundler", "~> 1.10"
17
- spec.add_development_dependency "pry", "0.10.3"
16
+ spec.add_development_dependency "bundler"
18
17
  spec.add_development_dependency "rake", "~> 10.0"
19
18
  spec.add_development_dependency "redcarpet", "3.3.3"
20
19
  spec.add_development_dependency "rspec", "3.4.0"
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdiff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
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: 2022-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.10'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.10'
27
- - !ruby/object:Gem::Dependency
28
- name: pry
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '='
17
+ - - ">="
32
18
  - !ruby/object:Gem::Version
33
- version: 0.10.3
19
+ version: '0'
34
20
  type: :development
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - '='
24
+ - - ">="
39
25
  - !ruby/object:Gem::Version
40
- version: 0.10.3
26
+ version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rake
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -115,10 +101,11 @@ executables: []
115
101
  extensions: []
116
102
  extra_rdoc_files: []
117
103
  files:
104
+ - ".github/workflows/test.yml"
118
105
  - ".gitignore"
119
- - ".travis.yml"
120
106
  - CHANGELOG.md
121
107
  - Gemfile
108
+ - Gemfile.lock
122
109
  - LICENSE.txt
123
110
  - README.md
124
111
  - Rakefile
@@ -155,10 +142,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
142
  - !ruby/object:Gem::Version
156
143
  version: '0'
157
144
  requirements: []
158
- rubyforge_project:
159
- rubygems_version: 2.4.5
145
+ rubygems_version: 3.1.4
160
146
  signing_key:
161
147
  specification_version: 4
162
148
  summary: Rendered Markdown differ.
163
149
  test_files: []
164
- has_rdoc:
data/.travis.yml DELETED
@@ -1,4 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.2.0
4
- before_install: gem install bundler -v 1.10.6