devcenter-parser 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,7 @@ require 'sanitize'
6
6
 
7
7
  module DevcenterParser
8
8
 
9
- VERSION = '1.1.0'
9
+ VERSION = '1.2.0'
10
10
 
11
11
  AVAILABLE_FLAVOURS = [:github, :maruku]
12
12
 
@@ -38,6 +38,7 @@ module DevcenterParser
38
38
  else
39
39
  raise UnknownFlavourError, "Markdown flavour '#{flavour}' not supported"
40
40
  end
41
+ convert_to_article_links_all_relative_links_with_missing_initial_slashes(doc)
41
42
  html = doc.to_html(:encoding => 'utf-8')
42
43
  verify_raw_html(html)
43
44
  html
@@ -113,6 +114,14 @@ module DevcenterParser
113
114
  end
114
115
  end
115
116
 
117
+ def self.convert_to_article_links_all_relative_links_with_missing_initial_slashes(doc)
118
+ doc.css('a').each do |node|
119
+ unless node['href'] =~ /\Ahttp|\A\/|mailto\:/
120
+ node['href'] = "/articles/#{node['href']}"
121
+ end
122
+ end
123
+ end
124
+
116
125
  def self.verify_raw_html(html)
117
126
  raise(InvalidRawHTMLError, parse_raw_html_error(html)) if invalid_raw_html?(html)
118
127
  end
@@ -184,6 +184,24 @@ And that's it.
184
184
  assert_all_flavours_result(md, html)
185
185
  end
186
186
 
187
+ it 'converts relative links with missing initial slashes to article links' do
188
+ ['foo', 'foo/bar', 'foo#bar', '123'].each do |href|
189
+ md = "[link](#{href})"
190
+ html = "<p><a href=\"/articles/#{href}\">link</a></p>"
191
+ assert_maruku_result md, html
192
+ assert_github_result md, html
193
+ end
194
+ end
195
+
196
+ it 'does not alter relative links with initial slashes nor absolute links' do
197
+ ['http://foo.com', 'https://foo.com', '/foo', '/foo/bar', '/foo#bar', '/123', 'mailto:foo@foobar.com'].each do |href|
198
+ md = "[link](#{href})"
199
+ html = "<p><a href=\"#{href}\">link</a></p>"
200
+ assert_maruku_result md, html
201
+ assert_github_result md, html
202
+ end
203
+ end
204
+
187
205
  end
188
206
 
189
207
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devcenter-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-31 00:00:00.000000000 Z
12
+ date: 2013-06-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: maruku