nathanhoad-moredown 1.0.1 → 1.0.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.
data/README.markdown CHANGED
@@ -52,18 +52,14 @@ implements some extras:
52
52
  * Embed Youtube videos (similar to image syntax)
53
53
 
54
54
  ![Video](youtube:lfAzVe5H-vE)
55
-
56
- * Convert Youtube videos to their preview images (for RSS, etc)
57
-
58
- Moredown.new(text, :youtube_as_images => true)
59
55
 
60
56
  * Use Flash movies
61
57
 
62
58
  ![Flash](flash:movieclip.swf)
63
59
 
64
- * Replace Flash with text (eg. Flash is not available for RSS)
60
+ * Use SwfObject (javascript not included) for graceful Flash degradation
65
61
 
66
- Moredown.new(text, :replace_flash_with => 'Flash is not available')
62
+ Moredown.new(text, :swfobject => { :src => 'swfobject.js', :version => '10', :fallback => 'No Flash' })
67
63
 
68
64
  * Image alignments (extension to image syntax)
69
65
 
data/lib/moredown.rb CHANGED
@@ -1,8 +1,7 @@
1
1
  require 'rdiscount'
2
2
 
3
3
  class Moredown < RDiscount
4
- # Convert youtube videos to preview images (handy for valid RSS)
5
- attr_accessor :youtube_as_images
4
+ VERSION = '1.0.3'
6
5
 
7
6
  # Don't use inline CSS for styling
8
7
  attr_accessor :has_stylesheet
@@ -16,8 +15,8 @@ class Moredown < RDiscount
16
15
  # Map headings down a few ranks (eg. :map_headings => 2 would convert h1 to h3)
17
16
  attr_accessor :map_headings
18
17
 
19
- # Replace Flash with text (eg. Flash is unavailable in RSS)
20
- attr_accessor :replace_flash_with
18
+ # Use SwfObject2 if available (eg. :swfobject => { :src => 'swfobject.js', :version => '10', :fallback => 'No Flash' })
19
+ attr_accessor :swfobject
21
20
 
22
21
  # Create a Moredown Markdown processor. The +text+ argument
23
22
  # should be a string containing Markdown text. Additional arguments may be
@@ -29,21 +28,22 @@ class Moredown < RDiscount
29
28
  # * <tt>:filter_html</tt> - Do not output any raw HTML tags included in
30
29
  # the source text.
31
30
  # * <tt>:fold_lines</tt> - RedCloth compatible line folding (not used).
32
- # * <tt>:youtube_as_images</tt> - Convert youtube videos to preview images (handy for valid RSS).
33
31
  # * <tt>:has_stylesheet</tt> - Don't use inline CSS for styling.
34
32
  # * <tt>:emotes</tt> - Process emoticons.
35
33
  # * <tt>:base_url</tt> - Map any relative URLs in the text to absolute URLs.
36
34
  # * <tt>:map_headings</tt> - Map any headings down a few ranks (eg. h1 => h3).
37
- # * <tt>:replace_flash_with</tt> - Replace Flash with text (eg. Flash is unavailable in RSS)
35
+ # * <tt>:swfobject</tt> - Use SwfObject2 if available (eg. :swfobject => { :src => 'swfobject.js', :version => '10', :fallback => 'No Flash' })
38
36
  #
39
37
  # NOTE: The <tt>:filter_styles</tt> extension is not yet implemented.
40
38
  def initialize text, args = {}
41
- @youtube_as_images = args[:youtube_as_images]
42
39
  @has_stylesheet = args[:has_stylesheet]
43
40
  @emotes = args[:emotes]
44
41
  @base_url = args[:base_url]
45
42
  @map_headings = args[:map_headings] || 0
46
- @replace_flash_with = args[:replace_flash_with]
43
+ @swfobject = args[:swfobject]
44
+
45
+ # each swfobject needs a unique id
46
+ @next_flash_id = 0
47
47
 
48
48
  if args[:extensions]
49
49
  super(text, args[:extensions])
@@ -57,24 +57,16 @@ class Moredown < RDiscount
57
57
 
58
58
  # youtube
59
59
  html.gsub!(/<img src="youtube:(.*)?" alt="(.*)?" \/>/) do |match|
