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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dad582795e7cd14b58107e3c533ecfc71503f4d2
4
- data.tar.gz: 71b248c82c33cb1d4ed0991531f79dec0fb58da2
3
+ metadata.gz: b721d419c467bda182458949f39695c1b732d9e8
4
+ data.tar.gz: c118f3700a68ef6fa62416a28032bbc13b94129d
5
5
  SHA512:
6
- metadata.gz: bf4eb1f65e95f3b94a6b76814f854ba2cda0ad59aed4ebff05232689009e5cad6cf10aa1b4704274b1fa7c62bde43a439c992a0804a4d6d23ce3751f8e57eda9
7
- data.tar.gz: 4c986a05888c0d05b48de4dcc726f1e3ff2fbaea6ca32447170d5cc197d8f45357431892081b6d65e1d4d6f7b958940ad89c69888df2f84e4941a2f315ecaaa8
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
- def call
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
- img['src'] = relative_path_from_document_root src unless http_uri? src
13
- end
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
- def relative_path_from_document_root(src)
19
- File.join(context[:original_document_root], src).to_s
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
@@ -1,3 +1,3 @@
1
1
  module Octodown
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
data/spec/dummy/test.md CHANGED
@@ -10,3 +10,5 @@ def some_code()
10
10
  puts 'Yeah, this is some code.'
11
11
  end
12
12
  ```
13
+
14
+ [some-file](test.txt)
@@ -35,4 +35,10 @@ describe Octodown::Renderer::GithubMarkdown do
35
35
  end
36
36
  end
37
37
  end
38
+
39
+ describe 'local file linking' do
40
+ it 'includes the local file from correct location' do
41
+ expect(html).to include '<a href="tmp/test.txt">some-file</a>'
42
+ end
43
+ end
38
44
  end
@@ -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?('assets/test.png')).to eq false
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?('http://foo.com/assets/test.png')).to eq true
12
- expect(subject.http_uri?('https://foo.com/assets/test.png')).to eq true
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
- ,����tn��+՞��OS<��U����u�dVQ�@{��)`�|7�E��x!�w����"�N�}�3i�9�r�uh��uҺU�_zt�� ���e�S����V:U&�@����SIRHLw#Ƴ:��2�y��5%�������f������Dzk�q��8���\G�Ewm(�G�;�7�m�)8����3��eG�#��)��d˛#�B��$��r�<��䁇>�K���%�-D)�U5(����]G
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.2
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-07 00:00:00.000000000 Z
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