1
by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
1
begin
2
require "rdoc/markup/simple_markup"
3
require 'rdoc/markup/simple_markup/to_html'
271
by Jacques Distler
More Ruby 1.9 Compatibility fixes
5
# Ruby 1.9
7
require 'rdoc/markup/to_html'
9
class SimpleMarkup < RDoc::Markup
11
class ToHtml <RDoc::Markup::ToHtml
1
by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
14
end
18
# A simple +rdoc+ markup class which recognizes some additional
19
# formatting commands suitable for Wiki use.
20
class RDocMarkup < SM::SimpleMarkup
24
pre = '(?:\\s|^|\\\\)'
27
# [[<url> description with spaces]]
28
add_special(/((\\)?\[\[\S+?\s+.+?\]\])/,:TIDYLINK)
30
# and external references
31
add_special(/((\\)?(link:|anchor:|http:|mailto:|ftp:|img:|www\.)\S+\w\/?)/,
35
add_special(%r{(#{pre}<br/>)}, :BR)
37
# and <center> ... </center>
38
add_html("center", :CENTER)
41
def convert(text, handler)
42
super.sub(/^<p>\n/, '').sub(/<\/p>$/, '')
46
# Handle special hyperlinking requirments for RDoc formatted
47
# entries. Requires RDoc
49
class HyperLinkHtml < SM::ToHtml
51
# Initialize the HyperLinkHtml object.
52
# [path] location of the node
53
# [site] object representing the whole site (typically of class
57
add_tag(:CENTER, "<center>", "</center>")
61
def handle_special_BR(special)
62
return "<br/>" if special.text[0,1] == '\\'
66
# We're invoked with a potential external hyperlink.
67
# [mailto:] just gets inserted.
68
# [http:] links are checked to see if they
69
# reference an image. If so, that image gets inserted
70
# using an <img> tag. Otherwise a conventional <a href>
72
# [img:] insert a <tt><img></tt> tag
73
# [link:] used to insert arbitrary <tt><a></tt> references
74
# [anchor:] used to create an anchor
75
def handle_special_HYPERLINK(special)
76
text = special.text.strip
77
return text[1..-1] if text[0,1] == '\\'
78
url = special.text.strip
79
if url =~ /([A-Za-z]+):(.*)/
90
if url =~ /\.(gif|png|jpg|jpeg|bmp)$/
91
"<img src=\"#{url}\"/>"
93
"<a href=\"#{url}\">#{url.sub(%r{^\w+:/*}, '')}</a>"
96
"<img src=\"#{path}\"/>"
98
"<a href=\"#{path}\">#{path}</a>"
100
"<a name=\"#{path}\"></a>"
102
"<a href=\"#{url}\">#{url.sub(%r{^\w+:/*}, '')}</a>"
106
# Here's a hyperlink where the label is different to the URL
107
# [[url label that may contain spaces]]
110
def handle_special_TIDYLINK(special)
111
text = special.text.strip
112
return text[1..-1] if text[0,1] == '\\'
113
unless text =~ /\[\[(\S+?)\s+(.+?)\]\]/
118
label = RDocFormatter.new(label).to_html
119
label = label.split.select{|x| x =~ /\S/}.
120
map{|x| x.chomp}.join(' ')
124
return %{<a href="#{1ドル}">#{label}</a>}
126
return %{<img src="http://#{1ドル}" alt="#{label}" />}
127
when /rubytalk:(\S+)/
128
return %{<a href="http://ruby-talk.org/blade/#{1ドル}">#{label}</a>}
129
when /rubygarden:(\S+)/
130
return %{<a href="http://www.rubygarden.org/ruby?#{1ドル}">#{label}</a>}
132
return %{<a href="http://c2.com/cgi/wiki?#{1ドル}">#{label}</a>}
134
return %{<a href="http://search.barnesandnoble.com/bookSearch/} +
135
%{isbnInquiry.asp?isbn=#{1ドル}">#{label}</a>}
138
unless url =~ /\w+?:/
139
url = "http://#{url}"
142
"<a href=\"#{url}\">#{label}</a>"
152
markup = RDocMarkup.new
153
h = HyperLinkHtml.new
154
markup.convert(@text, h)
271
by Jacques Distler
More Ruby 1.9 Compatibility fixes
158
end