60
- if @youtube_as_images
61
- "<img src=\"http://img.youtube.com/vi/#{$1}/default.jpg\" alt=\"#{$2}\" />"
62
- else
63
- flash_tag "http://www.youtube.com/v/#{$1}", :width => 425, :height => 350
64
- end
60
+ flash_tag "http://www.youtube.com/v/#{$1}", :width => 425, :height => 350
65
61
  end
66
62
 
67
63
  # flash movies
68
64
  html.gsub!(/<img src="flash:(.*?)"\s?(?:title="(.*?)")? alt="(.*)" \/>/) do |match|
69
- if @replace_flash_with
70
- @replace_flash_with
71
- else
72
- if $2
73
- sizes = $2.split(' ')
74
- sizes = { :width => sizes[0], :height => sizes[1] }
75
- end
76
- flash_tag $1, (sizes || {})
65
+ if $2
66
+ sizes = $2.split(' ')
67
+ sizes = { :width => sizes[0], :height => sizes[1] }
77
68
  end
69
+ flash_tag $1, (sizes || {})
78
70
  end
79
71
 
80
72
  # image alignments
@@ -110,6 +102,17 @@ class Moredown < RDiscount
110
102
  html.gsub!(/<(\/)?h(\d)>/) { |match| "<#{$1}h#{$2.to_i + @map_headings}>" }
111
103
  end
112
104
 
105
+ # add the js for swfobject
106
+ if @swfobject
107
+ swfobjects = []
108
+ 1.upto(@next_flash_id).each do |n|
109
+ swfobjects << "swfobject.registerObject(\"swf-#{n}\", \"#{@swfobject[:version]}\");\n"
110
+ end
111
+
112
+ # html seems to need to go after the swfobject javascript
113
+ html = "<script type=\"text/javascript\" src=\"#{@swfobject[:src]}\"></script><script type=\"text/javascript\">\n//<![CDATA[\n#{swfobjects}//]]>\n</script>\n#{html}"
114
+ end
115
+
113
116
  html
114
117
  end
115
118
 
@@ -121,7 +124,23 @@ class Moredown < RDiscount
121
124
 
122
125
  protected
123
126
  def flash_tag url, args = {}
124
- args = {:width => 400, :height => 300}.merge args
125
- "<object data=\"#{url}\" type=\"application/x-shockwave-flash\" width=\"#{args[:width]}\" height=\"#{args[:height]}\"><param name=\"movie\" value=\"#{url}\" /></object>"
127
+ args = {:width => 400, :height => 300, :fallback => 'Flash is not available.'}.merge args
128
+
129
+ if url.include? 'youtube.com'
130
+ fallback = "<a href=\"#{url}\"><img src=\"http://img.youtube.com/vi/#{url.split('/').last}/default.jpg\" alt=\"\" /></a>"
131
+ elsif @swfobject
132
+ fallback = @swfobject[:fallback]
133
+ else
134
+ fallback = args[:fallback]
135
+ end
136
+
137
+ return "<object id=\"swf-#{@next_flash_id += 1}\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"#{args[:width]}\" height=\"#{args[:height]}\">" \
138
+ +"<param name=\"movie\" value=\"#{url}\" />" \
139
+ +"<!--[if !IE]>-->" \
140
+ +"<object type=\"application/x-shockwave-flash\" data=\"#{url}\" width=\"#{args[:width]}\" height=\"#{args[:height]}\">" \
141
+ +"<!--<![endif]-->#{fallback}<!--[if !IE]>-->" \
142
+ +"</object>" \
143
+ +"<!--<![endif]-->" \
144
+ +"</object>"
126
145
  end
127
146
  end
@@ -1,12 +1,12 @@
1
1
  Gem::Specification.new do |s|
2
- s.name = 'rdiscount'
3
- s.version = '1.3.5'
2
+ s.name = 'moredown'
3
+ s.version = '1.0.3'
4
4
  s.summary = "Fast Implementation of Gruber's Markdown in C"
5
- s.date = '2009-07-26'
6
- s.email = 'r@tomayko.com'
7
- s.homepage = 'http://github.com/rtomayko/rdiscount'
5
+ s.date = '2009-09-08'
6
+ s.email = 'nathan@nathanhoad.net'
7
+ s.homepage = 'http://github.com/nathanhoad/moredown'
8
8
  s.has_rdoc = true
9
- s.authors = ["Ryan Tomayko", "Andrew White"]
9
+ s.authors = ["Nathan Hoad", "Ryan Tomayko", "Andrew White"]
10
10
  # = MANIFEST =
11
11
  s.files = %w[
12
12
  COPYING
@@ -29,18 +29,19 @@ Gem::Specification.new do |s|
29
29
  ext/resource.c
30
30
  ext/toc.c
31
31
  lib/markdown.rb
32
+ lib/moredown.rb
32
33
  lib/rdiscount.rb
33
- rdiscount.gemspec
34
+ moredown.gemspec
34
35
  test/benchmark.rb
35
36
  test/benchmark.txt
36
37
  test/markdown_test.rb
38
+ test/moredown_test.rb
37
39
  test/rdiscount_test.rb
38
40
  ]
39
41
  # = MANIFEST =
40
- s.test_files = ["test/markdown_test.rb", "test/rdiscount_test.rb"]
42
+ s.test_files = ["test/moredown_test.rb", "test/markdown_test.rb", "test/rdiscount_test.rb"]
41
43
  s.extra_rdoc_files = ["COPYING"]
42
44
  s.extensions = ["ext/extconf.rb"]
43
45
  s.executables = ["rdiscount"]
44
46
  s.require_paths = ["lib"]
45
- s.rubyforge_project = 'wink'
46
47
  end
@@ -20,7 +20,7 @@ class MoredownTest < Test::Unit::TestCase
20
20
 
21
21
  def test_youtube_videos
22
22
  text = "![Video](youtube:12345678)"
23
- html = "<p><object data=\"http://www.youtube.com/v/12345678\" type=\"application/x-shockwave-flash\" width=\"425\" height=\"350\"><param name=\"movie\" value=\"http://www.youtube.com/v/12345678\" /></object></p>\n"
23
+ html = "<p><object id=\"swf-1\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"425\" height=\"350\"><param name=\"movie\" value=\"http://www.youtube.com/v/12345678\" /><!--[if !IE]>--><object type=\"application/x-shockwave-flash\" data=\"http://www.youtube.com/v/12345678\" width=\"425\" height=\"350\"><!--<![endif]--><a href=\"http://www.youtube.com/v/12345678\"><img src=\"http://img.youtube.com/vi/12345678/default.jpg\" alt=\"\" /></a><!--[if !IE]>--></object><!--<![endif]--></object></p>\n"
24
24
  assert_equal html, Moredown.text_to_html(text)
25
25
 
26
26
  text = <<TEXT
@@ -30,22 +30,10 @@ Here is a video:
30
30
 
31
31
  That was _awesome_.
32
32
  TEXT
33
- html = <<TEXT
34
- <p>Here is a video:</p>
35
-
36
- <p><object data="http://www.youtube.com/v/12345678" type="application/x-shockwave-flash" width="425" height="350"><param name="movie" value="http://www.youtube.com/v/12345678" /></object></p>
37
-
38
- <p>That was <em>awesome</em>.</p>
39
- TEXT
33
+ html = "<p>Here is a video:</p>\n\n<p><object id=\"swf-1\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"425\" height=\"350\"><param name=\"movie\" value=\"http://www.youtube.com/v/12345678\" /><!--[if !IE]>--><object type=\"application/x-shockwave-flash\" data=\"http://www.youtube.com/v/12345678\" width=\"425\" height=\"350\"><!--<![endif]--><a href=\"http://www.youtube.com/v/12345678\"><img src=\"http://img.youtube.com/vi/12345678/default.jpg\" alt=\"\" /></a><!--[if !IE]>--></object><!--<![endif]--></object></p>\n\n<p>That was <em>awesome</em>.</p>\n"
40
34
  assert_equal html, Moredown.text_to_html(text)
41
35
  end
42
36
 
43
- def test_youtube_images
44
- text = "![Video](youtube:12345678)"
45
- html = "<p><img src=\"http://img.youtube.com/vi/12345678/default.jpg\" alt=\"Video\" /></p>\n"
46
- assert_equal html, Moredown.text_to_html(text, :youtube_as_images => true)
47
- end
48
-
49
37
  def test_image_alignments
50
38
  text = "![Image](/image.jpg):left"
51
39
  html = "<p><img style=\"float: left; margin: 0 10px 10px 0;\" src=\"/image.jpg\" alt=\"Image\" /></p>\n"
@@ -146,17 +134,35 @@ TEXT
146
134
 
147
135
  def test_flash_movies
148
136
  text = '![Flash](flash:movieclip.swf)'
