mumukit-content-type 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7aedd885623474e1042495be8d2feb3ce324ae41d4b0bcea728f4c84d8fb9cfa
4
- data.tar.gz: ea4f7890b2fc9bf079017943b2cde767aace30727c09d636c3d517a8b159bce7
3
+ metadata.gz: 4fdf9d6b5af5bcdb4de689b9a5489880aca70a4b9dabd7343e3c7510026b4149
4
+ data.tar.gz: 143fba3f1f5cc5e9cd4410019d57a984bc3d1e12e20341bbb608dcf007b3833a
5
5
  SHA512:
6
- metadata.gz: c7f9f1a844ca3e19c28fa5497c3cb3f54a455ca46e15ef37a632cb1c6cdfd132fe016c026279c91d2433ed8f680cca83fcbe4b452ddb7f89b8c19fb68bd56f8f
7
- data.tar.gz: a463b43ae6bf86313194807678181bbaa8d36e11f2bc8ea3f9d50e13905e4fea64fbba2ebe5cf5a4c0be3317527b667280fe626e7da33d50a205fb2953bb9615
6
+ metadata.gz: dd20954abd94ceaceb2d6a9ff2310d843a1410a5b94b8d7352d06dd62330cca4469626380ee7f1d581dfdc549d3be35f8b612b204e0d8ffb8db8238170006c0a
7
+ data.tar.gz: 646b6a9b35e54dbd33de377bb08b386a4e6c2d1fbfdfa0d2a926a9b402625e6b110ad723d31736f59d9765921d0bc396ff2c0a34ce11b438e52348da0f9c2ad9
@@ -7,6 +7,10 @@ module Mumukit
7
7
  def format_exception(e)
8
8
  "#{title e.message}\n#{code e.backtrace.join("\n")}"
9
9
  end
10
+
11
+ def to_html(content)
12
+ Mumukit::ContentType::Sanitizer.sanitize(htmlize content).html_safe
13
+ end
10
14
  end
11
15
 
12
16
  def self.parse(s)
@@ -21,6 +25,7 @@ module Mumukit
21
25
  end
22
26
  end
23
27
 
28
+ require_relative './content_type/sanitizer'
24
29
  require_relative './content_type/emoji'
25
30
  require_relative './content_type/markdown'
26
31
  require_relative './content_type/with_markdown'
@@ -9,8 +9,8 @@ module Mumukit::ContentType::Html
9
9
  "<pre>#{code}</pre>"
10
10
  end
11
11
 
12
- def self.to_html(content)
13
- content.html_safe if content
12
+ def self.htmlize(content)
13
+ content
14
14
  end
15
15
 
16
16
  def self.name
@@ -43,8 +43,8 @@ module Mumukit::ContentType::Markdown
43
43
  .gsub('ム', mumuki_logo)
44
44
  end
45
45
 
46
- def self.to_html(content)
47
- replace_mu_logo(content).html_safe if content
46
+ def self.htmlize(content)
47
+ replace_mu_logo(content) if content
48
48
  end
49
49
 
50
50
  def self.name
@@ -0,0 +1,30 @@
1
+ require 'sanitize'
2
+
3
+ module Mumukit::ContentType::Sanitizer
4
+ class << self
5
+ class_attribute :should_sanitize, :allowed_elements, :allowed_attributes
6
+
7
+ self.should_sanitize = false
8
+ self.allowed_elements = []
9
+ self.allowed_attributes = {
10
+ 'a' => Sanitize::Config::RELAXED[:attributes]['a'] + ['target']
11
+ }
12
+
13
+ def sanitize(html)
14
+ return html unless should_sanitize?
15
+
16
+ Sanitize.fragment(html, sanitization_settings)
17
+ end
18
+
19
+ def sanitization_settings
20
+ Sanitize::Config.merge(Sanitize::Config::RELAXED, custom_sanitization_settings)
21
+ end
22
+
23
+ def custom_sanitization_settings
24
+ {
25
+ elements: Sanitize::Config::RELAXED[:elements] + allowed_elements,
26
+ attributes: allowed_attributes
27
+ }
28
+ end
29
+ end
30
+ end
@@ -1,5 +1,5 @@
1
1
  module Mumukit
2
2
  module ContentType
3
- VERSION = '1.3.1'
3
+ VERSION = '1.4.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mumukit-content-type
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franco Leonardo Bulgarelli
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-19 00:00:00.000000000 Z
11
+ date: 2018-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sanitize
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '5.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '5.0'
97
111
  description:
98
112
  email:
99
113
  - franco@mumuki.org
@@ -107,6 +121,7 @@ files:
107
121
  - lib/mumukit/content_type/html.rb
108
122
  - lib/mumukit/content_type/markdown.rb
109
123
  - lib/mumukit/content_type/plain.rb
124
+ - lib/mumukit/content_type/sanitizer.rb
110
125
  - lib/mumukit/content_type/version.rb
111
126
  - lib/mumukit/content_type/with_markdown.rb
112
127
  - vendor/assets/images/emojis/-1.png
@@ -1012,7 +1027,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1012
1027
  version: '0'
1013
1028
  requirements: []
1014
1029
  rubyforge_project:
1015
- rubygems_version: 2.7.6
1030
+ rubygems_version: 2.7.7
1016
1031
  signing_key:
1017
1032
  specification_version: 4
1018
1033
  summary: Content Type handling for Mumuki