spirit 0.2 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/spirit.rb +8 -10
- data/lib/spirit/constants.rb +17 -7
- data/lib/spirit/document.rb +4 -9
- data/lib/spirit/errors.rb +0 -1
- data/lib/spirit/logger.rb +5 -6
- data/lib/spirit/manifest.rb +4 -5
- data/lib/spirit/render.rb +0 -2
- data/lib/spirit/render/errors.rb +0 -4
- data/lib/spirit/render/html.rb +17 -117
- data/lib/spirit/render/processable.rb +78 -0
- data/lib/spirit/render/processors.rb +15 -0
- data/lib/spirit/render/processors/base.rb +40 -0
- data/lib/spirit/render/processors/block_image_processor.rb +49 -0
- data/lib/spirit/render/processors/headers_processor.rb +41 -0
- data/lib/spirit/render/processors/layout_processor.rb +28 -0
- data/lib/spirit/render/processors/math_processor.rb +102 -0
- data/lib/spirit/render/processors/problems_processor.rb +76 -0
- data/lib/spirit/render/processors/pygments_processor.rb +22 -0
- data/lib/spirit/render/processors/sanitize_processor.rb +86 -0
- data/lib/spirit/render/templates.rb +1 -3
- data/lib/spirit/render/templates/header.rb +2 -3
- data/lib/spirit/render/templates/image.rb +6 -13
- data/lib/spirit/render/templates/multi.rb +9 -10
- data/lib/spirit/render/templates/navigation.rb +4 -5
- data/lib/spirit/render/templates/problem.rb +24 -28
- data/lib/spirit/render/templates/short.rb +2 -3
- data/lib/spirit/render/templates/table.rb +2 -2
- data/lib/spirit/render/templates/template.rb +12 -8
- data/lib/spirit/version.rb +1 -2
- data/views/header.haml +1 -1
- data/views/img.haml +2 -2
- data/views/layout.haml +27 -0
- data/views/multi.haml +10 -14
- data/views/nav.haml +2 -2
- data/views/short.haml +6 -11
- data/views/table.haml +20 -26
- metadata +36 -57
- data/lib/spirit/render/sanitize.rb +0 -90
- data/views/exe.haml +0 -5
@@ -1,90 +0,0 @@
|
|
1
|
-
# ~*~ encoding: utf-8 ~*~
|
2
|
-
require 'sanitize'
|
3
|
-
|
4
|
-
module Spirit
|
5
|
-
|
6
|
-
module Render
|
7
|
-
|
8
|
-
# Encapsulate sanitization options.
|
9
|
-
# @see https://github.com/github/gollum/blob/master/lib/gollum/sanitization.rb
|
10
|
-
class Sanitize < ::Sanitize
|
11
|
-
|
12
|
-
# white-listed elements
|
13
|
-
ELEMENTS = [
|
14
|
-
'a', 'abbr', 'acronym', 'address', 'area', 'b', 'big',
|
15
|
-
'blockquote', 'br', 'button', 'caption', 'center', 'cite',
|
16
|
-
'code', 'col', 'colgroup', 'dd', 'del', 'dfn', 'dir',
|
17
|
-
'div', 'dl', 'dt', 'em', 'fieldset', 'font', 'form', 'h1',
|
18
|
-
'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'img', 'input',
|
19
|
-
'ins', 'kbd', 'label', 'legend', 'li', 'map', 'menu',
|
20
|
-
'ol', 'optgroup', 'option', 'p', 'pre', 'q', 's', 'samp',
|
21
|
-
'select', 'small', 'span', 'strike', 'strong', 'sub',
|
22
|
-
'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th',
|
23
|
-
'thead', 'tr', 'tt', 'u', 'ul', 'var'
|
24
|
-
].freeze
|
25
|
-
|
26
|
-
# white-listed attributes
|
27
|
-
ATTRIBUTES = {
|
28
|
-
'a' => ['href', 'name', 'data-magellan-destination'],
|
29
|
-
'dd' => ['data-magellan-arrival'],
|
30
|
-
'dl' => ['data-magellan-expedition'],
|
31
|
-
'img' => ['src'],
|
32
|
-
:all => ['abbr', 'accept', 'accept-charset',
|
33
|
-
'accesskey', 'action', 'align', 'alt', 'axis',
|
34
|
-
'border', 'cellpadding', 'cellspacing', 'char',
|
35
|
-
'charoff', 'class', 'charset', 'checked', 'cite',
|
36
|
-
'clear', 'cols', 'colspan', 'color',
|
37
|
-
'compact', 'coords', 'datetime', 'dir',
|
38
|
-
'disabled', 'enctype', 'for', 'frame',
|
39
|
-
'headers', 'height', 'hreflang',
|
40
|
-
'hspace', 'id', 'ismap', 'label', 'lang',
|
41
|
-
'longdesc', 'maxlength', 'media', 'method',
|
42
|
-
'multiple', 'name', 'nohref', 'noshade',
|
43
|
-
'nowrap', 'prompt', 'readonly', 'rel', 'rev',
|
44
|
-
'rows', 'rowspan', 'rules', 'scope',
|
45
|
-
'selected', 'shape', 'size', 'span',
|
46
|
-
'start', 'summary', 'tabindex', 'target',
|
47
|
-
'title', 'type', 'usemap', 'valign', 'value',
|
48
|
-
'vspace', 'width']
|
49
|
-
}.freeze
|
50
|
-
|
51
|
-
# white-listed protocols
|
52
|
-
PROTOCOLS = {
|
53
|
-
'a' => {'href' => ['http', 'https', 'mailto', 'ftp', 'irc', 'apt', :relative]},
|
54
|
-
'img' => {'src' => ['http', 'https', :relative]}
|
55
|
-
}.freeze
|
56
|
-
|
57
|
-
# elements to remove (incl. contents)
|
58
|
-
REMOVE_CONTENTS = [
|
59
|
-
'script',
|
60
|
-
'style'
|
61
|
-
].freeze
|
62
|
-
|
63
|
-
# attributes to add to elements
|
64
|
-
ADD_ATTRIBUTES = {
|
65
|
-
'a' => {'rel' => 'nofollow'}
|
66
|
-
}
|
67
|
-
|
68
|
-
# Creates a new sanitizer with {Spirit}'s configuration.
|
69
|
-
def initialize
|
70
|
-
super config
|
71
|
-
end
|
72
|
-
|
73
|
-
private
|
74
|
-
|
75
|
-
# @return [Hash] configuration hash.
|
76
|
-
def config
|
77
|
-
{ elements: ELEMENTS.dup,
|
78
|
-
attributes: ATTRIBUTES.dup,
|
79
|
-
protocols: PROTOCOLS.dup,
|
80
|
-
add_attributes: ADD_ATTRIBUTES.dup,
|
81
|
-
remove_contents: REMOVE_CONTENTS.dup,
|
82
|
-
allow_comments: false
|
83
|
-
}
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|