149
- html = "<p><object data=\"movieclip.swf\" type=\"application/x-shockwave-flash\" width=\"400\" height=\"300\"><param name=\"movie\" value=\"movieclip.swf\" /></object></p>\n"
137
+ html = "<p><object id=\"swf-1\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"400\" height=\"300\"><param name=\"movie\" value=\"movieclip.swf\" /><!--[if !IE]>--><object type=\"application/x-shockwave-flash\" data=\"movieclip.swf\" width=\"400\" height=\"300\"><!--<![endif]-->Flash is not available.<!--[if !IE]>--></object><!--<![endif]--></object></p>\n"
150
138
  assert_equal html, Moredown.text_to_html(text)
151
139
 
152
140
  text = '![Flash](flash:movieclip.swf "800 600")'
153
- html = "<p><object data=\"movieclip.swf\" type=\"application/x-shockwave-flash\" width=\"800\" height=\"600\"><param name=\"movie\" value=\"movieclip.swf\" /></object></p>\n"
141
+ html = "<p><object id=\"swf-1\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"800\" height=\"600\"><param name=\"movie\" value=\"movieclip.swf\" /><!--[if !IE]>--><object type=\"application/x-shockwave-flash\" data=\"movieclip.swf\" width=\"800\" height=\"600\"><!--<![endif]-->Flash is not available.<!--[if !IE]>--></object><!--<![endif]--></object></p>\n"
154
142
  assert_equal html, Moredown.text_to_html(text)
155
143
  end
156
144
 
157
- def test_replace_flash_with
158
- text = '![Flash](flash:movieclip.swf)'
159
- html = "<p>Flash cannot be displayed</p>\n"
160
- assert_equal html, Moredown.text_to_html(text, :replace_flash_with => 'Flash cannot be displayed');
145
+ def test_swfobject
146
+ text = "Here is some flash:
147
+
148
+ ![Flash](flash:movieclip.swf)
149
+
150
+ ![Flash](flash:movieclip.swf)
151
+
152
+ And that's all."
153
+ html = "<script type=\"text/javascript\" src=\"./swfobject.js\"></script><script type=\"text/javascript\">
154
+ //<![CDATA[
155
+ swfobject.registerObject(\"swf-1\", \"10\");
156
+ swfobject.registerObject(\"swf-2\", \"10\");
157
+ //]]>
158
+ </script>
159
+ <p>Here is some flash:</p>
160
+
161
+ <p><object id=\"swf-1\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"400\" height=\"300\"><param name=\"movie\" value=\"movieclip.swf\" /><!--[if !IE]>--><object type=\"application/x-shockwave-flash\" data=\"movieclip.swf\" width=\"400\" height=\"300\"><!--<![endif]-->No Flash<!--[if !IE]>--></object><!--<![endif]--></object></p>
162
+
163
+ <p><object id=\"swf-2\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"400\" height=\"300\"><param name=\"movie\" value=\"movieclip.swf\" /><!--[if !IE]>--><object type=\"application/x-shockwave-flash\" data=\"movieclip.swf\" width=\"400\" height=\"300\"><!--<![endif]-->No Flash<!--[if !IE]>--></object><!--<![endif]--></object></p>
164
+
165
+ <p>And that's all.</p>\n"
166
+ assert_equal html, Moredown.text_to_html(text, :swfobject => { :js_src => './swfobject.js', :version => '10', :fallback => 'No Flash' })
161
167
  end
162
168
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nathanhoad-moredown
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hoad
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-09-03 00:00:00 -07:00
14
+ date: 2009-09-08 00:00:00 -07:00
15
15
  default_executable:
16
16
  dependencies: []
17
17
 
@@ -43,14 +43,14 @@ files:
43
43
  - ext/rdiscount.c
44
44
  - ext/resource.c
45
45
  - ext/toc.c
46
- - lib/moredown.rb
47
46
  - lib/markdown.rb
47
+ - lib/moredown.rb
48
48
  - lib/rdiscount.rb
49
- - rdiscount.gemspec
49
+ - moredown.gemspec
50
50
  - test/benchmark.rb
51
51
  - test/benchmark.txt
52
- - test/moredown_test.rb
53
52
  - test/markdown_test.rb
53
+ - test/moredown_test.rb
54
54
  - test/rdiscount_test.rb
55
55
  has_rdoc: true
56
56
  homepage: http://github.com/nathanhoad/moredown