octodown 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +2 -2
- data/lib/octodown/support/relative_root_filter.rb +47 -10
- data/lib/octodown/version.rb +1 -1
- data/spec/dummy/test.md +2 -0
- data/spec/markdown_generation_spec.rb +6 -0
- data/spec/relative_root_filter_spec.rb +15 -3
- data.tar.gz.sig +2 -1
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b721d419c467bda182458949f39695c1b732d9e8
|
4
|
+
data.tar.gz: c118f3700a68ef6fa62416a28032bbc13b94129d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83597f2ebb4badd314fe9b5bb0671db01e5d673fdf363b1a0d7dd7145fe132f9bbf60d311db27bf1f74b9f82d64dde1c63bf744cc8fcfac6b5872812ee65401b
|
7
|
+
data.tar.gz: 297fd7ac4d5c7bf7ab649bee4b8c3137f977e88d0a72f2fd7f4e82c7030f341f3a5c36c146b5a1586834960c93adf200b5ab515f12406f656b06f0c4ee644d57
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -34,8 +34,8 @@ primary goal to reproduce it as faithfully as possible.
|
|
34
34
|
## Installation
|
35
35
|
|
36
36
|
1. Install `icu4c` and `cmake`:
|
37
|
-
- Mac: `brew install icu4c cmake`
|
38
|
-
- Apt: `sudo apt-get install -y libicu-dev cmake`
|
37
|
+
- Mac: `brew install icu4c cmake pkg-config`
|
38
|
+
- Apt: `sudo apt-get install -y libicu-dev cmake pkg-config`
|
39
39
|
|
40
40
|
2. Install octodown:
|
41
41
|
- If you have a non-system Ruby (_highly recommended_): `gem install
|
@@ -3,26 +3,63 @@ require 'uri'
|
|
3
3
|
module Octodown
|
4
4
|
module Support
|
5
5
|
class RelativeRootFilter < HTML::Pipeline::Filter
|
6
|
-
|
7
|
-
doc.search('img').each do |img|
|
8
|
-
next if img['src'].nil?
|
9
|
-
|
10
|
-
src = img['src'].strip
|
6
|
+
attr_accessor :root
|
11
7
|
|
12
|
-
|
13
|
-
|
8
|
+
def call
|
9
|
+
@root = context[:original_document_root]
|
14
10
|
|
15
|
-
doc
|
11
|
+
filter_images doc.search('img')
|
12
|
+
filter_links doc.search('a')
|
16
13
|
end
|
17
14
|
|
18
|
-
|
19
|
-
|
15
|
+
private
|
16
|
+
|
17
|
+
def relative_path_from_document_root(root, src)
|
18
|
+
File.join(root, src).to_s
|
20
19
|
end
|
21
20
|
|
22
21
|
def http_uri?(src)
|
23
22
|
parsed_uri = URI.parse src
|
24
23
|
parsed_uri.is_a? URI::HTTP
|
25
24
|
end
|
25
|
+
|
26
|
+
# TODO: These two methods are highly similar and can be refactored, but
|
27
|
+
# I'm can't find the right abstraction at the moment that isn't a total
|
28
|
+
# hack involving bizarre object references and mutation
|
29
|
+
|
30
|
+
def filter_images(images)
|
31
|
+
images.each do |img|
|
32
|
+
src = img['src']
|
33
|
+
|
34
|
+
next if src.nil?
|
35
|
+
|
36
|
+
src.strip!
|
37
|
+
|
38
|
+
unless http_uri? src
|
39
|
+
path = relative_path_from_document_root root, src
|
40
|
+
img['src'] = path
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
doc
|
45
|
+
end
|
46
|
+
|
47
|
+
def filter_links(links)
|
48
|
+
links.each do |a|
|
49
|
+
src = a.attributes['href'].value
|
50
|
+
|
51
|
+
next if src.nil?
|
52
|
+
|
53
|
+
src.strip!
|
54
|
+
|
55
|
+
unless http_uri? src
|
56
|
+
path = relative_path_from_document_root root, src
|
57
|
+
a.attributes['href'].value = path
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
doc
|
62
|
+
end
|
26
63
|
end
|
27
64
|
end
|
28
65
|
end
|
data/lib/octodown/version.rb
CHANGED
data/spec/dummy/test.md
CHANGED
@@ -3,12 +3,24 @@ require 'tempfile'
|
|
3
3
|
describe Octodown::Renderer::GithubMarkdown do
|
4
4
|
subject { Octodown::Support::RelativeRootFilter.new(nil) }
|
5
5
|
|
6
|
+
# Testing private methods because Nokogirl is a black box
|
6
7
|
it 'detects an non-HTTP/HTTPS URI correctly' do
|
7
|
-
expect(subject.http_uri
|
8
|
+
expect(subject.send(:http_uri?, 'assets/test.png')).to eq false
|
8
9
|
end
|
9
10
|
|
10
11
|
it 'detects HTTP/HTTPS URI correctly' do
|
11
|
-
expect(subject.http_uri
|
12
|
-
|
12
|
+
expect(subject.send(:http_uri?, 'http://foo.com/assets/test.png'))
|
13
|
+
.to eq true
|
14
|
+
expect(subject.send(:http_uri?, 'https://foo.com/assets/test.png'))
|
15
|
+
.to eq true
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'renders the relative root correctly' do
|
19
|
+
root = '/home/test'
|
20
|
+
src = 'dummy/test.md'
|
21
|
+
|
22
|
+
expect(subject.send(:relative_path_from_document_root, root, src)).to eq(
|
23
|
+
'/home/test/dummy/test.md'
|
24
|
+
)
|
13
25
|
end
|
14
26
|
end
|
data.tar.gz.sig
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
|
1
|
+
�S�{m
|
2
|
+
�Q�z��P�:v��}���*Q";H@��D�uEJ����5ܟoe��H��5֒�����a%���)����&5{�z���m�z��)Œ����Q�U�]d3��<7��W;"0~i��nQ��x�ҡ[*���0�z7���?Ǒ$[�y���T�����M'(�����xB
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: octodown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian Ker-Seymer
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
YGBeYMyEy7Q4wf7k4k5yyDUZyyaeg0DF/kNEN5llspJ9DHMP2cQqOiH+IQSNiUhR
|
31
31
|
32sJqaZRHeJLDhZPLi5yXItTsQnPy6uob2oyypwFYTM=
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2015-01-
|
33
|
+
date: 2015-01-14 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: github-markup
|
metadata.gz.sig
CHANGED
Binary file
|