slodown 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,14 +1,22 @@
1
- # Slodown: the ultimate user input rendering pipeline.
1
+ ![slodown](https://dl.dropbox.com/u/7288/hendrik.mans.de/slodown.png)
2
2
 
3
- I love Markdown. I love syntax highlighting. I love oEmbed. And last but not least, I love whitelist-based HTML sanitizing. **Slodown** rolls all of these into one, and then some.
3
+ # slodown is the ultimate user input rendering pipeline.
4
4
 
5
- Here's what Slodown does by default:
5
+ [![Build Status](https://travis-ci.org/hmans/slodown.png?branch=master)](https://travis-ci.org/hmans/slodown) [![Gem Version](https://badge.fury.io/rb/slodown.png)](http://badge.fury.io/rb/slodown)
6
+
7
+ **I love Markdown. I love syntax highlighting. I love oEmbed. And last but not least, I love whitelist-based HTML sanitizing. slodown rolls all of these into one, and then some.**
8
+
9
+ Here's what slodown does by default:
6
10
 
7
11
  - **render extended Markdown into HTML**. It uses the [kramdown](http://kramdown.rubyforge.org/) library, so yes, footnotes are supported!
8
- - **supports super-easy rich media embeds**, [sloblog.io-style](http://sloblog.io/~hmans/qhdsk2SMoAU). Just point the Markdown image syntax at, say, a Youtube video, and Slodown will fetch the complete embed code through the magic of [ruby-oembed](https://github.com/judofyr/ruby-oembed).
12
+ - **adds syntax highlighting to Markdown code blocks** through [CodeRay](http://coderay.rubychan.de/).
13
+ - **supports super-easy rich media embeds**, [sloblog.io-style](http://sloblog.io/~hmans/qhdsk2SMoAU). Just point the Markdown image syntax at, say, a Youtube video, and slodown will fetch the complete embed code through the magic of [ruby-oembed](https://github.com/judofyr/ruby-oembed).
9
14
  - **auto-link contained URLs** using [Rinku](https://github.com/vmg/rinku), which is smart enough to not auto-link URLs contained in, say, code blocks.
10
15
  - **sanitize the generated HTML** using the white-list based [sanitize](https://github.com/rgrove/sanitize) gem.
11
16
 
17
+ slodown is an extraction from [sloblog.io](http://sloblog.io). It is very easy to extend or modify, as it's just a plain old Ruby class you can inherit from.
18
+
19
+
12
20
  ## Installation
13
21
 
14
22
  Add this line to your application's Gemfile:
@@ -33,20 +41,23 @@ For every piece of user input that needs to be rendered, create an instance of `
33
41
  # let's create an instance to work with
34
42
  formatter = Slodown::Formatter.new(text)
35
43
 
36
- # just markdown
37
- @formatter.markdown.to_s
44
+ # just render Markdown to HTML
45
+ formatter.markdown.to_s
46
+
47
+ # just auto-link contained URLs
48
+ formatter.autolink.to_s
38
49
 
39
- # just HTML tag sanitizing
40
- @formatter.sanitize.to_s
50
+ # just sanitize HTML tags
51
+ formatter.sanitize.to_s
41
52
 
42
53
  # you can chain multiple operations
43
- @formatter.markdown.sanitize.to_s
54
+ formatter.markdown.sanitize.to_s
44
55
 
45
56
  # this is the whole deal:
46
- @formatter.markdown.autolink.sanitize.to_s
57
+ formatter.markdown.autolink.sanitize.to_s
47
58
 
48
59
  # which is the same as:
49
- @formatter.complete.to_s
60
+ formatter.complete.to_s
50
61
  ~~~
51
62
 
52
63
  ## Hints
@@ -55,6 +66,10 @@ formatter = Slodown::Formatter.new(text)
55
66
  * Markdown transformations, HTML sanitizing, oEmbed handshakes and other operations are pretty expensive operations. For sake of performance (and stability), it is recommended that you cache the generated output in some manner.
56
67
  * Eat more Schnitzel.
57
68
 
69
+ ## TODOs
70
+
71
+ - More/better specs. slodown doesn't have a lot of functionality of its own, passing most of its duties over to the beautiful rendering gems it uses, but I'm sure there's still an opportunity or two for it to break, so, yeah, I should be adding _some_ specs.
72
+ - Better configuration for the HTML sanitizer. Right now, in order to change the sanitizing behavior, you'll need to inherit a new class from `Slodown::Formatter` and override its `#sanitize_config` method. Regarding the contents of the hash this method returns, please refer to the [sanitize documentation](https://github.com/rgrove/sanitize#custom-configuration).
58
73
 
59
74
  ## Contributing
60
75
 
@@ -26,47 +26,48 @@ module Slodown
26
26
 
27
27
  # Sanitize HTML tags.
28
28
  #
29
- def sanitize(mode = :normal)
30
- @current = case mode
31
- when :normal
32
- Sanitize.clean(@current,
33
- elements: %w(
34
- p a span sub sup strong em div hr abbr
35
- ul ol li
36
- blockquote pre code
37
- h1 h2 h3 h4 h5 h6
38
- img object param del
39
- ),
40
- attributes: {
41
- :all => ['class', 'style', 'title'],
42
- 'a' => ['href', 'rel', 'name'],
43
- 'li' => ['id'],
44
- 'sup' => ['id'],
45
- 'img' => ['src', 'title', 'alt', 'width', 'height'],
46
- 'object' => ['width', 'height'],
47
- 'param' => ['name', 'value'],
48
- 'embed' => ['allowscriptaccess', 'width', 'height', 'src'],
49
- 'iframe' => ['width', 'height', 'src']
50
- },
51
- protocols: {
52
- 'a' => { 'href' => ['ftp', 'http', 'https', 'mailto', '#fn', '#fnref', :relative] },
53
- 'img' => {'src' => ['http', 'https', :relative]},
54
- 'iframe' => {'src' => ['http', 'https']},
55
- 'embed' => {'src' => ['http', 'https']},
56
- 'object' => {'src' => ['http', 'https']},
57
- 'li' => {'id' => ['fn']},
58
- 'sup' => {'id' => ['fnref']}
59
- },
60
- transformers: EmbedTransformer)
61
- else
62
- Sanitize.clean(@current)
63
- end
64
-
29
+ def sanitize
30
+ @current = Sanitize.clean(@current, sanitize_config)
65
31
  self
66
32
  end
67
33
 
68
34
  def to_s
69
35
  @current
70
36
  end
37
+
38
+ private
39
+
40
+ def sanitize_config
41
+ {
42
+ elements: %w(
43
+ p a span sub sup strong em div hr abbr
44
+ ul ol li
45
+ blockquote pre code
46
+ h1 h2 h3 h4 h5 h6
47
+ img object param del
48
+ ),
49
+ attributes: {
50
+ :all => ['class', 'style', 'title', 'id'],
51
+ 'a' => ['href', 'rel', 'name'],
52
+ 'li' => ['id'],
53
+ 'sup' => ['id'],
54
+ 'img' => ['src', 'title', 'alt', 'width', 'height'],
55
+ 'object' => ['width', 'height'],
56
+ 'param' => ['name', 'value'],
57
+ 'embed' => ['allowscriptaccess', 'width', 'height', 'src'],
58
+ 'iframe' => ['width', 'height', 'src']
59
+ },
60
+ protocols: {
61
+ 'a' => { 'href' => ['ftp', 'http', 'https', 'mailto', '#fn', '#fnref', :relative] },
62
+ 'img' => {'src' => ['http', 'https', :relative]},
63
+ 'iframe' => {'src' => ['http', 'https']},
64
+ 'embed' => {'src' => ['http', 'https']},
65
+ 'object' => {'src' => ['http', 'https']},
66
+ 'li' => {'id' => ['fn']},
67
+ 'sup' => {'id' => ['fnref']}
68
+ },
69
+ transformers: EmbedTransformer
70
+ }
71
+ end
71
72
  end
72
73
  end
@@ -1,3 +1,3 @@
1
1
  module Slodown
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slodown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: