Soks 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. data/README.txt +22 -20
  2. data/bin/soks-create-wiki.rb +11 -2
  3. data/contrib/{redcloth-3.0.1.rb → redcloth-3.0.3.rb} +161 -66
  4. data/lib/authenticators.rb +2 -2
  5. data/lib/helpers/mail2wiki-helper.rb +101 -0
  6. data/lib/helpers/rss2wiki-helper.rb +48 -0
  7. data/lib/soks-model.rb +7 -5
  8. data/lib/soks-servlet.rb +8 -19
  9. data/lib/soks-view.rb +70 -162
  10. data/lib/soks.rb +20 -2
  11. data/templates/default/attachment/favicon.ico +0 -0
  12. data/templates/default/attachment/logo_thumb.bmp +0 -0
  13. data/templates/default/attachment/robots.txt +5 -0
  14. data/templates/default/attachment/stylesheet.css +1 -0
  15. data/templates/default/content/Attached%20ruby%20logo.textile +1 -0
  16. data/templates/default/content/Attached%20test%20thing.textile +1 -0
  17. data/templates/default/content/Automatic%20Summaries.textile +1 -1
  18. data/templates/default/content/Bug%3A%20%5BFATAL%5D%20When%20renaming%20upload%20%2F%20picture%2.textile +1 -0
  19. data/templates/default/content/Bug%3A%20Duplicate%20links%2Dto%20a%20page%20sometimes%20appear.textile +1 -1
  20. data/templates/default/content/Bug%3A%20External%20links%20incorrectly%20include%20trailing%20pu.textile +1 -1
  21. data/templates/default/content/Bug%3A%20No%20robots%2Etxt%20or%20favicon%2Eico.textile +1 -1
  22. data/templates/default/content/Bug%3A%20Page%20titles%20cannot%20have%20html%20tags%20in%20them.textile +1 -1
  23. data/templates/default/content/Bug%3A%20Punctuation%20in%20page%20titles%20still%20problematic.textile +7 -0
  24. data/templates/default/content/Bug%3A%20Search%20includes%20leading%20and%20trailing%20spaces.textile +1 -0
  25. data/templates/default/content/Bug%3A%20Search%20inluced%20leading%20and%20trailing%20spaces.textile +1 -0
  26. data/templates/default/content/Bug%3A%20no%20superclass%20method%20%60%5Fdeprecated%5Fbase64.textile +1 -0
  27. data/templates/default/content/Bug%3A%20notextile%20does%20not%20prevent%20page%20inserts.textile +1 -0
  28. data/templates/default/content/Fixed%20Bug%3A%20%5BFATAL%5D%20When%20renaming%20upload%20%2F%20p.textile +34 -0
  29. data/templates/default/content/Fixed%20Bug%3A%20Duplicate%20links%2Dto%20a%20page%20sometimes%20.textile +3 -0
  30. data/templates/default/content/Fixed%20Bug%3A%20External%20links%20incorrectly%20include%20trail.textile +3 -0
  31. data/templates/default/content/Fixed%20Bug%3A%20No%20robots%2Etxt%20or%20favicon%2Eico.textile +4 -0
  32. data/templates/default/content/Fixed%20Bug%3A%20Search%20includes%20leading%20and%20trailing%20s.textile +3 -0
  33. data/templates/default/content/Fixed%20Bug%3A%20no%20superclass%20method%20%60%5Fdeprecated%5Fba.textile +3 -0
  34. data/templates/default/content/Home%20Page.textile +2 -2
  35. data/templates/default/content/How%20to%20administrate%20this%20wiki.textile +1 -1
  36. data/templates/default/content/How%20to%20report%20a%20bug.textile +8 -0
  37. data/templates/default/content/Instructions%20and%20Howtos.textile +1 -0
  38. data/templates/default/content/Known%20bugs.textile +4 -5
  39. data/templates/default/content/List%20of%20changes.textile +32 -0
  40. data/templates/default/content/Picture%20of%20a%20logo%20for%20the%20ruby%20language.textile +1 -0
  41. data/templates/default/content/Picture%20of%20powered%20by%20ruby%20logo.textile +1 -0
  42. data/templates/default/content/Planned%20Features.textile +19 -0
  43. data/templates/default/content/README.textile +22 -20
  44. data/templates/default/content/Recent%20Changes%20to%20This%20Site.textile +123 -8
  45. data/templates/default/content/SOKS%20features.textile +5 -1
  46. data/templates/default/content/Site%20Index.textile +11 -6
  47. data/templates/default/start.rb +17 -6
  48. data/templates/default/version.txt +1 -1
  49. data/templates/default/views/Page_edit.rhtml +7 -6
  50. data/templates/default/views/Page_meta.rhtml +5 -5
  51. data/templates/default/views/Page_revisions.rhtml +4 -3
  52. data/templates/default/views/Page_search_results.rhtml +3 -3
  53. data/templates/default/views/Page_view.rhtml +2 -2
  54. data/templates/default/views/UploadPage_edit.rhtml +6 -6
  55. data/templates/default/views/frame.rhtml +15 -14
  56. data/templates/instiki/content/Attached%20ruby%20logo.textile +1 -0
  57. data/templates/instiki/content/Attached%20test%20thing.textile +1 -0
  58. data/templates/instiki/content/Automatic%20Summaries.textile +1 -1
  59. data/templates/instiki/content/Bug%3A%20%5BFATAL%5D%20When%20renaming%20upload%20%2F%20picture%2.textile +1 -0
  60. data/templates/instiki/content/Bug%3A%20Duplicate%20links%2Dto%20a%20page%20sometimes%20appear.textile +1 -1
  61. data/templates/instiki/content/Bug%3A%20External%20links%20incorrectly%20include%20trailing%20pu.textile +1 -1
  62. data/templates/instiki/content/Bug%3A%20No%20robots%2Etxt%20or%20favicon%2Eico.textile +1 -1
  63. data/templates/instiki/content/Bug%3A%20Page%20titles%20cannot%20have%20html%20tags%20in%20them.textile +1 -1
  64. data/templates/instiki/content/Bug%3A%20Punctuation%20in%20page%20titles%20still%20problematic.textile +7 -0
  65. data/templates/instiki/content/Bug%3A%20Search%20includes%20leading%20and%20trailing%20spaces.textile +1 -0
  66. data/templates/instiki/content/Bug%3A%20Search%20inluced%20leading%20and%20trailing%20spaces.textile +1 -0
  67. data/templates/instiki/content/Bug%3A%20no%20superclass%20method%20%60%5Fdeprecated%5Fbase64.textile +1 -0
  68. data/templates/instiki/content/Bug%3A%20notextile%20does%20not%20prevent%20page%20inserts.textile +1 -0
  69. data/templates/instiki/content/Fixed%20Bug%3A%20%5BFATAL%5D%20When%20renaming%20upload%20%2F%20p.textile +34 -0
  70. data/templates/instiki/content/Fixed%20Bug%3A%20Duplicate%20links%2Dto%20a%20page%20sometimes%20.textile +3 -0
  71. data/templates/instiki/content/Fixed%20Bug%3A%20External%20links%20incorrectly%20include%20trail.textile +3 -0
  72. data/templates/instiki/content/Fixed%20Bug%3A%20No%20robots%2Etxt%20or%20favicon%2Eico.textile +4 -0
  73. data/templates/instiki/content/Fixed%20Bug%3A%20Search%20includes%20leading%20and%20trailing%20s.textile +3 -0
  74. data/templates/instiki/content/Fixed%20Bug%3A%20no%20superclass%20method%20%60%5Fdeprecated%5Fba.textile +3 -0
  75. data/templates/instiki/content/Home%20Page.textile +2 -2
  76. data/templates/instiki/content/How%20to%20administrate%20this%20wiki.textile +1 -1
  77. data/templates/instiki/content/How%20to%20report%20a%20bug.textile +8 -0
  78. data/templates/instiki/content/Instructions%20and%20Howtos.textile +1 -0
  79. data/templates/instiki/content/Known%20bugs.textile +4 -5
  80. data/templates/instiki/content/List%20of%20changes.textile +32 -0
  81. data/templates/instiki/content/Picture%20of%20a%20logo%20for%20the%20ruby%20language.textile +1 -0
  82. data/templates/instiki/content/Picture%20of%20powered%20by%20ruby%20logo.textile +1 -0
  83. data/templates/instiki/content/Planned%20Features.textile +19 -0
  84. data/templates/instiki/content/README.textile +22 -20
  85. data/templates/instiki/content/Recent%20Changes%20to%20This%20Site.textile +123 -8
  86. data/templates/instiki/content/SOKS%20features.textile +5 -1
  87. data/templates/instiki/content/Site%20Index.textile +11 -6
  88. data/templates/instiki/version.txt +1 -1
  89. data/templates/rails/content/Attached%20ruby%20logo.textile +1 -0
  90. data/templates/rails/content/Attached%20test%20thing.textile +1 -0
  91. data/templates/rails/content/Automatic%20Summaries.textile +1 -1
  92. data/templates/rails/content/Bug%3A%20%5BFATAL%5D%20When%20renaming%20upload%20%2F%20picture%2.textile +1 -0
  93. data/templates/rails/content/Bug%3A%20Duplicate%20links%2Dto%20a%20page%20sometimes%20appear.textile +1 -1
  94. data/templates/rails/content/Bug%3A%20External%20links%20incorrectly%20include%20trailing%20pu.textile +1 -1
  95. data/templates/rails/content/Bug%3A%20No%20robots%2Etxt%20or%20favicon%2Eico.textile +1 -1
  96. data/templates/rails/content/Bug%3A%20Page%20titles%20cannot%20have%20html%20tags%20in%20them.textile +1 -1
  97. data/templates/rails/content/Bug%3A%20Punctuation%20in%20page%20titles%20still%20problematic.textile +7 -0
  98. data/templates/rails/content/Bug%3A%20Search%20includes%20leading%20and%20trailing%20spaces.textile +1 -0
  99. data/templates/rails/content/Bug%3A%20Search%20inluced%20leading%20and%20trailing%20spaces.textile +1 -0
  100. data/templates/rails/content/Bug%3A%20no%20superclass%20method%20%60%5Fdeprecated%5Fbase64.textile +1 -0
  101. data/templates/rails/content/Bug%3A%20notextile%20does%20not%20prevent%20page%20inserts.textile +1 -0
  102. data/templates/rails/content/Fixed%20Bug%3A%20%5BFATAL%5D%20When%20renaming%20upload%20%2F%20p.textile +34 -0
  103. data/templates/rails/content/Fixed%20Bug%3A%20Duplicate%20links%2Dto%20a%20page%20sometimes%20.textile +3 -0
  104. data/templates/rails/content/Fixed%20Bug%3A%20External%20links%20incorrectly%20include%20trail.textile +3 -0
  105. data/templates/rails/content/Fixed%20Bug%3A%20No%20robots%2Etxt%20or%20favicon%2Eico.textile +4 -0
  106. data/templates/rails/content/Fixed%20Bug%3A%20Search%20includes%20leading%20and%20trailing%20s.textile +3 -0
  107. data/templates/rails/content/Fixed%20Bug%3A%20no%20superclass%20method%20%60%5Fdeprecated%5Fba.textile +3 -0
  108. data/templates/rails/content/Home%20Page.textile +2 -2
  109. data/templates/rails/content/How%20to%20administrate%20this%20wiki.textile +1 -1
  110. data/templates/rails/content/How%20to%20report%20a%20bug.textile +8 -0
  111. data/templates/rails/content/Instructions%20and%20Howtos.textile +1 -0
  112. data/templates/rails/content/Known%20bugs.textile +4 -5
  113. data/templates/rails/content/List%20of%20changes.textile +32 -0
  114. data/templates/rails/content/Picture%20of%20a%20logo%20for%20the%20ruby%20language.textile +1 -0
  115. data/templates/rails/content/Picture%20of%20powered%20by%20ruby%20logo.textile +1 -0
  116. data/templates/rails/content/Planned%20Features.textile +19 -0
  117. data/templates/rails/content/README.textile +22 -20
  118. data/templates/rails/content/Recent%20Changes%20to%20This%20Site.textile +123 -8
  119. data/templates/rails/content/SOKS%20features.textile +5 -1
  120. data/templates/rails/content/Site%20Index.textile +11 -6
  121. data/templates/rails/version.txt +1 -1
  122. metadata +64 -5
  123. data/contrib/redcloth-2.0.11.rb +0 -896
  124. /data/lib/{soks-helpers.rb → helpers/default-helpers.rb} +0 -0
