hparser 0.4.2 → 0.4.3

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
2
  SHA1:
3
- metadata.gz: e0e9c4a8998be7369d61c61260b30bda66092a2f
4
- data.tar.gz: 4d466fc8d360d45fabf4ab2b9a10875271b92a47
3
+ metadata.gz: 66dc4ee0fd999bad870fd9f26d61d9055da7516e
4
+ data.tar.gz: 7dc748fef818067722c1cf438bbe25aa6e0278ce
5
5
  SHA512:
6
- metadata.gz: e4f17441160d92e13b3c67a54014c3febc56ea9e83275061bc7d09b69f5a703269741044f9c3b45adda8bfeb0bdf7dcda999a4248304742156bf1611c7a5e21a
7
- data.tar.gz: b8924948ed9c896b96158bab7c8bc8d49140983555c8bb45ad6f812d4b4c482a16fea512e516bdaf2be8a3750b7b9eb1235d45723de6aed4e46f2705457f9965
6
+ metadata.gz: 5b6a6bb3892c0ae65cea9fbb455c4b94b3f913984254cb6f87049d33d91e6db2a48f662d41b91a0ecd730fb701fd7f7b98876c879381b66d77988f5f54e2b95d
7
+ data.tar.gz: c2085b5618fb7a6ceca5b3f0b95d5ff1df1d16f5133802c70586283d1f8cb27c3eff1819851aca0a702d5d6e81a0b71ffce379b8d7e740dfc7adf29eca8d146e
data/.travis.yml CHANGED
@@ -1,3 +1,5 @@
1
+ before_install:
2
+ - gem install bundler
1
3
  rvm:
2
4
  - 1.8.7
3
5
  - 1.9.3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.2
1
+ 0.4.3
data/hparser.gemspec CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.require_paths = ['lib']
17
17
 
18
18
  gem.add_development_dependency "rake", ">= 0.9.2"
19
+ gem.add_development_dependency "test-unit", "1.2.3" # for ruby 1.8
19
20
  gem.add_development_dependency "pry"
20
21
  end
21
22
 
data/lib/hparser/html.rb CHANGED
@@ -4,6 +4,8 @@
4
4
  # This file define +to_html+. +to_html+ is convert hatena format to html.
5
5
  #
6
6
 
7
+ require 'cgi'
8
+
7
9
  module HParser
8
10
  # This module provide +to_html+ method.
9
11
  # This method is intended to convert hatena format to html format.
