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 +4 -4
- data/.travis.yml +2 -0
- data/VERSION +1 -1
- data/hparser.gemspec +1 -0
- data/lib/hparser/html.rb +13 -14
- data/test/test_inline_html.rb +11 -5
- metadata +26 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66dc4ee0fd999bad870fd9f26d61d9055da7516e
|
4
|
+
data.tar.gz: 7dc748fef818067722c1cf438bbe25aa6e0278ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b6a6bb3892c0ae65cea9fbb455c4b94b3f913984254cb6f87049d33d91e6db2a48f662d41b91a0ecd730fb701fd7f7b98876c879381b66d77988f5f54e2b95d
|
7
|
+
data.tar.gz: c2085b5618fb7a6ceca5b3f0b95d5ff1df1d16f5133802c70586283d1f8cb27c3eff1819851aca0a702d5d6e81a0b71ffce379b8d7e740dfc7adf29eca8d146e
|
data/.travis.yml
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.3
|
data/hparser.gemspec
CHANGED
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
|
-
'&' => '&',
|
44
|
-
'"' => '"',
|
45
|
-
'<' => '<',
|
46
|
-
'>' => '>'
|
47
|
-
}
|
48
|
-
|
49
44
|
def escape(str)
|
50
|
-
|
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
|
-
|
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}">#{
|
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="#{
|
334
|
+
%(<img src="#{escape(url)}" class="tex" alt="#{escape(self.text)}">)
|
336
335
|
end
|
337
336
|
end
|
338
337
|
|
data/test/test_inline_html.rb
CHANGED
@@ -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 & 'b:'
|
32
|
+
assert_html 'a < "b" <img src="http://example.com/"/> c <> 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&c=d">http://example.com/?a=b&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&B</a>',
|
46
52
|
'[http://example.com/:title=A&B]'
|
47
|
-
assert_html '<a href="http://example.com
|
48
|
-
'<a href="http://b.hatena.ne.jp/entry/http://example.com
|
49
|
-
'<img src="http://b.hatena.ne.jp/entry/image/http://example.com
|
50
|
-
'[http://example.com
|
53
|
+
assert_html '<a href="http://example.com/?a=b&c=d#a">TITLE</a> ' +
|
54
|
+
'<a href="http://b.hatena.ne.jp/entry/http://example.com/?a=b&c=d%23a" class="http-bookmark">' +
|
55
|
+
'<img src="http://b.hatena.ne.jp/entry/image/http://example.com/?a=b&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&chf=bg,s,00000000&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.
|
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-
|
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
|
-
-
|
50
|
-
-
|
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.
|
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: []
|