@@ -1,896 +0,0 @@
1
- # vim:ts=4:sw=4:
2
- # = RedCloth - Textile for Ruby
3
- #
4
- # Homepage:: http://whytheluckystiff.net/ruby/redcloth/
5
- # Author:: why the lucky stiff (http://whytheluckystiff.net/)
6
- # Copyright:: (c) 2004 why the lucky stiff (and his puppet organizations.)
7
- # License:: BSD
8
- #
9
- # (see http://hobix.com/textile/ for a Textile Reference.)
10
- #
11
- # Based on (and also inspired by) both:
12
- #
13
- # PyTextile: http://diveintomark.org/projects/textile/textile.py.txt
14
- # Textism for PHP: http://www.textism.com/tools/textile/
15
- #
16
- #
17
-
18
- class String
19
- #
20
- # Flexible HTML escaping
21
- #
22
- def htmlesc!( mode )
23
- #gsub!( '&', '&' )
24
- gsub!( '"', '"' ) if mode != :NoQuotes
25
- gsub!( "'", ''' ) if mode == :Quotes
26
- gsub!('<', '&lt;')
27
- gsub!('>', '&gt;')
28
- end
29
- end
30
-
31
- # = RedCloth
32
- #
33
- # RedCloth is a Ruby library for converting Textile
34
- # into HTML.
35
- #
36
- # == What is Textile?
37
- #
38
- # Textile is a simple formatting style for text
39
- # documents, loosely based on some HTML conventions.
40
- #
41
- # == Sample Textile Text
42
- #
43
- # h2. This is a title
44
- #
45
- # h3. This is a subhead
46
- #
47
- # This is a bit of paragraph.
48
- #
49
- # bq. This is a blockquote.
50
- #
51
- # = Writing Textile
52
- #
53
- # A Textile document consists of paragraphs. Paragraphs
54
- # can be specially formatted by adding a small instruction
55
- # to the beginning of the paragraph.
56
- #
57
- # h[n]. Header of size [n].
58
- # bq. Blockquote.
59
- # # Numeric list.
60
- # * Bulleted list.
61
- #
62
- # == Quick Phrase Modifiers
63
- #
64
- # Quick phrase modifiers are also included, to allow formatting
65
- # of small portions of text within a paragraph.
66
- #
67
- # \_emphasis\_
68
- # \_\_italicized\_\_
69
- # \*strong\*
70
- # \*\*bold\*\*
71
- # ??citation??
72
- # -deleted text-
73
- # +inserted text+
74
- # ^superscript^
75
- # ~subscript~
76
- # @code@
77
- # %(classname)span%
78
- #
79
- # ==notextile== (leave text alone)
80
- #
81
- # == Links
82
- #
83
- # To make a hypertext link, put the link text in "quotation
84
- # marks" followed immediately by a colon and the URL of the link.
85
- #
86
- # Optional: text in (parentheses) following the link text,
87
- # but before the closing quotation mark, will become a Title
88
- # attribute for the link, visible as a tool tip when a cursor is above it.
89
- #
90
- # Example:
91
- #
92
- # "This is a link (This is a title) ":http://www.textism.com
93
- #
94
- # Will become:
95
- #
96
- # <a href="http://www.textism.com" title="This is a title">This is a link</a>
97
- #
98
- # == Images
99
- #
100
- # To insert an image, put the URL for the image inside exclamation marks.
101
- #
102
- # Optional: text that immediately follows the URL in (parentheses) will
103
- # be used as the Alt text for the image. Images on the web should always
104
- # have descriptive Alt text for the benefit of readers using non-graphical
105
- # browsers.
106
- #
107
- # Optional: place a colon followed by a URL immediately after the
108
- # closing ! to make the image into a link.
109
- #
110
- # Example:
111
- #
112
- # !http://www.textism.com/common/textist.gif(Textist)!
113
- #
114
- # Will become:
115
- #
116
- # <img src="http://www.textism.com/common/textist.gif" alt="Textist" />
117
- #
118
- # With a link:
119
- #
120
- # !/common/textist.gif(Textist)!:http://textism.com
121
- #
122
- # Will become:
123
- #
124
- # <a href="http://textism.com"><img src="/common/textist.gif" alt="Textist" /></a>
125
- #
126
- # == Defining Acronyms
127
- #
128
- # HTML allows authors to define acronyms via the tag. The definition appears as a
129
- # tool tip when a cursor hovers over the acronym. A crucial aid to clear writing,
130
- # this should be used at least once for each acronym in documents where they appear.
131
- #
132
- # To quickly define an acronym in Textile, place the full text in (parentheses)
133
- # immediately following the acronym.
134
- #
135
- # Example:
136
- #
137
- # ACLU(American Civil Liberties Union)
138
- #
139
- # Will become:
140
- #
141
- # <acronym title="American Civil Liberties Union">ACLU</acronym>
142
- #
143
- # == Adding Tables
144
- #
145
- # In Textile, simple tables can be added by seperating each column by
146
- # a pipe.
147
- #
148
- # |a|simple|table|row|
149
- # |And|Another|table|row|
150
- #
151
- # Attributes are defined by style definitions in parentheses.
152
- #
153
- # table(border:1px solid black).
154
- # (background:#ddd;color:red). |{}| | | |
155
- #
156
- # == Using RedCloth
157
- #
158
- # RedCloth is simply an extension of the String class, which can handle
159
- # Textile formatting. Use it like a String and output HTML with its
160
- # RedCloth#to_html method.
161
- #
162
- # doc = RedCloth.new "
163
- #
164
- # h2. Test document
165
- #
166
- # Just a simple test."
167
- #
168
- # puts doc.to_html
169
-
170
- class RedCloth < String
171
-
172
- VERSION = '2.0.11'
173
-
174
- #
175
- # Two accessor for setting security restrictions.
176
- #
177
- # This is a nice thing if you're using RedCloth for
178
- # formatting in public places (e.g. Wikis) where you
179
- # don't want users to abuse HTML for bad things.
180
- #
181
- # If +:filter_html+ is set, HTML which wasn't
182
- # created by the Textile processor will be escaped.
183
- #
184
- # If +:filter_styles+ is set, it will also disable
185
- # the style markup specifier. ('{color: red}')
186
- #
187
- attr_accessor :filter_html, :filter_styles
188
-
189
- #
190
- # Accessor for toggling line folding.
191
- #
192
- # If +:fold_lines+ is set, single newlines will
193
- # not be converted to break tags.
194
- #
195
- attr_accessor :fold_lines
196
-
197
- #
198
- # Returns a new RedCloth object, based on _string_ and
199
- # enforcing all the included _restrictions_.
200
- #
201
- # r = RedCloth.new( "h1. A <b>bold</b> man", [:filter_html] )
202
- # r.to_html
203
- # #=>"<h1>A &lt;b&gt;bold&lt;/b&gt; man</h1>"
204
- #
205
- def initialize( string, restrictions = [] )
206
- @lite = false
207
- restrictions.each { |r| method( "#{ r }=" ).call( true ) }
208
- super( string )
209
- end
210
-
211
- #
212
- # Generates HTML from the Textile contents. The _lite_ flag
213
- # may be used to honor only inline markup, ignoring lists, tables,
214
- # and block formatting.
215
- #
216
- # r = RedCloth.new( "And then? She *fell*!" )
217
- # r.to_html( true )
218
- # #=>"And then? She <strong>fell</strong>!"
219
- #
220
- def to_html( lite = nil )
221
-
222
- @lite = lite unless lite.nil?
223
-
224
- # make our working copy
225
- text = self.dup
226
-
227
- @urlrefs = {}
228
- @shelf = []
229
-
230
- incoming_entities text
231
- ## encode_entities text
232
- ## fix_entities text
233
- clean_white_space text
234
-
235
- get_refs text
236
-
237
- no_textile text
238
-
239
- inline text
240
-
241
- unless @lite
242
- fold text
243
- block text
244
- end
245
-
246
- retrieve text
247
-
248
- text.gsub!( /<\/?notextile>/, '' )
249
- text.gsub!( /x%x%/, '&#38;' )
250
- text.gsub!( /<br \/>/, "<br />\n" )
251
- text.strip!
252
- text
253
-
254
- end
255
-
256
- #######
257
- private
258
- #######
259
- #
260
- # Mapping of 8-bit ASCII codes to HTML numerical entity equivalents.
261
- # (from PyTextile)
262
- #
263
- TEXTILE_TAGS =
264
-
265
- [[128, 8364], [129, 0], [130, 8218], [131, 402], [132, 8222], [133, 8230],
266
- [134, 8224], [135, 8225], [136, 710], [137, 8240], [138, 352], [139, 8249],
267
- [140, 338], [141, 0], [142, 0], [143, 0], [144, 0], [145, 8216], [146, 8217],
268
- [147, 8220], [148, 8221], [149, 8226], [150, 8211], [151, 8212], [152, 732],
269
- [153, 8482], [154, 353], [155, 8250], [156, 339], [157, 0], [158, 0], [159, 376]].
270
-
271
- collect! do |a, b|
272
- [a.chr, ( b.zero? and "" or "&#{ b };" )]
273
- end
274
-
275
- #
276
- # Regular expressions to convert to HTML.
277
- #
278
- A_HLGN = /(?:(?:<>|<|>|\=|[()]+)+)/
279
- A_VLGN = /[\-^~]/
280
- C_CLAS = '(?:\([^)]+\))'
281
- C_LNGE = '(?:\[[^\]]+\])'
282
- C_STYL = '(?:\{[^}]+\})'
283
- S_CSPN = '(?:\\\\\d+)'
284
- S_RSPN = '(?:/\d+)'
285
- A = "(?:#{A_HLGN}?#{A_VLGN}?|#{A_VLGN}?#{A_HLGN}?)"
286
- S = "(?:#{S_CSPN}?#{S_RSPN}|#{S_RSPN}?#{S_CSPN}?)"
287
- C = "(?:#{C_CLAS}?#{C_STYL}?#{C_LNGE}?|#{C_STYL}?#{C_LNGE}?#{C_CLAS}?|#{C_LNGE}?#{C_STYL}?#{C_CLAS}?)"
288
- # PUNCT = Regexp::quote( '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' )
289
- PUNCT = Regexp::quote( '!"#$%&\'*+,-./:;=?@\\^_`|~' )
290
- HYPERLINK = '(\S+?)([^\w\s/;=\?]*?)(\s|$)'
291
-
292
- GLYPHS = [
293
- # [ /([^\s\[{(>])?\'([dmst]\b|ll\b|ve\b|\s|:|$)/, '\1&#8217;\2' ], # single closing
294
- [ /([^\s\[{(>])\'/, '\1&#8217;' ], # single closing
295
- [ /\'(?=\s|s\b|[#{PUNCT}])/, '&#8217;' ], # single closing
296
- [ /\'/, '&#8216;' ], # single opening
297
- # [ /([^\s\[{(])?"(\s|:|$)/, '\1&#8221;\2' ], # double closing
298
- [ /([^\s\[{(>])"/, '\1&#8221;' ], # double closing
299
- [ /"(?=\s|[#{PUNCT}])/, '&#8221;' ], # double closing
300
- [ /"/, '&#8220;' ], # double opening
301
- [ /\b( )?\.{3}/, '\1&#8230;' ], # ellipsis
302
- [ /\b([A-Z][A-Z0-9]{2,})\b(?:[(]([^)]*)[)])/, '<acronym title="\2">\1</acronym>' ], # 3+ uppercase acronym
303
- [ /(^|[^"][>\s])([A-Z][A-Z0-9 ]{2,})([^<a-z0-9]|$)/, '\1<span class="caps">\2</span>\3' ], # 3+ uppercase caps
304
- [ /(\.\s)?\s?--\s?/, '\1&#8212;' ], # em dash
305
- [ /\s->\s/, ' &rarr; ' ], # en dash
306
- [ /\s-\s/, ' &#8211; ' ], # en dash
307
- [ /(\d+) ?x ?(\d+)/, '\1&#215;\2' ], # dimension sign
308
- [ /\b ?[(\[]TM[\])]/i, '&#8482;' ], # trademark
309
- [ /\b ?[(\[]R[\])]/i, '&#174;' ], # registered
310
- [ /\b ?[(\[]C[\])]/i, '&#169;' ] # copyright
311
- ]
312
-
313
- I_ALGN_VALS = {
314
- '<' => 'left',
315
- '=' => 'center',
316
- '>' => 'right'
317
- }
318
-
319
- H_ALGN_VALS = {
320
- '<' => 'left',
321
- '=' => 'center',
322
- '>' => 'right',
323
- '<>' => 'justify'
324
- }
325
-
326
- V_ALGN_VALS = {
327
- '^' => 'top',
328
- '-' => 'middle',
329
- '~' => 'bottom'
330
- }
331
-
332
- QTAGS = [
333
- ['**', 'b'],
334
- ['*', 'strong'],
335
- ['??', 'cite'],
336
- ['-', 'del'],
337
- ['__', 'i'],
338
- ['_', 'em'],
339
- ['%', 'span'],
340
- ['+', 'ins'],
341
- ['^', 'sup'],
342
- ['~', 'sub']
343
- ].collect do |rc, ht|
344
- ttr = Regexp.quote(rc)
345
- punct = PUNCT.sub( Regexp::quote(rc), '' )
346
- re = /(^|[\s\>#{punct}{(\[])
347
- #{ttr}
348
- (#{C})
349
- (?::(\S+?))?
350
- ([^\s#{ttr}]+?(?:[^\n]|\n(?!\n))*?)
351
- ([#{punct}]*?)
352
- #{ttr}
353
- (?=[\s\])}<#{punct}]|$)/xm
354
- [re, ht]
355
- end
356
-
357
- def pgl( text )
358
- GLYPHS.each do |re, resub|
359
- text.gsub! re, resub
360
- end
361
- end
362
-
363
- def pba( text_in, element = "" )
364
-
365
- return '' unless text_in
366
-
367
- style = []
368
- text = text_in.dup
369
- if element == 'td'
370
- colspan = $1 if text =~ /\\(\d+)/
371
- rowspan = $1 if text =~ /\/(\d+)/
372
- style << "vertical-align:#{ v_align( $& ) };" if text =~ A_VLGN
373
- end
374
-
375
- style << "#{ $1 };" if not @filter_styles and
376
- text.sub!( /\{([^}]*)\}/, '' )
377
-
378
- lang = $1 if
379
- text.sub!( /\[([^)]+?)\]/, '' )
380
-
381
- cls = $1 if
382
- text.sub!( /\(([^()]+?)\)/, '' )
383
-
384
- style << "padding-left:#{ $1.length }em;" if
385
- text.sub!( /([(]+)/, '' )
386
-
387
- style << "padding-right:#{ $1.length }em;" if text.sub!( /([)]+)/, '' )
388
-
389
- style << "text-align:#{ h_align( $& ) };" if text =~ A_HLGN
390
-
391
- cls, id = $1, $2 if cls =~ /^(.*?)#(.*)$/
392
-
393
- atts = ''
394
- atts << " style=\"#{ style.join }\"" unless style.empty?
395
- atts << " class=\"#{ cls }\"" unless cls.to_s.empty?
396
- atts << " lang=\"#{ lang }\"" if lang
397
- atts << " id=\"#{ id }\"" if id
398
- atts << " colspan=\"#{ colspan }\"" if colspan
399
- atts << " rowspan=\"#{ rowspan }\"" if rowspan
400
-
401
- atts
402
- end
403
-
404
- TABLE_RE = /^(?:table(_?#{S}#{A}#{C})\. ?\n)?^(#{A}#{C}\.? ?\|.*?\|)(\n\n|\Z)/m
405
-
406
- def table( text )
407
- text.gsub!( TABLE_RE ) do |matches|
408
-
409
- tatts, fullrow = $~[1..2]
410
- tatts = pba( tatts, 'table' )
411
- rows = []
412
-
413
- fullrow.
414
- split( /\|$/m ).
415
- delete_if { |x| x.empty? }.
416
- each do |row|
417
-
418
- ratts, row = pba( $1, 'tr' ), $2 if row =~ /^(#{A}#{C}\. )(.*)/m
419
-
420
- cells = []
421
- row.split( '|' ).each do |cell|
422
- ctyp = 'd'
423
- ctyp = 'h' if cell =~ /^_/
424
-
425
- catts = ''
426
- catts, cell = pba( $1, 'td' ), $2 if cell =~ /^(_?#{S}#{A}#{C}\. )(.*)/
427
-
428
- unless cell.strip.empty?
429
- cells << "\t\t\t<t#{ ctyp }#{ catts }>#{ cell }</t#{ ctyp }>"
430
- end
431
- end
432
- rows << "\t\t<tr#{ ratts }>\n#{ cells.join( "\n" ) }\n\t\t</tr>"
433
- end
434
- "\t<table#{ tatts }>\n#{ rows.join( "\n" ) }\n\t</table>\n\n"
435
- end
436
- end
437
-
438
- LISTS_RE = /^([#*]+?#{C} .*?)$(?![^#*])/m
439
- LISTS_CONTENT_RE = /^([#*]+)(#{A}#{C}) (.*)$/m
440
-
441
- def lists( text )
442
- text.gsub!( LISTS_RE ) do |match|
443
- lines = match.split( /\n/ )
444
- last_line = -1
445
- depth = []
446
- lines.each_with_index do |line, line_id|
447
- if line =~ LISTS_CONTENT_RE
448
- tl,atts,content = $~[1..3]
449
- if depth.last
450
- if depth.last.length > tl.length
451
- (depth.length - 1).downto(0) do |i|
452
- break if depth[i].length == tl.length
453
- lines[line_id - 1] << "</li>\n\t</#{ lT( depth[i] ) }l>\n\t"
454
- depth.pop
455
- end
456
- end
457
- if depth.last.length == tl.length
458
- lines[line_id - 1] << '</li>'
459
- end
460
- end
461
- unless depth.last == tl
462
- depth << tl
463
- atts = pba( atts )
464
- lines[line_id] = "\t<#{ lT(tl) }l#{ atts }>\n\t<li>#{ content }"
465
- else
466
- lines[line_id] = "\t\t<li>#{ content }"
467
- end
468
- last_line = line_id
469
-
470
- elsif line =~ /^\s+\S/
471
- last_line = line_id
472
- elsif line_id - last_line < 2 and line =~ /^\S/
473
- last_line = line_id
474
- end
475
- if line_id - last_line > 1 or line_id == lines.length - 1
476
- depth.delete_if do |v|
477
- lines[last_line] << "</li>\n\t</#{ lT( v ) }l>"
478
- end
479
- end
480
- end
481
- lines.join( "\n" )
482
- end
483
- end
484
-
485
- def lT( text )
486
- text =~ /\#$/ ? 'o' : 'u'
487
- end
488
-
489
- def fold( text )
490
- text.gsub!( /(.+)\n(?![#*\s|])/, "\\1#{ @fold_lines ? ' ' : '<br />' }" )
491
- end
492
-
493
- BLOCK_RE = ['bq','h[1-6]','fn\d+','p'].collect!{|stag|
494
- [stag,
495
- /^(#{ stag })(#{A}#{C})\.(?::(\S+))? (.*)$/]
496
- }
497
-
498
- def block( text )
499
- pre = false
500
- find = ['bq','h[1-6]','fn\d+','p']
501
-
502
- lines = text.split( /\n/ ) + [' ']
503
- new_text =
504
- lines.collect do |line|
505
- pre = true if line =~ /<(pre|notextile)[^>]*>/i
506
- BLOCK_RE.each do |stag, ctag|
507
- line.gsub!( ctag ) do |m|
508
- tag,atts,cite,content = $~[1..4]
509
-
510
- atts = pba( atts )
511
-
512
- if tag =~ /fn(\d+)/
513
- tag = 'p';
514
- atts << " id=\"fn#{ $1 }\""
515
- content = "<sup>#{ $1 }</sup> #{ content }"
516
- end
517
-
518
- start = "\t<#{ tag }"
519
- tend = "</#{ tag }>"
520
-
521
- if tag == "bq"
522
- cite = check_refs( cite )
523
- cite = " cite=\"#{ cite }\"" if cite
524
- start = "\t<blockquote#{ cite }>\n\t\t<p";
525
- tend = "</p>\n\t</blockquote>";
526
- end
527
-
528
- "#{ start }#{ atts }>#{ content }#{ tend }"
529
- end unless pre
530
- end
531
-
532
- # line.gsub!( /^(?!\t|<\/?div|<\/?pre|<\/?notextile|<\/?code|$| )(.*)/, "\t<p>\\1</p>" ) unless pre
533
-
534
- line.gsub!( /^(?!\t|<\/?div|<\/?pre|<\/?notextile|<\/?code| )(.*)/, "\t<p>\\1</p>" ) unless pre
535
-
536
- line.gsub!( "<br />", "\n" ) if pre
537
- pre = false if line =~ /<\/(pre|notextile)>/i
538
-
539
- line
540
- end.join( "\n" )
541
- text.replace( new_text )
542
- end
543
-
544
- def span( text )
545
- QTAGS.each do |ttr, ht|
546
- text.gsub!(ttr) do |m|
547
-
548
- start,atts,cite,content,tend = $~[1..5]
549
- atts = pba( atts )
550
- atts << " cite=\"#{ cite }\"" if cite
551
-
552
- "#{ start }<#{ ht }#{ atts }>#{ content }#{ tend }</#{ ht }>"
553
-
554
- end
555
- end
556
- end
557
-
558
- LINK_RE = /
559
- ([\s\[{(]|[#{PUNCT}])? # $pre
560
- " # start
561
- (#{C}) # $atts
562
- ([^"]+?) # $text
563
- \s?
564
- (?:\(([^)]+?)\)(?="))? # $title
565
- ":
566
- (\S+?) # $url
567
- (\/)? # $slash
568
- ([^\w\/;]*?) # $post
569
- (?=<|\s|$)
570
- /x
571
-
572
- def links( text )
573
- text.gsub!( LINK_RE ) do |m|
574
- pre,atts,text,title,url,slash,post = $~[1..7]
575
-
576
- url = check_refs( url )
577
-
578
- atts = pba( atts )
579
- atts << " title=\"#{ title }\"" if title
580
- atts = shelve( atts ) if atts
581
-
582
- "#{ pre }<a href=\"#{ url }#{ slash }\"#{ atts }>#{ text }</a>#{ post }"
583
- end
584
- end
585
-
586
- REFS_RE = /(^|\s)\[(.+?)\]((?:http:\/\/|javascript:|ftp:\/\/|\/)\S+?)(?=\s|$)/
587
-
588
- def get_refs( text )
589
- text.gsub!( REFS_RE ) do |m|
590
- flag, url = $~[2..3]
591
- @urlrefs[flag] = url
592
- nil
593
- end
594
- end
595
-
596
- def check_refs( text )
597
- @urlrefs[text] || text
598
- end
599
-
600
- IMAGE_RE = /
601
- \! # opening
602
- (\<|\=|\>)? # optional alignment atts
603
- (#{C}) # optional style,class atts
604
- (?:\. )? # optional dot-space
605
- ([^\s(!]+?) # presume this is the src
606
- \s? # optional space
607
- (?:\(((?:[^\(\)]|\([^\)]+\))+?)\))? # optional title
608
- \! # closing
609
- (?::#{ HYPERLINK })? # optional href
610
- /x
611
-
612
- def image( text )
613
- text.gsub!( IMAGE_RE ) do |m|
614
- algn,atts,url,title,href,href_a1,href_a2 = $~[1..7]
615
- atts = pba( atts )
616
- atts << " align=\"#{ i_align( algn ) }\"" if algn
617
- atts << " title=\"#{ title }\"" if title
618
- atts << " alt=\"#{ title }\""
619
- # size = @getimagesize($url);
620
- # if($size) $atts.= " $size[3]";
621
-
622
- href = check_refs( href ) if href
623
- url = check_refs( url )
624
- atts << " border=\"0\"" if href
625
-
626
- out = ''
627
- out << "<a href=\"#{ href }\">" if href
628
- out << "<img src=\"#{ url }\"#{ atts } />"
629
- out << "</a>#{ href_a1 }#{ href_a2 }" if href
630
-
631
- out
632
- end
633
- end
634
-
635
- CODE_RE = /
636
- (^|[\s>#{PUNCT}{(\[]) # 1 open bracket?
637
- @ # opening
638
- (?:\|(\w+?)\|)? # 2 language
639
- (\S(?:[^\n]|\n(?!\n))*?) # 3 code
640
- @ # closing
641
- (?=[\s\]}\)<#{PUNCT}]|$) # 4 closing bracket?
642
- /x
643
-
644
- def code( text )
645
- text.gsub!( CODE_RE ) do |m|
646
- before,lang,code,after = $~[1..4]
647
- lang = " language=\"#{ lang }\"" if lang
648
- "#{ before }<code#{ lang }>#{ code }</code>#{ after }"
649
- end
650
- end
651
-
652
- def shelve( val )
653
- @shelf << val
654
- " <#{ @shelf.length }>"
655
- end
656
-
657
- def retrieve( text )
658
- @shelf.each_with_index do |r, i|
659
- text.gsub!( " <#{ i + 1 }>", r )
660
- end
661
- end
662
-
663
- def incoming_entities( text )
664
- ## turn any incoming ampersands into a dummy character for now.
665
- ## This uses a negative lookahead for alphanumerics followed by a semicolon,
666
- ## implying an incoming html entity, to be skipped
667
-
668
- text.gsub!( /&(?![#a-z0-9]+;)/i, "x%x%" )
669
- end
670
-
671
- def encode_entities( text )
672
- ## Convert high and low ascii to entities.
673
- # if $-K == "UTF-8"
674
- # encode_high( text )
675
- # else
676
- text.htmlesc!( :NoQuotes )
677
- # end
678
- end
679
-
680
- def fix_entities( text )
681
- ## de-entify any remaining angle brackets or ampersands
682
- text.gsub!( "&gt;", ">" )
683
- text.gsub!( "&lt;", "<" )
684
- text.gsub!( "&amp;", "&" )
685
- end
686
-
687
- def clean_white_space( text )
688
- text.gsub!( /\r\n/, "\n" )
689
- text.gsub!( /\t/, '' )
690
- text.gsub!( /\n{3,}/, "\n\n" )
691
- text.gsub!( /\n *\n/, "\n\n" )
692
- text.gsub!( /"$/, "\" " )
693
- end
694
-
695
- def no_textile( text )
696
- text.gsub!( /(^|\s)==(.*?)==(\s|$)?/,
697
- '\1<notextile>\2</notextile>\3' )
698
- end
699
-
700
- def footnote_ref( text )
701
- text.gsub!( /\b\[([0-9]+?)\](\s)?/,
702
- '<sup><a href="#fn\1">\1</a></sup>\2' )
703
- end
704
-
705
- OFFTAGS = /(code|pre|kbd|notextile)/
706
- OFFTAG_MATCH = /(?:(<\/#{ OFFTAGS }>)|(<#{ OFFTAGS }[^>]*>))(.*?)(?=<\/?#{ OFFTAGS }>|\Z)/mi
707
- OFFTAG_OPEN = /<#{ OFFTAGS }/
708
- OFFTAG_CLOSE = /<\/?#{ OFFTAGS }/
709
- HASTAG_MATCH = /(<\/?\w[^\n]*?>)/m
710
- ALLTAG_MATCH = /(<\/?\w[^\n]*?>)|.*?(?=<\/?\w[^\n]*?>|$)/m
711
-
712
- def glyphs( text, level = 0 )
713
- if text !~ HASTAG_MATCH
714
- pgl text
715
- footnote_ref text
716
- else
717
- codepre = 0
718
- text.gsub!( ALLTAG_MATCH ) do |line|
719
- ## matches are off if we're between <code>, <pre> etc.
720
- if $1
721
- if @filter_html
722
- line.htmlesc!( :NoQuotes )
723
- elsif line =~ OFFTAG_OPEN
724
- codepre += 1
725
- elsif line =~ OFFTAG_CLOSE
726
- codepre -= 1
727
- codepre = 0 if codepre < 0
728
- end
729
- ## do htmlspecial if between <code>
730
- elsif codepre.zero?
731
- glyphs( line, level + 1 )
732
- else
733
- line.htmlesc!( :NoQuotes )
734
- end
735
- ## p [level, codepre, orig_line, line]
736
-
737
- line
738
- end
739
- end
740
- end
741
-
742
- def rip_offtags( text )
743
- pre_list = []
744
- if text =~ /<.*>/
745
- ## strip and encode <pre> content
746
- codepre, used_offtags = 0, {}
747
- text.gsub!( OFFTAG_MATCH ) do |line|
748
- if $3
749
- offtag, aftertag = $4, $5
750
- codepre += 1
751
- used_offtags[offtag] = true
752
- if codepre - used_offtags.length > 0
753
- line.htmlesc!( :NoQuotes )
754
- pre_list.last << line
755
- line = ""
756
- else
757
- aftertag.htmlesc!( :NoQuotes ) if aftertag
758
- line = "<redpre##{ pre_list.length }>"
759
- pre_list << "#{ $3 }#{ aftertag }"
760
- end
761
- elsif $1 and codepre > 0
762
- if codepre - used_offtags.length > 0
763
- line.htmlesc!( :NoQuotes )
764
- pre_list.last << line
765
- line = ""
766
- end
767
- codepre -= 1 unless codepre.zero?
768
- used_offtags = {} if codepre.zero?
769
- end
770
- line
771
- end
772
- end
773
- pre_list
774
- end
775
-
776
- def smooth_offtags( text, pre_list )
777
- unless pre_list.empty?
778
- ## replace <pre> content
779
- text.gsub!( /<redpre#(\d+)>/ ) { pre_list[$1.to_i] }
780
- end
781
- end
782
-
783
- def inline( text )
784
- text.gsub!( /"\z/, "\" " )
785
- pre_list = rip_offtags text
786
-
787
- ## apply inline markup
788
- unless @lite
789
- lists text
790
- table text
791
- end
792
-
793
- image text
794
- links text
795
- code text
796
- span text
797
-
798
- ## replace entities
799
- glyphs text
800
- smooth_offtags text, pre_list
801
- end
802
-
803
- def i_align( text )
804
- I_ALGN_VALS[text]
805
- end
806
-
807
- def h_align( text )
808
- H_ALGN_VALS[text]
809
- end
810
-
811
- def v_align( text )
812
- V_ALGN_VALS[text]
813
- end
814
-
815
- def encode_high( text )
816
- ## mb_encode_numericentity($text, $cmap, $charset);
817
- end
818
-
819
- def decode_high( text )
820
- ## mb_decode_numericentity($text, $cmap, $charset);
821
- end
822
-
823
- def textile_popup_help( name, helpvar, windowW, windowH )
824
- ' <a target="_blank" href="http://www.textpattern.com/help/?item=' + helpvar + '" onclick="window.open(this.href, \'popupwindow\', \'width=' + windowW + ',height=' + windowH + ',scrollbars,resizable\'); return false;">' + name + '</a><br />'
825
- end
826
-
827
- CMAP = [
828
- 160, 255, 0, 0xffff,
829
- 402, 402, 0, 0xffff,
830
- 913, 929, 0, 0xffff,
831
- 931, 937, 0, 0xffff,
832
- 945, 969, 0, 0xffff,
833
- 977, 978, 0, 0xffff,
834
- 982, 982, 0, 0xffff,
835
- 8226, 8226, 0, 0xffff,
836
- 8230, 8230, 0, 0xffff,
837
- 8242, 8243, 0, 0xffff,
838
- 8254, 8254, 0, 0xffff,
839
- 8260, 8260, 0, 0xffff,
840
- 8465, 8465, 0, 0xffff,
841
- 8472, 8472, 0, 0xffff,
842
- 8476, 8476, 0, 0xffff,
843
- 8482, 8482, 0, 0xffff,
844
- 8501, 8501, 0, 0xffff,
845
- 8592, 8596, 0, 0xffff,
846
- 8629, 8629, 0, 0xffff,
847
- 8656, 8660, 0, 0xffff,
848
- 8704, 8704, 0, 0xffff,
849
- 8706, 8707, 0, 0xffff,
850
- 8709, 8709, 0, 0xffff,
851
- 8711, 8713, 0, 0xffff,
852
- 8715, 8715, 0, 0xffff,
853
- 8719, 8719, 0, 0xffff,
854
- 8721, 8722, 0, 0xffff,
855
- 8727, 8727, 0, 0xffff,
856
- 8730, 8730, 0, 0xffff,
857
- 8733, 8734, 0, 0xffff,
858
- 8736, 8736, 0, 0xffff,
859
- 8743, 8747, 0, 0xffff,
860
- 8756, 8756, 0, 0xffff,
861
- 8764, 8764, 0, 0xffff,
862
- 8773, 8773, 0, 0xffff,
863
- 8776, 8776, 0, 0xffff,
864
- 8800, 8801, 0, 0xffff,
865
- 8804, 8805, 0, 0xffff,
866
- 8834, 8836, 0, 0xffff,
867
- 8838, 8839, 0, 0xffff,
868
- 8853, 8853, 0, 0xffff,
869
- 8855, 8855, 0, 0xffff,
870
- 8869, 8869, 0, 0xffff,
871
- 8901, 8901, 0, 0xffff,
872
- 8968, 8971, 0, 0xffff,
873
- 9001, 9002, 0, 0xffff,
874
- 9674, 9674, 0, 0xffff,
875
- 9824, 9824, 0, 0xffff,
876
- 9827, 9827, 0, 0xffff,
877
- 9829, 9830, 0, 0xffff,
878
- 338, 339, 0, 0xffff,
879
- 352, 353, 0, 0xffff,
880
- 376, 376, 0, 0xffff,
881
- 710, 710, 0, 0xffff,
882
- 732, 732, 0, 0xffff,
883
- 8194, 8195, 0, 0xffff,
884
- 8201, 8201, 0, 0xffff,
885
- 8204, 8207, 0, 0xffff,
886
- 8211, 8212, 0, 0xffff,
887
- 8216, 8218, 0, 0xffff,
888
- 8218, 8218, 0, 0xffff,
889
- 8220, 8222, 0, 0xffff,
890
- 8224, 8225, 0, 0xffff,
891
- 8240, 8240, 0, 0xffff,
892
- 8249, 8250, 0, 0xffff,
893
- 8364, 8364, 0, 0xffff
894
- ]
895
- end
896
-