trac-wiki 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,6 +16,7 @@ require 'uri'
16
16
  # ||=Table=||=Heading=||
17
17
  # || Table || Cells ||
18
18
  # [[Image(image.png)]]
19
+ # [[Image(image.png, options)]]
19
20
  #
20
21
  # The simplest interface is TracWiki.render. The default handling of
21
22
  # links allow explicit local links using the [[link]] syntax. External
@@ -207,12 +208,35 @@ module TracWiki
207
208
  # method can be overridden to generate custom
208
209
  # markup, for example to add html additional attributes or
209
210
  # to put divs around the imgs.
210
- def make_image(uri, alt='')
211
- if alt
212
- "<img src=\"" << escape_html(uri) << "\" alt=\"" << escape_html(alt) << "\"/>"
213
- else
214
- "<img src=\"" << escape_html(uri) << "\"/>"
215
- end
211
+ def make_image(uri, attrs='')
212
+ "<img src=\"#{escape_html(uri)}\"#{make_image_attrs(attrs)}/>"
213
+ end
214
+
215
+ def make_image_attrs(attrs)
216
+ return '' if ! attrs
217
+ a = {}
218
+ style = []
219
+ attrs.strip.split(/\s*,\s*/).each do |opt|
220
+ case opt
221
+ when /^\d+[^\d]*$/
222
+ a['width'] = opt
223
+ when /^(right|left|center)/i
224
+ a['align'] = opt
225
+ when /^(top|bottom|middle)$/i
226
+ a['valign'] = opt
227
+ when /^link=(.*)$/i
228
+ # pass
229
+ when /^nolink$/i
230
+ # pass
231
+ when /^(align|valign|border|width|height|alt|title|longdesc|class|id|usemap)=(.*)$/i
232
+ a[$1]= escape_html($2)
233
+ when /^(margin|margin-(left|right|top|bottom))=(\d+)$/
234
+ style.push($1 + ":" + escape_html($3))
235
+ end
236
+ end
237
+ a['style'] = style.join(';') if ! style.empty?
238
+ return '' if a.empty?
239
+ return ' ' + a.map{|k,v| "#{k}=\"#{v}\"" }.sort.join(' ')
216
240
  end
217
241
 
218
242
  def make_headline(level, text)
@@ -244,7 +268,7 @@ module TracWiki
244
268
  end
245
269
  end
246
270
  # [[Image(pic.jpg|tag)]]
247
- when /\A\[\[Image\(([^|].*?)(\|(.*?))?\)\]\]/ # image
271
+ when /\A\[\[Image\(([^,]*?)(,(.*?))?\)\]\]/ # image
248
272
  str = $'
249
273
  @out << make_image($1, $3)
250
274
  # [[link]]
@@ -1,3 +1,3 @@
1
1
  module TracWiki
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -449,8 +449,8 @@ describe TracWiki::Parser do
449
449
  # Image tags should be escape
450
450
  tc("<p><img src=\"image.jpg\"/></p>\n", "[[Image(image.jpg)]]")
451
451
  tc("<p><img src=\"image.jpg\"/></p>\n", "[[Image(image.jpg)]]", :no_link=>true)
452
- tc("<p><img src=\"image.jpg\" alt=\"&quot;tag&quot;\"/></p>\n", "[[Image(image.jpg|\"tag\")]]")
453
- tc("<p><img src=\"image.jpg\" alt=\"&quot;tag&quot;\"/></p>\n", "[[Image(image.jpg|\"tag\")]]", :no_link=>true)
452
+ tc("<p><img src=\"image.jpg\" alt=\"a&quot;tag&quot;\"/></p>\n", "[[Image(image.jpg,alt=a\"tag\")]]")
453
+ tc("<p><img src=\"image.jpg\" alt=\"a&quot;tag&quot;\"/></p>\n", "[[Image(image.jpg,alt=a\"tag\")]]", :no_link=>true)
454
454
 
455
455
  # Malicious links should not be converted.
456
456
  tc("<p><a href=\"javascript%3Aalert%28%22Boo%21%22%29\">Click</a></p>\n", "[[javascript:alert(\"Boo!\")|Click]]")
@@ -708,7 +708,20 @@ describe TracWiki::Parser do
708
708
 
709
709
  it 'should parse image' do
710
710
  tc("<p><img src=\"image.jpg\"/></p>\n", "[[Image(image.jpg)]]")
711
- tc("<p><img src=\"image.jpg\" alt=\"tag\"/></p>\n", "[[Image(image.jpg|tag)]]")
711
+ tc("<p><img src=\"image.jpg\" alt=\"tag\"/></p>\n", "[[Image(image.jpg,alt=tag)]]")
712
+ tc("<p><img src=\"image.jpg\" width=\"120px\"/></p>\n", "[[Image(image.jpg, 120px )]]")
713
+ tc("<p><img src=\"image.jpg\" width=\"120px\"/></p>\n", "[[Image(image.jpg, \t120px )]]")
714
+ tc("<p><img src=\"image.jpg\" align=\"right\"/></p>\n", "[[Image(image.jpg, right)]]")
715
+ tc("<p><img src=\"image.jpg\" align=\"right\" valign=\"top\"/></p>\n", "[[Image(image.jpg, right,top)]]")
716
+ tc("<p><img src=\"image.jpg\" align=\"right\" valign=\"top\"/></p>\n", "[[Image(image.jpg, top,right)]]")
717
+ tc("<p><img src=\"image.jpg\" valign=\"top\"/></p>\n", "[[Image(image.jpg, top)]]")
718
+ tc("<p><img src=\"image.jpg\" valign=\"top\"/></p>\n", "[[Image(image.jpg, valign=top)]]")
719
+ tc("<p><img src=\"image.jpg\" align=\"center\"/></p>\n", "[[Image(image.jpg, center)]]")
720
+ tc("<p><img src=\"image.jpg\" valign=\"middle\"/></p>\n", "[[Image(image.jpg, middle)]]")
721
+ tc("<p><img src=\"image.jpg\" title=\"houhouhou\"/></p>\n", "[[Image(image.jpg, title=houhouhou)]]")
722
+ tc("<p><img src=\"image.jpg\" width=\"120px\"/></p>\n", "[[Image(image.jpg,width=120px)]]")
723
+ tc("<p><img src=\"image.jpg\" width=\"120%\"/></p>\n", "[[Image(image.jpg, width=120%)]]")
724
+ tc("<p><img src=\"image.jpg\" style=\"margin:5\"/></p>\n", "[[Image(image.jpg,margin=5)]]")
712
725
  tc("<p><img src=\"http://example.org/image.jpg\"/></p>\n", "[[Image(http://example.org/image.jpg)]]")
713
726
  end
714
727
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trac-wiki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-19 00:00:00.000000000 Z
12
+ date: 2013-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bacon