@@ -39,15 +41,8 @@ module HParser
39
41
  %(<#{html_tag}>#{content}</#{html_tag}>)
40
42
  end
41
43
 
42
- ESCAPE_TABLE = {
43
- '&' => '&amp;',
44
- '"' => '&quot;',
45
- '<' => '&lt;',
46
- '>' => '&gt;'
47
- }
48
-
49
44
  def escape(str)
50
- str.gsub(/[&"<>]/n) {|c| ESCAPE_TABLE[c] }
45
+ CGI.escapeHTML(str)
51
46
  end
52
47
  end
53
48
 
@@ -284,22 +279,26 @@ module HParser
284
279
 
285
280
  module Inline
286
281
  class Text
282
+ include Html
287
283
  def to_html
288
- self.text
284
+ # escape < > & " except for HTML tag and HTML entity
285
+ tag_regex = /(<\/?[a-z]+(?:\s[^>]+)?\/?>|&#\d+;|&#x[0-9a-z]+;|&[a-z]+;)/i
286
+ self.text.split(tag_regex).map {|e|
287
+ e.match(tag_regex) ? e : escape(e)
288
+ }.join
289
289
  end
290
290
  end
291
291
 
292
292
  class Url
293
293
  include Html
294
- require "cgi"
295
294
  def to_html
296
295
  if @bookmark then
297
296
  require 'uri'
298
- enc_url = URI.encode(url)
297
+ enc_url = escape(URI.encode(url))
299
298
  bookmark = %( <a href="http://b.hatena.ne.jp/entry/#{enc_url}" class="http-bookmark">) +
300
299
  %(<img src="http://b.hatena.ne.jp/entry/image/#{enc_url}" alt="" class="http-bookmark"></a>)
301
300
  end
302
- %(<a href="#{self.url}">#{CGI.escapeHTML(self.title)}</a>#{bookmark})
301
+ %(<a href="#{escape(self.url)}">#{escape(self.title)}</a>#{bookmark})
303
302
  end
304
303
  end
305
304
 
@@ -329,10 +328,10 @@ module HParser
329
328
  end
330
329
 
331
330
  class Tex
331
+ include Html
332
332
  def to_html
333
- require "cgi"
334
333
  url = "http://chart.apis.google.com/chart?cht=tx&chf=bg,s,00000000&chl=" + CGI.escape(self.text)
335
- %(<img src="#{url}" class="tex" alt="#{CGI.escapeHTML(self.text)}">)
334
+ %(<img src="#{escape(url)}" class="tex" alt="#{escape(self.text)}">)
336
335
  end
337
336
  end
338
337
 
@@ -27,6 +27,10 @@ class HtmlInlineTest < Test::Unit::TestCase
27
27
  assert_same '<img src="http://example.com/" />'
28
28
  assert_same '<iframe src="http://example.com/"></iframe>'
29
29
  assert_same '<a href="http://example.com/"></a>'
30
+ assert_same '<br/>'
31
+ assert_same 'a &amp; &#39;b&#x3a;'
32
+ assert_html 'a &lt; &quot;b&quot; <img src="http://example.com/"/> c &lt;&gt; d',
33
+ 'a < "b" <img src="http://example.com/"/> c <> d'
30
34
  end
31
35
 
32
36
  def test_id
@@ -40,14 +44,16 @@ class HtmlInlineTest < Test::Unit::TestCase
40
44
  def test_url
41
45
  assert_html '<a href="http://mzp.sakura.ne.jp">http://mzp.sakura.ne.jp</a>',
42
46
  'http://mzp.sakura.ne.jp'
47
+ assert_html '<a href="http://example.com/?a=b&amp;c=d">http://example.com/?a=b&amp;c=d</a>',
48
+ 'http://example.com/?a=b&c=d'
43
49
  assert_html '<a href="http://example.com/">TITLE</a>',
44
50
  '[http://example.com/:title=TITLE]'
45
51
  assert_html '<a href="http://example.com/">A&amp;B</a>',
46
52
  '[http://example.com/:title=A&B]'
47
- assert_html '<a href="http://example.com/#a">TITLE</a> ' +
48
- '<a href="http://b.hatena.ne.jp/entry/http://example.com/%23a" class="http-bookmark">' +
49
- '<img src="http://b.hatena.ne.jp/entry/image/http://example.com/%23a" alt="" class="http-bookmark"></a>',
50
- '[http://example.com/#a:title=TITLE:bookmark]'
53
+ assert_html '<a href="http://example.com/?a=b&amp;c=d#a">TITLE</a> ' +
54
+ '<a href="http://b.hatena.ne.jp/entry/http://example.com/?a=b&amp;c=d%23a" class="http-bookmark">' +
55
+ '<img src="http://b.hatena.ne.jp/entry/image/http://example.com/?a=b&amp;c=d%23a" alt="" class="http-bookmark"></a>',
56
+ '[http://example.com/?a=b&c=d#a:title=TITLE:bookmark]'
51
57
  end
52
58
 
53
59
  def test_fotolife
@@ -57,7 +63,7 @@ class HtmlInlineTest < Test::Unit::TestCase
57
63
  end
58
64
 
59
65
  def test_tex
60
- assert_html '<img src="http://chart.apis.google.com/chart?cht=tx&chf=bg,s,00000000&chl=e%5E%7Bi%5Cpi%7D+%3D+-1"' +
66
+ assert_html '<img src="http://chart.apis.google.com/chart?cht=tx&amp;chf=bg,s,00000000&amp;chl=e%5E%7Bi%5Cpi%7D+%3D+-1"' +
61
67
  ' class="tex" alt="e^{i\pi} = -1">',
62
68
  '[tex:e^{i\pi} = -1]'
63
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - HIROKI Mizuno
@@ -10,34 +10,48 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-10-29 00:00:00.000000000 Z
13
+ date: 2015-12-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - ">="
19
+ - - '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: 0.9.2
22
22
  type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - ">="
26
+ - - '>='
27
27
  - !ruby/object:Gem::Version
28
28
  version: 0.9.2
29
+ - !ruby/object:Gem::Dependency
30
+ name: test-unit
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - '='
34
+ - !ruby/object:Gem::Version
35
+ version: 1.2.3
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '='
41
+ - !ruby/object:Gem::Version
42
+ version: 1.2.3
29
43
  - !ruby/object:Gem::Dependency
30
44
  name: pry
31
45
  requirement: !ruby/object:Gem::Requirement
32
46
  requirements:
33
- - - ">="
47
+ - - '>='
34
48
  - !ruby/object:Gem::Version
35
49
  version: '0'
36
50
  type: :development
37
51
  prerelease: false
38
52
  version_requirements: !ruby/object:Gem::Requirement
39
53
  requirements:
40
- - - ">="
54
+ - - '>='
41
55
  - !ruby/object:Gem::Version
42
56
  version: '0'
43
57
  description: Hatena Syntax parser for Ruby
@@ -46,8 +60,8 @@ executables: []
46
60
  extensions: []
47
61
  extra_rdoc_files: []
48
62
  files:
49
- - ".gitignore"
50
- - ".travis.yml"
63
+ - .gitignore
64
+ - .travis.yml
51
65
  - ChangeLog
52
66
  - Gemfile
53
67
  - README.rdoc
@@ -122,45 +136,18 @@ require_paths:
122
136
  - lib
123
137
  required_ruby_version: !ruby/object:Gem::Requirement
124
138
  requirements:
125
- - - ">="
139
+ - - '>='
126
140
  - !ruby/object:Gem::Version
127
141
  version: '0'
128
142
  required_rubygems_version: !ruby/object:Gem::Requirement
129
143
  requirements:
130
- - - ">="
144
+ - - '>='
131
145
  - !ruby/object:Gem::Version
132
146
  version: '0'
133
147
  requirements: []
134
148
  rubyforge_project:
135
- rubygems_version: 2.4.5.1
149
+ rubygems_version: 2.0.3
136
150
  signing_key:
137
151
  specification_version: 4
138
152
  summary: Hatena Syntax parser for Ruby
139
- test_files:
140
- - test/integration_texts/error1.ok.hatena
141
- - test/test_block.rb
142
- - test/test_bruteforce.rb
143
- - test/test_dl.rb
144
- - test/test_footnote.rb
145
- - test/test_fotolife.rb
146
- - test/test_from_perl/01_module.t
147
- - test/test_from_perl/02_module_extend.t
148
- - test/test_from_perl/10_autolink.t
149
- - test/test_from_perl/11_autolink_extend.t
150
- - test/test_hatena.rb
151
- - test/test_head.rb
152
- - test/test_helper.rb
153
- - test/test_html.rb
154
- - test/test_id.rb
155
- - test/test_inline.rb
156
- - test/test_inline_html.rb
157
- - test/test_integration.rb
158
- - test/test_latex.rb
159
- - test/test_p.rb
160
- - test/test_pair.rb
161
- - test/test_quote.rb
162
- - test/test_see_more.rb
163
- - test/test_table.rb
164
- - test/test_tex.rb
165
- - test/test_text.rb
166
- - test/test_url.rb
153
+ test_files: []