nathanhoad-moredown 1.0.0 → 1.0.1

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
@@ -34,10 +34,55 @@ Usage
34
34
  -----
35
35
 
36
36
  Moredown can be used in any way that RDiscount can be (see below). In addition, Moredown
37
- implements some extra syntax options via a static formatting method:
38
-
39
- require 'nathanhoad-moredown'
40
- html = Moredown.text_to_html("Hello World!")
37
+ implements some extras:
38
+
39
+ * Static method for simple calls
40
+
41
+ require 'nathanhoad-moredown'
42
+ html = Moredown.text_to_html("Hello World!")
43
+
44
+ * Remap relative URLs
45
+
46
+ Moredown.new(text, :base_url => 'http://nathanhoad.net').to_html
47
+
48
+ * Remap headings (eg. h1 becomes h3).
49
+
50
+ Moredown.new(text, :map_headings => 2)
51
+
52
+ * Embed Youtube videos (similar to image syntax)
53
+
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
+
60
+ * Use Flash movies
61
+
62
+ ![Flash](flash:movieclip.swf)
63
+
64
+ * Replace Flash with text (eg. Flash is not available for RSS)
65
+
66
+ Moredown.new(text, :replace_flash_with => 'Flash is not available')
67
+
68
+ * Image alignments (extension to image syntax)
69
+
70
+ ![Image](/images/test.jpg):left
71
+ ![Image](/images/test.jpg):right
72
+ ![Image](/images/test.jpg):center
73
+
74
+ * Emoticons
75
+
76
+ :-)
77
+ :-P
78
+ :-D
79
+ :-(
80
+ :-@
81
+ ;-)
82
+
83
+ * RDiscount extensions are now passed under `:extensions`
84
+
85
+ Moredown.new(text, :extensions => [:smart])
41
86
 
42
87
  RDiscount implements the basic protocol popularized by RedCloth and adopted
43
88
  by BlueCloth:
data/lib/moredown.rb CHANGED
@@ -16,6 +16,9 @@ class Moredown < RDiscount
16
16
  # Map headings down a few ranks (eg. :map_headings => 2 would convert h1 to h3)
17
17
  attr_accessor :map_headings
18
18
 
19
+ # Replace Flash with text (eg. Flash is unavailable in RSS)
20
+ attr_accessor :replace_flash_with
21
+
19
22
  # Create a Moredown Markdown processor. The +text+ argument
20
23
  # should be a string containing Markdown text. Additional arguments may be
21
24
  # supplied to set various processing options:
@@ -31,6 +34,7 @@ class Moredown < RDiscount
31
34
  # * <tt>:emotes</tt> - Process emoticons.
32
35
  # * <tt>:base_url</tt> - Map any relative URLs in the text to absolute URLs.
33
36
  # * <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)
34
38
  #
35
39
  # NOTE: The <tt>:filter_styles</tt> extension is not yet implemented.
36
40
  def initialize text, args = {}
@@ -39,6 +43,7 @@ class Moredown < RDiscount
39
43
  @emotes = args[:emotes]
40
44
  @base_url = args[:base_url]
41
45
  @map_headings = args[:map_headings] || 0
46
+ @replace_flash_with = args[:replace_flash_with]
42
47
 
43
48
  if args[:extensions]
44
49
  super(text, args[:extensions])
@@ -48,14 +53,29 @@ class Moredown < RDiscount
48
53
  end
49
54
 
50
55
  def to_html
51
- # Youtube
52
- if @youtube_as_images
53
- @text.gsub!(/!\[(.*)?\]\(youtube:(.+)?\)/) { |match| "<img src=\"http://img.youtube.com/vi/#{$2}/default.jpg\" alt=\"#{$1}\" />" }
54
- else
55
- @text.gsub!(/!\[.*?\]\(youtube:(.+)?\)/) { |match| "<object data=\"http://www.youtube.com/v/#{$1}\" type=\"application/x-shockwave-flash\" width=\"425\" height=\"350\"><param name=\"movie\" value=\"http://www.youtube.com/v/#{$1}\" /></object>" }
56
+ html = super
57
+
58
+ # youtube
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
56
65
  end
57
66
 
58
- html = super
67
+ # flash movies
68
+ 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 || {})
77
+ end
78
+ end
59
79
 
60
80
  # image alignments
61
81
  if @has_stylesheet
@@ -97,4 +117,11 @@ class Moredown < RDiscount
97
117
  def self.text_to_html text, args = {}
98
118
  Moredown.new(text, args).to_html
99
119
  end
120
+
121
+
122
+ protected
123
+ 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>"
126
+ end
100
127
  end
@@ -132,5 +132,31 @@ TEXT
132
132
  text = "<h1>Heading</h1>\n<h2>Sub-heading</h2>"
133
133
  html = "<h3>Heading</h3>\n\n\n<h4>Sub-heading</h4>\n\n"
134
134
  assert_equal html, Moredown.text_to_html(text, :map_headings => 2)
135
+
136
+ text = <<TEXT
137
+ Heading
138
+ =======
139
+
140
+ Sub-heading
141
+ -----------
142
+ TEXT
143
+ html = "<h3>Heading</h3>\n\n<h4>Sub-heading</h4>\n"
144
+ assert_equal html, Moredown.text_to_html(text, :map_headings => 2)
145
+ end
146
+
147
+ def test_flash_movies
148
+ 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"
150
+ assert_equal html, Moredown.text_to_html(text)
151
+
152
+ 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"
154
+ assert_equal html, Moredown.text_to_html(text)
155
+ end
156
+
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');
135
161
  end
136
162
  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.0
4
+ version: 1.0.1
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-08-22 00:00:00 -07:00
14
+ date: 2009-09-03 00:00:00 -07:00
15
15
  default_executable:
16
16
  dependencies: []
17
17
 
@@ -54,7 +54,6 @@ files:
54
54
  - test/rdiscount_test.rb
55
55
  has_rdoc: true
56
56
  homepage: http://github.com/nathanhoad/moredown
57
- licenses:
58
57
  post_install_message:
59
58
  rdoc_options: []
60
59
 
@@ -75,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
74
  requirements: []
76
75
 
77
76
  rubyforge_project:
78
- rubygems_version: 1.3.5
77
+ rubygems_version: 1.2.0
79
78
  signing_key:
80
79
  specification_version: 2
81
80
  summary: Fast Implementation of Gruber's Markdown in C