gitlab-gollum-lib 1.1.0 → 4.2.7
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.
- checksums.yaml +4 -4
- data/Gemfile +1 -3
- data/HISTORY.md +25 -0
- data/LICENSE +1 -1
- data/README.md +24 -312
- data/Rakefile +32 -16
- data/gemspec.rb +110 -0
- data/gollum-lib.gemspec +8 -75
- data/gollum-lib_java.gemspec +4 -0
- data/lib/gollum-lib.rb +18 -6
- data/lib/gollum-lib/blob_entry.rb +10 -9
- data/lib/gollum-lib/committer.rb +37 -30
- data/lib/gollum-lib/file.rb +71 -15
- data/lib/gollum-lib/file_view.rb +53 -48
- data/lib/gollum-lib/filter.rb +78 -0
- data/lib/gollum-lib/filter/code.rb +145 -0
- data/lib/gollum-lib/filter/emoji.rb +39 -0
- data/lib/gollum-lib/filter/macro.rb +57 -0
- data/lib/gollum-lib/filter/metadata.rb +29 -0
- data/lib/gollum-lib/filter/plain_text.rb +16 -0
- data/lib/gollum-lib/filter/plantuml.rb +176 -0
- data/lib/gollum-lib/filter/remote_code.rb +63 -0
- data/lib/gollum-lib/filter/render.rb +20 -0
- data/lib/gollum-lib/filter/sanitize.rb +18 -0
- data/lib/gollum-lib/filter/tags.rb +327 -0
- data/lib/gollum-lib/filter/toc.rb +134 -0
- data/lib/gollum-lib/filter/wsd.rb +54 -0
- data/lib/gollum-lib/git_access.rb +30 -32
- data/lib/gollum-lib/gitcode.rb +16 -16
- data/lib/gollum-lib/helpers.rb +3 -3
- data/lib/gollum-lib/hook.rb +35 -0
- data/lib/gollum-lib/macro.rb +43 -0
- data/lib/gollum-lib/macro/all_pages.rb +11 -0
- data/lib/gollum-lib/macro/global_toc.rb +12 -0
- data/lib/gollum-lib/macro/navigation.rb +20 -0
- data/lib/gollum-lib/macro/series.rb +48 -0
- data/lib/gollum-lib/markup.rb +95 -572
- data/lib/gollum-lib/markups.rb +9 -3
- data/lib/gollum-lib/page.rb +109 -80
- data/lib/gollum-lib/pagination.rb +1 -1
- data/lib/gollum-lib/sanitization.rb +75 -75
- data/lib/gollum-lib/version.rb +5 -0
- data/lib/gollum-lib/wiki.rb +287 -129
- metadata +237 -92
- data/CHANGELOG +0 -2
- data/VERSION +0 -1
- data/lib/gollum-lib/grit_ext.rb +0 -20
- data/lib/gollum-lib/remote_code.rb +0 -39
- data/lib/gollum-lib/web_sequence_diagram.rb +0 -44
data/lib/gollum-lib/markups.rb
CHANGED
@@ -1,14 +1,20 @@
|
|
1
1
|
# ~*~ encoding: utf-8 ~*~
|
2
2
|
module Gollum
|
3
3
|
class Markup
|
4
|
+
|
5
|
+
GitHub::Markup::Markdown::MARKDOWN_GEMS['kramdown'] = proc { |content|
|
6
|
+
Kramdown::Document.new(content, :auto_ids => false, :input => "markdown").to_html
|
7
|
+
}
|
8
|
+
|
4
9
|
register(:markdown, "Markdown", :regexp => /md|mkdn?|mdown|markdown/)
|
5
10
|
register(:textile, "Textile")
|
6
11
|
register(:rdoc, "RDoc")
|
7
12
|
register(:org, "Org-mode")
|
8
|
-
register(:creole, "Creole")
|
13
|
+
register(:creole, "Creole", :reverse_links => true)
|
9
14
|
register(:rest, "reStructuredText", :regexp => /re?st(\.txt)?/)
|
10
15
|
register(:asciidoc, "AsciiDoc")
|
11
|
-
register(:mediawiki, "MediaWiki", :regexp => /(media)?wiki
|
16
|
+
register(:mediawiki, "MediaWiki", :regexp => /(media)?wiki/, :reverse_links => true)
|
12
17
|
register(:pod, "Pod")
|
18
|
+
register(:txt, "Plain Text")
|
13
19
|
end
|
14
|
-
end
|
20
|
+
end
|
data/lib/gollum-lib/page.rb
CHANGED
@@ -4,7 +4,9 @@ module Gollum
|
|
4
4
|
include Pagination
|
5
5
|
|
6
6
|
Wiki.page_class = self
|
7
|
-
|
7
|
+
|
8
|
+
SUBPAGENAMES = [:header, :footer, :sidebar]
|
9
|
+
|
8
10
|
# Sets a Boolean determing whether this page is a historical version.
|
9
11
|
#
|
10
12
|
# Returns nothing.
|
@@ -23,7 +25,7 @@ module Gollum
|
|
23
25
|
# Returns e.g. ["Home", :markdown], or [] if the extension is unregistered
|
24
26
|
def self.parse_filename(filename)
|
25
27
|
return [] unless filename =~ /^(.+)\.([a-zA-Z]\w*)$/i
|
26
|
-
pref, ext =
|
28
|
+
pref, ext = Regexp.last_match[1], Regexp.last_match[2]
|
27
29
|
|
28
30
|
Gollum::Markup.formats.each_pair do |name, format|
|
29
31
|
return [pref, name] if ext =~ format[:regexp]
|
@@ -84,10 +86,11 @@ module Gollum
|
|
84
86
|
#
|
85
87
|
# Returns a newly initialized Gollum::Page.
|
86
88
|
def initialize(wiki)
|
87
|
-
@wiki
|
88
|
-
@blob
|
89
|
-
@
|
90
|
-
@
|
89
|
+
@wiki = wiki
|
90
|
+
@blob = nil
|
91
|
+
@formatted_data = nil
|
92
|
+
@doc = nil
|
93
|
+
@parent_page = nil
|
91
94
|
end
|
92
95
|
|
93
96
|
# Public: The on-disk filename of the page including extension.
|
@@ -139,20 +142,27 @@ module Gollum
|
|
139
142
|
# Returns the String url_path
|
140
143
|
def url_path
|
141
144
|
path = if self.path.include?('/')
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
145
|
+
self.path.sub(/\/[^\/]+$/, '/')
|
146
|
+
else
|
147
|
+
''
|
148
|
+
end
|
146
149
|
|
147
150
|
path << Page.cname(self.name, '-', '-')
|
148
151
|
path
|
149
152
|
end
|
150
153
|
|
154
|
+
# Public: The display form of the url path required to reach this page within the repo.
|
155
|
+
#
|
156
|
+
# Returns the String url_path
|
157
|
+
def url_path_display
|
158
|
+
url_path.gsub("-", " ")
|
159
|
+
end
|
160
|
+
|
151
161
|
# Public: Defines title for page.rb
|
152
162
|
#
|
153
163
|
# Returns the String title
|
154
164
|
def url_path_title
|
155
|
-
metadata_title ||
|
165
|
+
metadata_title || url_path_display
|
156
166
|
end
|
157
167
|
|
158
168
|
# Public: Metadata title
|
@@ -173,7 +183,7 @@ module Gollum
|
|
173
183
|
#
|
174
184
|
# Returns the String url_path
|
175
185
|
def escaped_url_path
|
176
|
-
CGI.escape(self.url_path).gsub('%2F','/')
|
186
|
+
CGI.escape(self.url_path).gsub('%2F', '/')
|
177
187
|
end
|
178
188
|
|
179
189
|
# Public: The raw contents of the page.
|
@@ -208,11 +218,19 @@ module Gollum
|
|
208
218
|
# encoding - Encoding Constant or String.
|
209
219
|
#
|
210
220
|
# Returns the String data.
|
211
|
-
def formatted_data(encoding = nil, &block)
|
212
|
-
|
213
|
-
|
214
|
-
|
221
|
+
def formatted_data(encoding = nil, include_levels = 10, &block)
|
222
|
+
return nil unless @blob
|
223
|
+
|
224
|
+
if @formatted_data && @doc then
|
225
|
+
yield @doc if block_given?
|
226
|
+
else
|
227
|
+
@formatted_data = markup_class.render(historical?, encoding, include_levels) do |doc|
|
228
|
+
@doc = doc
|
229
|
+
yield doc if block_given?
|
230
|
+
end
|
215
231
|
end
|
232
|
+
|
233
|
+
@formatted_data
|
216
234
|
end
|
217
235
|
|
218
236
|
# Public: The table of contents of the page.
|
@@ -220,7 +238,7 @@ module Gollum
|
|
220
238
|
# formatted_data - page already marked up in html.
|
221
239
|
#
|
222
240
|
# Returns the String data.
|
223
|
-
def toc_data
|
241
|
+
def toc_data
|
224
242
|
return @parent_page.toc_data if @parent_page and @sub_page
|
225
243
|
formatted_data if markup_class.toc == nil
|
226
244
|
markup_class.toc
|
@@ -229,7 +247,7 @@ module Gollum
|
|
229
247
|
# Public: Embedded metadata.
|
230
248
|
#
|
231
249
|
# Returns Hash of metadata.
|
232
|
-
def metadata
|
250
|
+
def metadata
|
233
251
|
formatted_data if markup_class.metadata == nil
|
234
252
|
markup_class.metadata
|
235
253
|
end
|
@@ -250,7 +268,7 @@ module Gollum
|
|
250
268
|
|
251
269
|
# Public: The current version of the page.
|
252
270
|
#
|
253
|
-
# Returns the
|
271
|
+
# Returns the Gollum::Git::Commit.
|
254
272
|
attr_reader :version
|
255
273
|
|
256
274
|
# Public: All of the versions that have touched the Page.
|
@@ -258,48 +276,50 @@ module Gollum
|
|
258
276
|
# options - The options Hash:
|
259
277
|
# :page - The Integer page number (default: 1).
|
260
278
|
# :per_page - The Integer max count of items to return.
|
261
|
-
# :follow - Follow's a file across renames,
|
262
|
-
# to a slower Grit native call. (default: false)
|
279
|
+
# :follow - Follow's a file across renames, slower. (default: false)
|
263
280
|
#
|
264
|
-
# Returns an Array of
|
281
|
+
# Returns an Array of Gollum::Git::Commit.
|
265
282
|
def versions(options = {})
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
283
|
+
@wiki.repo.git.versions_for_path(@path, @wiki.ref, log_pagination_options(options))
|
284
|
+
end
|
285
|
+
|
286
|
+
# Public: The last version that has touched the Page. Can be nil.
|
287
|
+
#
|
288
|
+
# Returns Gollum::Git::Commit, or nil.
|
289
|
+
def last_version
|
290
|
+
return @last_version if defined? @last_version
|
291
|
+
@last_version = @wiki.repo.git.versions_for_path(@path, @wiki.ref, {:max_count => 1}).first
|
275
292
|
end
|
276
293
|
|
277
294
|
# Public: The first 7 characters of the current version.
|
278
295
|
#
|
279
296
|
# Returns the first 7 characters of the current version.
|
280
|
-
|
281
|
-
|
282
|
-
|
297
|
+
def version_short
|
298
|
+
version.to_s[0, 7]
|
299
|
+
end
|
283
300
|
|
284
301
|
# Public: The header Page.
|
285
302
|
#
|
286
303
|
# Returns the header Page or nil if none exists.
|
287
304
|
def header
|
288
|
-
|
305
|
+
find_sub_pages unless defined?(@header)
|
306
|
+
@header
|
289
307
|
end
|
290
308
|
|
291
309
|
# Public: The footer Page.
|
292
310
|
#
|
293
311
|
# Returns the footer Page or nil if none exists.
|
294
312
|
def footer
|
295
|
-
|
313
|
+
find_sub_pages unless defined?(@footer)
|
314
|
+
@footer
|
296
315
|
end
|
297
316
|
|
298
317
|
# Public: The sidebar Page.
|
299
318
|
#
|
300
319
|
# Returns the sidebar Page or nil if none exists.
|
301
320
|
def sidebar
|
302
|
-
|
321
|
+
find_sub_pages unless defined?(@sidebar)
|
322
|
+
@sidebar
|
303
323
|
end
|
304
324
|
|
305
325
|
# Gets a Boolean determining whether this page is a historical version.
|
@@ -334,8 +354,8 @@ module Gollum
|
|
334
354
|
# Returns the String canonical name.
|
335
355
|
def self.cname(name, char_white_sub = '-', char_other_sub = '-')
|
336
356
|
name.respond_to?(:gsub) ?
|
337
|
-
|
338
|
-
|
357
|
+
name.gsub(%r(\s), char_white_sub).gsub(%r([<>+]), char_other_sub) :
|
358
|
+
''
|
339
359
|
end
|
340
360
|
|
341
361
|
# Convert a format Symbol into an extension String.
|
@@ -358,7 +378,7 @@ module Gollum
|
|
358
378
|
# Returns the Gollum::Wiki containing the page.
|
359
379
|
attr_reader :wiki
|
360
380
|
|
361
|
-
# Set the
|
381
|
+
# Set the Gollum::Git::Commit version of the page.
|
362
382
|
#
|
363
383
|
# Returns nothing.
|
364
384
|
attr_writer :version
|
@@ -371,13 +391,13 @@ module Gollum
|
|
371
391
|
# Returns a Gollum::Page or nil if the page could not be found.
|
372
392
|
def find(name, version, dir = nil, exact = false)
|
373
393
|
map = @wiki.tree_map_for(version.to_s)
|
374
|
-
if page = find_page_in_tree(map, name, dir, exact)
|
375
|
-
page.version = version.is_a?(
|
376
|
-
|
394
|
+
if (page = find_page_in_tree(map, name, dir, exact))
|
395
|
+
page.version = version.is_a?(Gollum::Git::Commit) ?
|
396
|
+
version : @wiki.commit_for(version)
|
377
397
|
page.historical = page.version.to_s == version.to_s
|
378
398
|
page
|
379
399
|
end
|
380
|
-
rescue
|
400
|
+
rescue Gollum::Git::NoSuchShaFound
|
381
401
|
end
|
382
402
|
|
383
403
|
# Find a page in a given tree.
|
@@ -390,16 +410,15 @@ module Gollum
|
|
390
410
|
# Returns a Gollum::Page or nil if the page could not be found.
|
391
411
|
def find_page_in_tree(map, name, checked_dir = nil, exact = false)
|
392
412
|
return nil if !map || name.to_s.empty?
|
393
|
-
if checked_dir = BlobEntry.normalize_dir(checked_dir)
|
394
|
-
checked_dir.downcase!
|
395
|
-
end
|
396
413
|
|
414
|
+
checked_dir = BlobEntry.normalize_dir(checked_dir)
|
397
415
|
checked_dir = '' if exact && checked_dir.nil?
|
416
|
+
name = ::File.join(checked_dir, name) if checked_dir
|
398
417
|
|
399
418
|
map.each do |entry|
|
400
419
|
next if entry.name.to_s.empty?
|
401
|
-
|
402
|
-
next unless page_match(name,
|
420
|
+
path = checked_dir ? ::File.join(entry.dir, entry.name) : entry.name
|
421
|
+
next unless page_match(name, path)
|
403
422
|
return entry.page(@wiki, @version)
|
404
423
|
end
|
405
424
|
|
@@ -408,7 +427,7 @@ module Gollum
|
|
408
427
|
|
409
428
|
# Populate the Page with information from the Blob.
|
410
429
|
#
|
411
|
-
# blob - The
|
430
|
+
# blob - The Gollum::Git::Blob that contains the info.
|
412
431
|
# path - The String directory path of the page file.
|
413
432
|
#
|
414
433
|
# Returns the populated Gollum::Page.
|
@@ -421,11 +440,11 @@ module Gollum
|
|
421
440
|
# The full directory path for the given tree.
|
422
441
|
#
|
423
442
|
# treemap - The Hash treemap containing parentage information.
|
424
|
-
# tree - The
|
443
|
+
# tree - The Gollum::Git::Tree for which to compute the path.
|
425
444
|
#
|
426
445
|
# Returns the String path.
|
427
446
|
def tree_path(treemap, tree)
|
428
|
-
if ptree = treemap[tree]
|
447
|
+
if (ptree = treemap[tree])
|
429
448
|
tree_path(treemap, ptree) + '/' + tree.name
|
430
449
|
else
|
431
450
|
''
|
@@ -435,11 +454,11 @@ module Gollum
|
|
435
454
|
# Compare the canonicalized versions of the two names.
|
436
455
|
#
|
437
456
|
# name - The human or canonical String page name.
|
438
|
-
#
|
457
|
+
# path - the String path on disk (including file extension).
|
439
458
|
#
|
440
459
|
# Returns a Boolean.
|
441
|
-
def page_match(name,
|
442
|
-
if match = self.class.valid_filename?(
|
460
|
+
def page_match(name, path)
|
461
|
+
if (match = self.class.valid_filename?(path))
|
443
462
|
@wiki.ws_subs.each do |sub|
|
444
463
|
return true if Page.cname(name).downcase == Page.cname(match, sub).downcase
|
445
464
|
end
|
@@ -447,39 +466,49 @@ module Gollum
|
|
447
466
|
false
|
448
467
|
end
|
449
468
|
|
450
|
-
|
469
|
+
|
470
|
+
# Loads sub pages. Sub page names (footers, headers, sidebars) are prefixed with
|
451
471
|
# an underscore to distinguish them from other Pages. If there is not one within
|
452
472
|
# the current directory, starts walking up the directory tree to try and find one
|
453
473
|
# within parent directories.
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
return
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
474
|
+
def find_sub_pages(subpagenames = SUBPAGENAMES, map = nil)
|
475
|
+
subpagenames.each{|subpagename| instance_variable_set("@#{subpagename}", nil)}
|
476
|
+
return nil if self.filename =~ /^_/ || ! self.version
|
477
|
+
|
478
|
+
map ||= @wiki.tree_map_for(@wiki.ref, true)
|
479
|
+
valid_names = subpagenames.map(&:capitalize).join("|")
|
480
|
+
# From Ruby 2.2 onwards map.select! could be used
|
481
|
+
map = map.select{|entry| entry.name =~ /^_(#{valid_names})/ }
|
482
|
+
return if map.empty?
|
483
|
+
|
484
|
+
subpagenames.each do |subpagename|
|
485
|
+
dir = ::Pathname.new(self.path)
|
486
|
+
while dir = dir.parent do
|
487
|
+
subpageblob = map.find do |blob_entry|
|
488
|
+
|
489
|
+
filename = "_#{subpagename.to_s.capitalize}"
|
490
|
+
searchpath = dir == Pathname.new('.') ? Pathname.new(filename) : dir + filename
|
491
|
+
entrypath = ::Pathname.new(blob_entry.path)
|
492
|
+
# Ignore extentions
|
493
|
+
entrypath = entrypath.dirname + entrypath.basename(entrypath.extname)
|
494
|
+
entrypath == searchpath
|
495
|
+
end
|
496
|
+
|
497
|
+
if subpageblob
|
498
|
+
subpage = subpageblob.page(@wiki, @version)
|
499
|
+
subpage.parent_page = self
|
500
|
+
instance_variable_set("@#{subpagename}", subpage)
|
501
|
+
break
|
502
|
+
end
|
503
|
+
|
504
|
+
break if dir == Pathname.new('.')
|
471
505
|
end
|
472
|
-
|
473
|
-
end
|
474
|
-
|
475
|
-
if page = find_page_in_tree(map, name, '')
|
476
|
-
page.parent_page = self
|
477
|
-
end
|
478
|
-
page
|
506
|
+
end
|
479
507
|
end
|
480
508
|
|
481
509
|
def inspect
|
482
510
|
%(#<#{self.class.name}:#{object_id} #{name} (#{format}) @wiki=#{@wiki.repo.path.inspect}>)
|
483
511
|
end
|
512
|
+
|
484
513
|
end
|
485
514
|
end
|
@@ -30,7 +30,7 @@ module Gollum
|
|
30
30
|
#
|
31
31
|
# Returns Hash with :max_count and :skip keys.
|
32
32
|
def log_pagination_options(options = {})
|
33
|
-
skip
|
33
|
+
skip = page_to_skip(options.delete(:page))
|
34
34
|
options[:max_count] = [options.delete(:per_page).to_i, per_page].max
|
35
35
|
options[:skip] = skip if skip > 0
|
36
36
|
options
|
@@ -6,51 +6,51 @@ module Gollum
|
|
6
6
|
# See http://github.com/rgrove/sanitize/.
|
7
7
|
class Sanitization
|
8
8
|
# Default whitelisted elements.
|
9
|
-
ELEMENTS
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
9
|
+
ELEMENTS = [
|
10
|
+
'a', 'abbr', 'acronym', 'address', 'area', 'b', 'big',
|
11
|
+
'blockquote', 'br', 'button', 'caption', 'center', 'cite',
|
12
|
+
'code', 'col', 'colgroup', 'dd', 'del', 'dfn', 'dir',
|
13
|
+
'div', 'dl', 'dt', 'em', 'fieldset', 'font', 'form', 'h1',
|
14
|
+
'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'img', 'input',
|
15
|
+
'ins', 'kbd', 'label', 'legend', 'li', 'map', 'mark', 'menu',
|
16
|
+
'ol', 'optgroup', 'option', 'p', 'pre', 'q', 's', 'samp',
|
17
|
+
'select', 'small', 'span', 'strike', 'strong', 'sub',
|
18
|
+
'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th',
|
19
|
+
'thead', 'tr', 'tt', 'u', 'ul', 'var'
|
20
20
|
].freeze
|
21
21
|
|
22
22
|
# Default whitelisted attributes.
|
23
23
|
ATTRIBUTES = {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
24
|
+
'a' => ['href'],
|
25
|
+
'img' => ['src'],
|
26
|
+
:all => ['abbr', 'accept', 'accept-charset',
|
27
|
+
'accesskey', 'action', 'align', 'alt', 'axis',
|
28
|
+
'border', 'cellpadding', 'cellspacing', 'char',
|
29
|
+
'charoff', 'class', 'charset', 'checked', 'cite',
|
30
|
+
'clear', 'cols', 'colspan', 'color',
|
31
|
+
'compact', 'coords', 'datetime', 'dir',
|
32
|
+
'disabled', 'enctype', 'for', 'frame',
|
33
|
+
'headers', 'height', 'hreflang',
|
34
|
+
'hspace', 'id', 'ismap', 'label', 'lang',
|
35
|
+
'longdesc', 'maxlength', 'media', 'method',
|
36
|
+
'multiple', 'name', 'nohref', 'noshade',
|
37
|
+
'nowrap', 'prompt', 'readonly', 'rel', 'rev',
|
38
|
+
'rows', 'rowspan', 'rules', 'scope',
|
39
|
+
'selected', 'shape', 'size', 'span',
|
40
|
+
'start', 'summary', 'tabindex', 'target',
|
41
|
+
'title', 'type', 'usemap', 'valign', 'value',
|
42
|
+
'vspace', 'width']
|
43
43
|
}.freeze
|
44
44
|
|
45
45
|
# Default whitelisted protocols for URLs.
|
46
|
-
PROTOCOLS
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
PROTOCOLS = {
|
47
|
+
'a' => { 'href' => ['http', 'https', 'mailto', 'ftp', 'irc', 'apt', :relative] },
|
48
|
+
'img' => { 'src' => ['http', 'https', :relative] },
|
49
|
+
'form' => { 'action' => ['http', 'https', :relative] }
|
50
50
|
}.freeze
|
51
51
|
|
52
|
-
ADD_ATTRIBUTES
|
53
|
-
if add = env[:config][:add_attributes][node.name]
|
52
|
+
ADD_ATTRIBUTES = lambda do |env, node|
|
53
|
+
if (add = env[:config][:add_attributes][node.name])
|
54
54
|
add.each do |key, value|
|
55
55
|
node[key] = value
|
56
56
|
end
|
@@ -60,34 +60,34 @@ module Gollum
|
|
60
60
|
# Default elements whose contents will be removed in addition
|
61
61
|
# to the elements themselve
|
62
62
|
REMOVE_CONTENTS = [
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
'script',
|
64
|
+
'style'
|
65
|
+
].freeze
|
66
66
|
|
67
67
|
# Default transformers to force @id attributes with 'wiki-' prefix
|
68
|
-
TRANSFORMERS
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
68
|
+
TRANSFORMERS = [
|
69
|
+
lambda do |env|
|
70
|
+
node = env[:node]
|
71
|
+
return if env[:is_whitelisted] || !node.element?
|
72
|
+
prefix = env[:config][:id_prefix]
|
73
|
+
found_attrs = %w(id name).select do |key|
|
74
|
+
if (value = node[key])
|
75
|
+
node[key] = value.gsub(/\A(#{prefix})?/, prefix)
|
76
|
+
end
|
76
77
|
end
|
77
|
-
|
78
|
-
|
78
|
+
if found_attrs.size > 0
|
79
|
+
ADD_ATTRIBUTES.call(env, node)
|
80
|
+
{}
|
81
|
+
end
|
82
|
+
end,
|
83
|
+
lambda do |env|
|
84
|
+
node = env[:node]
|
85
|
+
return unless (value = node['href'])
|
86
|
+
prefix = env[:config][:id_prefix]
|
87
|
+
node['href'] = value.gsub(/\A\#(#{prefix})?/, '#'+prefix)
|
79
88
|
ADD_ATTRIBUTES.call(env, node)
|
80
89
|
{}
|
81
90
|
end
|
82
|
-
end,
|
83
|
-
lambda do |env|
|
84
|
-
node = env[:node]
|
85
|
-
return unless value = node['href']
|
86
|
-
prefix = env[:config][:id_prefix]
|
87
|
-
node['href'] = value.gsub(/\A\#(#{prefix})?/, '#'+prefix)
|
88
|
-
ADD_ATTRIBUTES.call(env, node)
|
89
|
-
{}
|
90
|
-
end
|
91
91
|
].freeze
|
92
92
|
|
93
93
|
# Gets an Array of whitelisted HTML elements. Default: ELEMENTS.
|
@@ -122,14 +122,14 @@ module Gollum
|
|
122
122
|
attr_writer :allow_comments
|
123
123
|
|
124
124
|
def initialize
|
125
|
-
@elements
|
126
|
-
@attributes
|
127
|
-
@protocols
|
128
|
-
@transformers
|
129
|
-
@add_attributes
|
130
|
-
@remove_contents
|
131
|
-
@allow_comments
|
132
|
-
@id_prefix
|
125
|
+
@elements = ELEMENTS.dup
|
126
|
+
@attributes = ATTRIBUTES.dup
|
127
|
+
@protocols = PROTOCOLS.dup
|
128
|
+
@transformers = TRANSFORMERS.dup
|
129
|
+
@add_attributes = {}
|
130
|
+
@remove_contents = REMOVE_CONTENTS.dup
|
131
|
+
@allow_comments = false
|
132
|
+
@id_prefix = ''
|
133
133
|
yield self if block_given?
|
134
134
|
end
|
135
135
|
|
@@ -146,7 +146,7 @@ module Gollum
|
|
146
146
|
# Returns a Sanitization instance.
|
147
147
|
def history_sanitization
|
148
148
|
self.class.new do |sanitize|
|
149
|
-
sanitize.add_attributes['a'] = {'rel' => 'nofollow'}
|
149
|
+
sanitize.add_attributes['a'] = { 'rel' => 'nofollow' }
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
@@ -154,14 +154,14 @@ module Gollum
|
|
154
154
|
#
|
155
155
|
# Returns a Hash.
|
156
156
|
def to_hash
|
157
|
-
{ :elements
|
158
|
-
:attributes
|
159
|
-
:protocols
|
160
|
-
:add_attributes
|
161
|
-
:remove_contents
|
162
|
-
:allow_comments
|
163
|
-
:transformers
|
164
|
-
:id_prefix
|
157
|
+
{ :elements => elements,
|
158
|
+
:attributes => attributes,
|
159
|
+
:protocols => protocols,
|
160
|
+
:add_attributes => add_attributes,
|
161
|
+
:remove_contents => remove_contents,
|
162
|
+
:allow_comments => allow_comments?,
|
163
|
+
:transformers => transformers,
|
164
|
+
:id_prefix => id_prefix
|
165
165
|
}
|
166
166
|
end
|
167
167
|
|