markdiff 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +2 -2
- data/Rakefile +4 -0
- data/lib/markdiff/differ.rb +28 -0
- data/lib/markdiff/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b3010fbe85faa7a63e166ffe7d18c45007f01a3
|
4
|
+
data.tar.gz: b1a4af8e050c517e9017e60539f3ccb946f394e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6012e20cb4d9129e710c4f49c88cdfe652b8a1951c8b07425433745bead2d49dc58d58c3a251a4042e11c9ef24c2788bee4beb81b705b17f6a6cfeaca737699f
|
7
|
+
data.tar.gz: aab0e79a022a104345388c5f79d378a6affa4774f92ee7aad69abb4211058449d454b0399ee52d49c75216c2bf5844653cdc592abc9a17405bb697edaa7ecb1a
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Markdiff
|
1
|
+
# Markdiff [![Build Status](https://travis-ci.org/r7kamura/markdiff.svg)](https://travis-ci.org/r7kamura/markdiff)
|
2
2
|
Rendered Markdown differ.
|
3
3
|
|
4
4
|
## Usage
|
@@ -7,7 +7,7 @@ require "markdiff"
|
|
7
7
|
|
8
8
|
differ = Markdiff::Differ.new
|
9
9
|
node = differ.render("<p>a</p>", "<p>b</p>")
|
10
|
-
node.to_html #=> "
|
10
|
+
node.to_html #=> '<div class="changed"><p><del>a</del><ins>b</ins></p></div>'
|
11
11
|
```
|
12
12
|
|
13
13
|
See [spec/markdiff/differ_spec.rb](spec/markdiff/differ_spec.rb) for more examples.
|
data/Rakefile
CHANGED
data/lib/markdiff/differ.rb
CHANGED
@@ -16,16 +16,26 @@ module Markdiff
|
|
16
16
|
case operation
|
17
17
|
when ::Markdiff::Operations::AddChildOperation
|
18
18
|
operation.target_node.add_child(operation.inserted_node)
|
19
|
+
mark_li_as_changed(operation.target_node)
|
20
|
+
mark_top_level_node_as_changed(operation.target_node)
|
19
21
|
when ::Markdiff::Operations::AddDataBeforeHrefOperation
|
20
22
|
operation.target_node["data-before-href"] = operation.target_node["href"]
|
21
23
|
operation.target_node["href"] = operation.after_href
|
24
|
+
mark_li_as_changed(operation.target_node)
|
25
|
+
mark_top_level_node_as_changed(operation.target_node)
|
22
26
|
when ::Markdiff::Operations::AddDataBeforeTagNameOperation
|
23
27
|
operation.target_node["data-before-tag-name"] = operation.target_node.name
|
24
28
|
operation.target_node.name = operation.after_tag_name
|
29
|
+
mark_li_as_changed(operation.target_node)
|
30
|
+
mark_top_level_node_as_changed(operation.target_node)
|
25
31
|
when ::Markdiff::Operations::AddPreviousSiblingOperation
|
26
32
|
operation.target_node.add_previous_sibling(operation.inserted_node)
|
33
|
+
mark_li_as_changed(operation.target_node)
|
34
|
+
mark_top_level_node_as_changed(operation.target_node.parent)
|
27
35
|
when ::Markdiff::Operations::RemoveOperation
|
28
36
|
operation.target_node.replace(operation.inserted_node)
|
37
|
+
mark_li_as_changed(operation.target_node)
|
38
|
+
mark_top_level_node_as_changed(operation.target_node)
|
29
39
|
end
|
30
40
|
end
|
31
41
|
node
|
@@ -153,5 +163,23 @@ module Markdiff
|
|
153
163
|
before_node["href"] != after_node["href"] &&
|
154
164
|
before_node.inner_html == after_node.inner_html
|
155
165
|
end
|
166
|
+
|
167
|
+
# @param [Nokogiri::XML::Node] node
|
168
|
+
def mark_li_as_changed(node)
|
169
|
+
until node.parent.nil? || node.parent.fragment?
|
170
|
+
if node.name == "li" && node["class"] != "changed"
|
171
|
+
node["class"] = "changed"
|
172
|
+
end
|
173
|
+
node = node.parent
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
# @param [Nokogiri::XML::Node] node
|
178
|
+
def mark_top_level_node_as_changed(node)
|
179
|
+
node = node.parent until node.parent.nil? || node.parent.fragment?
|
180
|
+
unless node.name == "div" && node["class"] == "changed"
|
181
|
+
node.replace(%(<div class="changed">#{node}</div>))
|
182
|
+
end
|
183
|
+
end
|
156
184
|
end
|
157
185
|
end
|
data/lib/markdiff/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: markdiff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
@@ -89,6 +89,7 @@ extra_rdoc_files: []
|
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
91
|
- ".travis.yml"
|
92
|
+
- CHANGELOG.md
|
92
93
|
- Gemfile
|
93
94
|
- LICENSE.txt
|
94
95
|
- README.md
|