html-pipeline 2.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +3 -0
- data/lib/html/pipeline.rb +1 -0
- data/lib/html/pipeline/emoji_filter.rb +6 -2
- data/lib/html/pipeline/image_filter.rb +17 -0
- data/lib/html/pipeline/sanitization_filter.rb +6 -3
- data/lib/html/pipeline/version.rb +1 -1
- data/script/changelog +27 -10
- data/test/html/pipeline/image_filter_test.rb +39 -0
- data/test/html/pipeline/sanitization_filter_test.rb +12 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef883e1a02e6690f3f708437f0750d38be6e26a7
|
4
|
+
data.tar.gz: c821156250cf94cbbf7a5d219bb6d10b3df77dbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 066dbba5d1a4c96b94a4eab74f0e6e1f81156362e05dec76e1b798489a8bdfb87db150bbe093b4c9e11cddc791a483d1bfbcc3ef2d0e43dec4df6f8d96b57f2c
|
7
|
+
data.tar.gz: 14e260bd46d314003cfd680d87f59660b584911e6646890a437afdfcf5e384f25bc06004d681886d3ae249ef3ff20ed8ddfc377e86ec5bfc0a4a5f585993d17a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 2.1.0
|
4
|
+
|
5
|
+
* Whitelist schemes for longdesc [#221](https://github.com/jch/html-pipeline/pull/221)
|
6
|
+
* Extract emoji image tag generation to own method [#195](https://github.com/jch/html-pipeline/pull/195)
|
7
|
+
* Update README.md [#211](https://github.com/jch/html-pipeline/pull/211)
|
8
|
+
* Add ImageFilter for image url to img tag conversion [#207](https://github.com/jch/html-pipeline/pull/207)
|
9
|
+
|
3
10
|
## 2.0
|
4
11
|
|
5
12
|
**New**
|
data/README.md
CHANGED
@@ -245,6 +245,9 @@ Here are some extensions people have built:
|
|
245
245
|
* [html-pipeline-rouge_filter](https://github.com/JuanitoFatas/html-pipeline-rouge_filter) - Syntax highlight with [Rouge](https://github.com/jneen/rouge/)
|
246
246
|
* [html-pipeline-nico_link](https://github.com/rutan/html-pipeline-nico_link) - An HTML::Pipeline filter for [niconico](http://www.nicovideo.jp) description links
|
247
247
|
* [html-pipeline-gitlab](https://gitlab.com/gitlab-org/html-pipeline-gitlab) - This gem implements various filters for html-pipeline used by GitLab
|
248
|
+
* [html-pipeline-youtube](https://github.com/st0012/html-pipeline-youtube) - An HTML::Pipeline filter for YouTube links
|
249
|
+
* [html-pipeline-flickr](https://github.com/st0012/html-pipeline-flickr) - An HTML::Pipeline filter for Flickr links
|
250
|
+
* [html-pipeline-vimeo](https://github.com/dlackty/html-pipeline-vimeo) - An HTML::Pipeline filter for Vimeo links
|
248
251
|
|
249
252
|
## Instrumenting
|
250
253
|
|
data/lib/html/pipeline.rb
CHANGED
@@ -32,6 +32,7 @@ module HTML
|
|
32
32
|
autoload :EmailReplyFilter, 'html/pipeline/email_reply_filter'
|
33
33
|
autoload :EmojiFilter, 'html/pipeline/emoji_filter'
|
34
34
|
autoload :HttpsFilter, 'html/pipeline/https_filter'
|
35
|
+
autoload :ImageFilter, 'html/pipeline/image_filter'
|
35
36
|
autoload :ImageMaxWidthFilter, 'html/pipeline/image_max_width_filter'
|
36
37
|
autoload :MarkdownFilter, 'html/pipeline/markdown_filter'
|
37
38
|
autoload :MentionFilter, 'html/pipeline/@mention_filter'
|
@@ -43,8 +43,7 @@ module HTML
|
|
43
43
|
# Returns a String with :emoji: replaced with images.
|
44
44
|
def emoji_image_filter(text)
|
45
45
|
text.gsub(emoji_pattern) do |match|
|
46
|
-
|
47
|
-
"<img class='emoji' title=':#{name}:' alt=':#{name}:' src='#{emoji_url(name)}' height='20' width='20' align='absmiddle' />"
|
46
|
+
emoji_image_tag($1)
|
48
47
|
end
|
49
48
|
end
|
50
49
|
|
@@ -70,6 +69,11 @@ module HTML
|
|
70
69
|
|
71
70
|
private
|
72
71
|
|
72
|
+
# Build an emoji image tag
|
73
|
+
def emoji_image_tag(name)
|
74
|
+
"<img class='emoji' title=':#{name}:' alt=':#{name}:' src='#{emoji_url(name)}' height='20' width='20' align='absmiddle' />"
|
75
|
+
end
|
76
|
+
|
73
77
|
def emoji_url(name)
|
74
78
|
File.join(asset_root, asset_path(name))
|
75
79
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module HTML
|
2
|
+
class Pipeline
|
3
|
+
# HTML Filter that converts image's url into <img> tag.
|
4
|
+
# For example, it will convert
|
5
|
+
# http://example.com/test.jpg
|
6
|
+
# into
|
7
|
+
# <img src="http://example.com/test.jpg" alt=""/>.
|
8
|
+
|
9
|
+
class ImageFilter < TextFilter
|
10
|
+
def call
|
11
|
+
@text.gsub(/(https|http)?:\/\/.+\.(jpg|jpeg|bmp|gif|png)(\?\S+)?/i) do |match|
|
12
|
+
%|<img src="#{match}" alt=""/>|
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -50,7 +50,7 @@ module HTML
|
|
50
50
|
:remove_contents => ['script'],
|
51
51
|
:attributes => {
|
52
52
|
'a' => ['href'],
|
53
|
-
'img' => ['src'],
|
53
|
+
'img' => ['src', 'longdesc'],
|
54
54
|
'div' => ['itemscope', 'itemtype'],
|
55
55
|
:all => ['abbr', 'accept', 'accept-charset',
|
56
56
|
'accesskey', 'action', 'align', 'alt', 'axis',
|
@@ -61,7 +61,7 @@ module HTML
|
|
61
61
|
'disabled', 'enctype', 'for', 'frame',
|
62
62
|
'headers', 'height', 'hreflang',
|
63
63
|
'hspace', 'ismap', 'label', 'lang',
|
64
|
-
'
|
64
|
+
'maxlength', 'media', 'method',
|
65
65
|
'multiple', 'name', 'nohref', 'noshade',
|
66
66
|
'nowrap', 'open', 'prompt', 'readonly', 'rel', 'rev',
|
67
67
|
'rows', 'rowspan', 'rules', 'scope',
|
@@ -72,7 +72,10 @@ module HTML
|
|
72
72
|
},
|
73
73
|
:protocols => {
|
74
74
|
'a' => {'href' => ANCHOR_SCHEMES},
|
75
|
-
'img' => {
|
75
|
+
'img' => {
|
76
|
+
'src' => ['http', 'https', :relative],
|
77
|
+
'longdesc' => ['http', 'https', :relative]
|
78
|
+
}
|
76
79
|
},
|
77
80
|
:transformers => [
|
78
81
|
# Top-level <li> elements are removed because they can break out of
|
data/script/changelog
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#!/
|
1
|
+
#!/bin/bash
|
2
2
|
# Usage: script/changelog [-r <repo>] [-b <base>] [-h <head>]
|
3
3
|
#
|
4
4
|
# repo: base string of GitHub repository url. e.g. "user_or_org/repository". Defaults to git remote url.
|
@@ -8,23 +8,40 @@
|
|
8
8
|
# Generate a changelog preview from pull requests merged between `base` and
|
9
9
|
# `head`.
|
10
10
|
#
|
11
|
-
# https://github.com/jch/release-scripts
|
11
|
+
# https://github.com/jch/release-scripts/blob/master/changelog
|
12
12
|
set -e
|
13
13
|
|
14
14
|
[ $# -eq 0 ] && set -- --help
|
15
|
+
while [[ $# > 1 ]]
|
16
|
+
do
|
17
|
+
key="$1"
|
18
|
+
case $key in
|
19
|
+
-r|--repo)
|
20
|
+
repo="$2"
|
21
|
+
shift
|
22
|
+
;;
|
23
|
+
-b|--base)
|
24
|
+
base="$2"
|
25
|
+
shift
|
26
|
+
;;
|
27
|
+
-h|--head)
|
28
|
+
head="$2"
|
29
|
+
shift
|
30
|
+
;;
|
31
|
+
*)
|
32
|
+
;;
|
33
|
+
esac
|
34
|
+
shift
|
35
|
+
done
|
15
36
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
head="HEAD"
|
37
|
+
repo="${repo:-$(git remote -v | grep push | awk '{print $2}' | cut -d'/' -f4- | sed 's/\.git//')}"
|
38
|
+
base="${base:-$(git tag -l | sort -t. -k 1,1n -k 2,2n -k 3,3n | tail -n 1)}"
|
39
|
+
head="${head:-HEAD}"
|
20
40
|
api_url="https://api.github.com"
|
21
41
|
|
22
|
-
echo "# $repo $base..$head"
|
23
|
-
echo
|
24
|
-
|
25
42
|
# get merged PR's. Better way is to query the API for these, but this is easier
|
26
43
|
for pr in $(git log --oneline $base..$head | grep "Merge pull request" | awk '{gsub("#",""); print $5}')
|
27
44
|
do
|
28
45
|
# frustrated with trying to pull out the right values, fell back to ruby
|
29
|
-
curl -s "$api_url/repos/$repo/pulls/$pr" | ruby -rjson -e 'pr=JSON.parse(STDIN.read); puts "* #{pr[%q(title)]} [##{pr[%q(number)]}](#{pr[%q(html_url)]})
|
46
|
+
curl -s "$api_url/repos/$repo/pulls/$pr" | ruby -rjson -e 'pr=JSON.parse(STDIN.read); puts "* #{pr[%q(title)]} [##{pr[%q(number)]}](#{pr[%q(html_url)]})"'
|
30
47
|
done
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
ImageFilter = HTML::Pipeline::ImageFilter
|
4
|
+
|
5
|
+
class HTML::Pipeline::ImageFilterTest < Minitest::Test
|
6
|
+
def filter(html)
|
7
|
+
ImageFilter.to_html(html)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_jpg
|
11
|
+
assert_equal %(<img src="http://example.com/test.jpg" alt=""/>),
|
12
|
+
filter(%(http://example.com/test.jpg))
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_jpeg
|
16
|
+
assert_equal %(<img src="http://example.com/test.jpeg" alt=""/>),
|
17
|
+
filter(%(http://example.com/test.jpeg))
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_bmp
|
21
|
+
assert_equal %(<img src="http://example.com/test.bmp" alt=""/>),
|
22
|
+
filter(%(http://example.com/test.bmp))
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_gif
|
26
|
+
assert_equal %(<img src="http://example.com/test.gif" alt=""/>),
|
27
|
+
filter(%(http://example.com/test.gif))
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_png
|
31
|
+
assert_equal %(<img src="http://example.com/test.png" alt=""/>),
|
32
|
+
filter(%(http://example.com/test.png))
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_https_url
|
36
|
+
assert_equal %(<img src="https://example.com/test.png" alt=""/>),
|
37
|
+
filter(%(https://example.com/test.png))
|
38
|
+
end
|
39
|
+
end
|
@@ -51,6 +51,18 @@ class HTML::Pipeline::SanitizationFilterTest < Minitest::Test
|
|
51
51
|
assert_equal '<a>Wat</a> is this', html
|
52
52
|
end
|
53
53
|
|
54
|
+
def test_whitelisted_longdesc_schemes_are_allowed
|
55
|
+
stuff = '<img src="./foo.jpg" longdesc="http://longdesc.com">'
|
56
|
+
html = SanitizationFilter.call(stuff).to_s
|
57
|
+
assert_equal '<img src="./foo.jpg" longdesc="http://longdesc.com">', html
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_weird_longdesc_schemes_are_removed
|
61
|
+
stuff = '<img src="./foo.jpg" longdesc="javascript:alert(1)">'
|
62
|
+
html = SanitizationFilter.call(stuff).to_s
|
63
|
+
assert_equal '<img src="./foo.jpg">', html
|
64
|
+
end
|
65
|
+
|
54
66
|
def test_standard_schemes_are_removed_if_not_specified_in_anchor_schemes
|
55
67
|
stuff = '<a href="http://www.example.com/">No href for you</a>'
|
56
68
|
filter = SanitizationFilter.new(stuff, {:anchor_schemes => []})
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html-pipeline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Tomayko
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-09-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- lib/html/pipeline/emoji_filter.rb
|
80
80
|
- lib/html/pipeline/filter.rb
|
81
81
|
- lib/html/pipeline/https_filter.rb
|
82
|
+
- lib/html/pipeline/image_filter.rb
|
82
83
|
- lib/html/pipeline/image_max_width_filter.rb
|
83
84
|
- lib/html/pipeline/markdown_filter.rb
|
84
85
|
- lib/html/pipeline/plain_text_input_filter.rb
|
@@ -97,6 +98,7 @@ files:
|
|
97
98
|
- test/html/pipeline/camo_filter_test.rb
|
98
99
|
- test/html/pipeline/emoji_filter_test.rb
|
99
100
|
- test/html/pipeline/https_filter_test.rb
|
101
|
+
- test/html/pipeline/image_filter_test.rb
|
100
102
|
- test/html/pipeline/image_max_width_filter_test.rb
|
101
103
|
- test/html/pipeline/markdown_filter_test.rb
|
102
104
|
- test/html/pipeline/mention_filter_test.rb
|
@@ -132,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
134
|
version: '0'
|
133
135
|
requirements: []
|
134
136
|
rubyforge_project:
|
135
|
-
rubygems_version: 2.
|
137
|
+
rubygems_version: 2.2.3
|
136
138
|
signing_key:
|
137
139
|
specification_version: 4
|
138
140
|
summary: Helpers for processing content through a chain of filters
|
@@ -143,6 +145,7 @@ test_files:
|
|
143
145
|
- test/html/pipeline/camo_filter_test.rb
|
144
146
|
- test/html/pipeline/emoji_filter_test.rb
|
145
147
|
- test/html/pipeline/https_filter_test.rb
|
148
|
+
- test/html/pipeline/image_filter_test.rb
|
146
149
|
- test/html/pipeline/image_max_width_filter_test.rb
|
147
150
|
- test/html/pipeline/markdown_filter_test.rb
|
148
151
|
- test/html/pipeline/mention_filter_test.rb
|