Permalink
Browse files

Allow custom sanitization.

Add two options:
 * allow_elements="object,embed"
 * allow_attributes="src"

Signed-off-by: François de Metz <francois@2metz.fr>
  • Loading branch information...
1 parent ddecbd5 commit 8ce51e09053e90ea4f62eba9a60895b206ba824e @francois2metz francois2metz committed Apr 11, 2011
Showing with 19 additions and 4 deletions.
  1. +14 −2 bin/gollum-site
  2. +1 −1 lib/gollum-site/sanitization.rb
  3. +4 −1 lib/gollum-site/site.rb
View
@@ -28,7 +28,9 @@ options = {
'output_path' => '_site',
'port' => 8000,
'watch' => false,
- 'level' => :warn
+ 'level' => :warn,
+ 'allow_elements' => [],
+ 'allow_attributes' => []
}
opts = OptionParser.new do |opts|
opts.banner = help
@@ -57,6 +59,14 @@ opts = OptionParser.new do |opts|
options['watch'] = true
end
+ opts.on("--allow_elements ELMS", "Custom elements to prevent sanitization") do |elements|
+ options['allow_elements'] = elements.split(',')
+ end
+
+ opts.on("--allow_attributes ATTRS", "Custom attributes to prevent sanitization") do |attrs|
+ options['allow_attributes'] = attrs.split(',')
+ end
+
opts.on("--log_level LEVEL", %w[debug info warn error fatal],
"Set logging level (debug, info, warn, error, fatal)") do |level|
options['level'] = level.to_sym
@@ -92,7 +102,9 @@ when 'generate'
site = Gollum::Site.new('.', {
:base_path => options['base_path'],
:output_path => options['output_path'],
- :version => options['working'] ? :working : options['ref']
+ :version => options['working'] ? :working : options['ref'],
+ :allow_elements => options['allow_elements'],
+ :allow_attributes => options['allow_attributes']
})
start = Time.now
site.generate()
@@ -16,7 +16,7 @@ class SiteSanitization
'select', 'small', 'span', 'strike', 'strong', 'sub',
'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th',
'thead', 'tr', 'tt', 'u', 'ul', 'var', 'iframe'
- ].freeze
+ ]
# Default whitelisted attributes.
ATTRIBUTES = {
@@ -10,11 +10,14 @@ def self.default_layout_dir()
def initialize(path, options = {})
@path = path
+ sanitization = Gollum::SiteSanitization.new
+ sanitization.elements.concat options[:allow_elements]
+ sanitization.attributes[:all].concat options[:allow_attributes]
@wiki = Gollum::Wiki.new(path, {
:markup_class => Gollum::SiteMarkup,
:page_class => Gollum::SitePage,
:base_path => options[:base_path],
- :sanitization => Gollum::SiteSanitization.new,
+ :sanitization => sanitization,
:history_sanitization => Gollum::SiteSanitization.new
})
@wiki.site = self

0 comments on commit 8ce51e0

Please sign in to comment.