convert 0.1.2 → 0.1.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/convert.gemspec +2 -2
- data/lib/convert.rb +15 -21
- data/lib/converters/auto_link.rb +16 -14
- data/lib/converters/dailymotion.rb +12 -10
- data/lib/converters/decode.rb +6 -4
- data/lib/converters/email_escape.rb +16 -14
- data/lib/converters/encode.rb +6 -4
- data/lib/converters/flickr.rb +16 -14
- data/lib/converters/gist.rb +12 -10
- data/lib/converters/google_maps.rb +30 -28
- data/lib/converters/hashtag.rb +11 -9
- data/lib/converters/html_escape.rb +9 -7
- data/lib/converters/iframe_embed.rb +8 -6
- data/lib/converters/image_tag.rb +8 -6
- data/lib/converters/instagram.rb +10 -8
- data/lib/converters/kramdown.rb +14 -12
- data/lib/converters/liveleak.rb +22 -20
- data/lib/converters/markdown.rb +16 -14
- data/lib/converters/metacafe.rb +23 -21
- data/lib/converters/nokogiri.rb +27 -25
- data/lib/converters/redcarpet.rb +8 -6
- data/lib/converters/sanitize.rb +10 -8
- data/lib/converters/simple_format.rb +8 -6
- data/lib/converters/soundcloud.rb +31 -29
- data/lib/converters/strip_params.rb +9 -7
- data/lib/converters/ted.rb +23 -21
- data/lib/converters/twitter.rb +15 -13
- data/lib/converters/unescape_html.rb +8 -6
- data/lib/converters/video_embed.rb +20 -18
- data/lib/converters/vimeo.rb +28 -26
- data/lib/converters/vimeo_embed.rb +8 -6
- data/lib/converters/worldstar.rb +14 -12
- data/lib/converters/youtube.rb +40 -38
- data/lib/converters/youtube_embed.rb +8 -6
- data/lib/converters/youtube_image.rb +30 -28
- data/lib/converters/youtube_js_api.rb +13 -11
- data/mod.rb +13 -0
- metadata +3 -3
- data/test.rb +0 -16
data/lib/converters/kramdown.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
def kramdown(string, options = {})
|
5
|
+
options = {
|
6
|
+
:auto_ids => false,
|
7
|
+
:entity_output => :as_char,
|
8
|
+
:enable_coderay => true,
|
9
|
+
:parse_block_html => true,
|
10
|
+
:parse_span_html => true,
|
11
|
+
:smart_quotes => ['apos', 'apos', 'quot', 'quot']
|
12
|
+
}.merge(options)
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
Kramdown::Document.new(string, options).to_html
|
15
|
+
end
|
15
16
|
|
17
|
+
end
|
16
18
|
end
|
data/lib/converters/liveleak.rb
CHANGED
@@ -1,28 +1,30 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
def liveleak(string, options = {})
|
5
|
+
options = {
|
6
|
+
:width => 420,
|
7
|
+
:height => 315,
|
8
|
+
:frameborder => 0,
|
9
|
+
:wmode => nil,
|
10
|
+
:autoplay => false,
|
11
|
+
:hide_related => false
|
12
|
+
}.merge(options)
|
12
13
|
|
13
|
-
|
14
|
+
@regex = %r{http://www\.liveleak\.com/(?:ll_embed|view)\?.=(\w+)}
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
string.gsub(@regex) do
|
17
|
+
a = []
|
18
|
+
a << "wmode=#{options[:wmode]}" if options[:wmode]
|
19
|
+
a << "autoplay=1" if options[:autoplay]
|
20
|
+
a << "rel=0" if options[:hide_related]
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
src = "http://www.liveleak.com/ll_embed?f=#{$1}"
|
23
|
+
src += "?#{a.join '&'}" unless a.empty?
|
23
24
|
|
24
|
-
|
25
|
+
%{<iframe width="#{options[:width]}" height="#{options[:height]}" src="#{src}" frameborder="#{options[:frameborder]}" allowfullscreen></iframe>}
|
26
|
+
end
|
25
27
|
end
|
26
|
-
end
|
27
28
|
|
29
|
+
end
|
28
30
|
end
|
data/lib/converters/markdown.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
# Converts the string into html
|
5
|
+
def markdown(string, options = {})
|
6
|
+
options = {
|
7
|
+
:autolink => true,
|
8
|
+
:fenced_code_blocks => true,
|
9
|
+
:disable_indented_code_blocks => true,
|
10
|
+
:no_intra_emphasis => true
|
11
|
+
}.merge(options)
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
Redcarpet::Markdown.new(
|
14
|
+
Redcarpet::Render::HTML.new(:filter_html => false, :hard_wrap => true),
|
15
|
+
options
|
16
|
+
).render(string)
|
17
|
+
end
|
17
18
|
|
19
|
+
end
|
18
20
|
end
|
data/lib/converters/metacafe.rb
CHANGED
@@ -1,28 +1,30 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
# Convert metacafe movie URL to embedded html
|
5
|
+
def metacafe(string, options = {})
|
6
|
+
# Original 440 272
|
7
|
+
options = {
|
8
|
+
:width => 590,
|
9
|
+
:height => 335,
|
10
|
+
:show_stats => false,
|
11
|
+
:autoplay => false
|
12
|
+
}.merge(options)
|
12
13
|
|
13
|
-
|
14
|
+
@regex = /http:\/\/www\.metacafe\.com\/watch\/([A-Za-z0-9._%-]*)\/([A-Za-z0-9._%-]*)(\/)?/
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
string.gsub(@regex) do
|
17
|
+
metacafe_id = $1
|
18
|
+
metacafe_slug = $2
|
19
|
+
width = options[:width]
|
20
|
+
height = options[:height]
|
21
|
+
show_stats = options[:show_stats] ? "showStats=yes" : "showStats=no"
|
22
|
+
autoplay = options[:autoplay] ? "autoPlay=yes" : "autoPlay=no"
|
23
|
+
flash_vars = [show_stats, autoplay].join("|")
|
23
24
|
|
24
|
-
|
25
|
+
%{<div style="background:#000000;width:#{width}px;height:#{height}px"><embed flashVars="playerVars=#{flash_vars}" src="http://www.metacafe.com/fplayer/#{metacafe_id}/#{metacafe_slug}.swf" width="#{width}" height="#{height}" wmode="transparent" allowFullScreen="true" allowScriptAccess="always" name="Metacafe_#{metacafe_id}" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed></div>}
|
26
|
+
end
|
25
27
|
end
|
26
|
-
end
|
27
28
|
|
29
|
+
end
|
28
30
|
end
|
data/lib/converters/nokogiri.rb
CHANGED
@@ -1,36 +1,38 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
+
SKIP = ['a', 'pre', 'code', 'kbd', 'script', 'iframe', 'img', 'link']
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
# Scan a string with Nokogiri and convert if match string
|
7
|
+
def scan(string, options = {})
|
8
|
+
return string if options[:converters].empty?
|
8
9
|
|
9
|
-
|
10
|
+
doc = Nokogiri::HTML.fragment(string)
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
doc.search('.//text()').each do |el|
|
13
|
+
t = el.text
|
14
|
+
if t.strip.size > 0
|
15
|
+
t = convert(t, options) if convertable?(el)
|
16
|
+
end
|
17
|
+
el.replace(t)
|
15
18
|
end
|
16
|
-
el.replace(t)
|
17
|
-
end
|
18
19
|
|
19
|
-
|
20
|
-
|
20
|
+
doc.to_html
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
# Loop converters and convert
|
24
|
+
def convert(string, options = {})
|
25
|
+
options[:converters].each{|c| string = send(c, string)}
|
26
|
+
string
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
# Checks if a node is convertable by scanning the parents
|
30
|
+
def convertable?(node)
|
31
|
+
while(node = node.parent) do
|
32
|
+
return false if SKIP.include?(node.name)
|
33
|
+
end
|
34
|
+
true
|
32
35
|
end
|
33
|
-
true
|
34
|
-
end
|
35
36
|
|
37
|
+
end
|
36
38
|
end
|
data/lib/converters/redcarpet.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
# Markown converter
|
5
|
+
def redcarpet(string, options = {})
|
6
|
+
options = {:renderer => Redcarpet::Render::HTML, :markdown_options => {}}.merge(options)
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
Redcarpet::Markdown.new(options[:renderer], options[:markdown_options]).render(string)
|
9
|
+
end
|
9
10
|
|
11
|
+
end
|
10
12
|
end
|
data/lib/converters/sanitize.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
+
CONFIGS = [:custom, :full, :linebreaks, :simple, :restricted, :basic, :relaxed]
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
def sanitize(string, options = {})
|
7
|
+
return string if options[:config] == false
|
8
|
+
options = {:config => nil}.merge(options)
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
config = Object.const_get("Sanitize::Config::#{options[:config].to_s.upcase}") if CONFIGS.include?(options[:config])
|
11
|
+
Sanitize.fragment(string, config || {})
|
12
|
+
end
|
12
13
|
|
14
|
+
end
|
13
15
|
end
|
@@ -1,9 +1,11 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
# Convert newlines to br tags
|
5
|
+
def simple_format(string, options = {})
|
6
|
+
options = {:config => :simple}.merge(options)
|
7
|
+
sanitize(string.gsub(%r{(\r\n|\n|\r)}, '<br>'), options)
|
8
|
+
end
|
8
9
|
|
10
|
+
end
|
9
11
|
end
|
@@ -1,36 +1,38 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
4
|
+
# Convert soundcloud player URL to embedded iframe
|
5
|
+
def soundcloud(string, options = {})
|
6
|
+
options = {
|
7
|
+
:width => '100%',
|
8
|
+
:height => 166,
|
9
|
+
:auto_play => false,
|
10
|
+
:theme_color => '00FF00',
|
11
|
+
:color => '915f33',
|
12
|
+
:show_comments => false,
|
13
|
+
:show_artwork => false
|
14
|
+
}.merge(options)
|
14
15
|
|
15
|
-
|
16
|
+
@regex = /(https?:\/\/)?(www.)?soundcloud\.com\/\S*/
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
18
|
+
begin
|
19
|
+
string.gsub(@regex) do |match|
|
20
|
+
new_uri = match.to_s
|
21
|
+
new_uri = (new_uri =~ /^https?\:\/\/.*/) ? URI(new_uri) : URI("http://#{new_uri}")
|
22
|
+
new_uri.normalize!
|
23
|
+
width = options[:width]
|
24
|
+
height = options[:height]
|
25
|
+
auto_play = options[:auto_play]
|
26
|
+
theme_color = options[:theme_color]
|
27
|
+
color = options[:color]
|
28
|
+
show_artwork = options[:show_artwork]
|
29
|
+
show_comments = options[:show_comments]
|
30
|
+
%{<iframe width="#{width}" height="#{height}" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player/?url=#{new_uri}&show_artwork=#{show_artwork}&show_comments=#{show_comments}&auto_play=#{auto_play}&color=#{color}&theme_color=#{theme_color}"></iframe> }
|
31
|
+
end
|
32
|
+
rescue URI::InvalidURIError
|
33
|
+
string
|
30
34
|
end
|
31
|
-
rescue URI::InvalidURIError
|
32
|
-
string
|
33
35
|
end
|
34
|
-
end
|
35
36
|
|
37
|
+
end
|
36
38
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
# Remove query params
|
5
|
+
def strip_params(url)
|
6
|
+
uri = URI.parse(URI.encode(url.strip))
|
7
|
+
uri.query = nil
|
8
|
+
uri.to_s
|
9
|
+
end
|
9
10
|
|
11
|
+
end
|
10
12
|
end
|
data/lib/converters/ted.rb
CHANGED
@@ -1,28 +1,30 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
4
|
+
# Convert ted movie URL to embedded iframe
|
5
|
+
def ted(string, options = {})
|
6
|
+
# Original: 640 360
|
7
|
+
options = {
|
8
|
+
:width => 590,
|
9
|
+
:height => 335,
|
10
|
+
:scrolling => 'no',
|
11
|
+
:frameborder => 0,
|
12
|
+
:allow_full_screen => false
|
13
|
+
}.merge(options)
|
13
14
|
|
14
|
-
|
15
|
+
@regex = /https?:\/\/(www.|embed.)?ted\.com\/talks\/([A-Za-z0-9._%-]*)\.html((\?|#)\S+)?/
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
string.gsub(@regex) do
|
18
|
+
ted_page = $2
|
19
|
+
width = options[:width]
|
20
|
+
height = options[:height]
|
21
|
+
frameborder = options[:frameborder]
|
22
|
+
scrolling = options[:scrolling]
|
23
|
+
allow_full_screen = options[:allow_full_screen]
|
23
24
|
|
24
|
-
|
25
|
+
%{<iframe width="#{width}" height="#{height}" frameborder="#{frameborder}" scrolling="#{scrolling}" src="http://embed.ted.com/talks/#{ted_page}.html"#{allow_full_screen ? ' webkitAllowFullScreen mozallowfullscreen allowFullScreen' : ''}></iframe>}
|
26
|
+
end
|
25
27
|
end
|
26
|
-
end
|
27
28
|
|
29
|
+
end
|
28
30
|
end
|
data/lib/converters/twitter.rb
CHANGED
@@ -1,21 +1,23 @@
|
|
1
|
-
module
|
1
|
+
module Convert
|
2
|
+
module Converters
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
# Convert twitter URL to embedded html
|
5
|
+
def twitter(string, options = {})
|
6
|
+
@regex = %r{(?<!href=")https://twitter\.com(/#!)?/[A-Za-z0-9_]{1,15}/status(es)?/\d+(/?)}
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
string.gsub(@regex) do |match|
|
9
|
+
params = {:url => match}.merge(options)
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
uri = URI("https://api.twitter.com/1/statuses/oembed.json")
|
12
|
+
uri.query = URI.encode_www_form(params)
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
15
|
+
http.use_ssl = true
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
response = JSON.parse(http.get(uri.request_uri).body)
|
18
|
+
response["html"]
|
19
|
+
end
|
18
20
|
end
|
19
|
-
end
|
20
21
|
|
22
|
+
end
|
21
23
|
end
|