slodown 0.3.0 → 0.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
  SHA1:
3
- metadata.gz: 69786a2c6984b3113df329ee878d76eb4de88655
4
- data.tar.gz: 9daa0d51fa74d936cf5441d0aafd7013f88b2643
3
+ metadata.gz: 17d27e385e008db49b05bee1acfdb62f0953e0cd
4
+ data.tar.gz: 96ef1fff701724d5f1fd95edb5245f88f8d81f30
5
5
  SHA512:
6
- metadata.gz: 37af9f2cf9371fac48f05e3301d916b5bf057980ff78b20f3b06848d9c7fbef5494e6604f658c69f89f063cd4cff11af9af53b941f78439bb3c163c6798abfaf
7
- data.tar.gz: 70e96284fdb75a2d9ffa4025b5550c8c0f2f1bc8cfd53aef622b4bd1c2b511801123a32a9ed5a9a4529c1bf64a39465e79a66de4f3f86f1958c6f1b98cd28b4e
6
+ metadata.gz: 0a31d2f4bd14fdadad10efccac44ba2de170b4f67099cd93146f497733d71774b2355ed830065f26fd288ff9b2687d98f5d024c13a94b815ce5ca517fb52afb7
7
+ data.tar.gz: a0f19df43d274b5a0c748575a84474b2a85d4e175e43768fcb0387503b83f5293172572778ab24650d72474831dac580dc273e11613be5e6333d9f69dee2ec74
@@ -1,7 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.2
4
- - 1.9.3
5
3
  - 2.0.0
6
4
  - 2.1.8
7
5
  - 2.2.4
data/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  Here's what Slodown does by default:
10
10
 
11
- - **render extended Markdown into HTML**. It uses the [kramdown](http://kramdown.rubyforge.org/) library, so yes, footnotes are supported!
11
+ - **render extended Markdown into HTML**. It uses the [kramdown](http://kramdown.gettalong.org/) library, so yes, footnotes are supported!
12
12
  - **add syntax highlighting to Markdown code blocks** through [CodeRay](http://coderay.rubychan.de/), [Rouge](http://rouge.jneen.net/), or any other highlighter supported by kramdown.
13
13
  - **support super-easy rich media embeds**. 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).
14
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.
@@ -25,7 +25,7 @@ Slodown, out of the box, implements my preferred way of handling user input, whi
25
25
  - Auto-link contained URLs and email addresses.
26
26
  - Finally, and most importantly, run the entire HTML through a really, really good whitelist-based sanitizer.
27
27
 
28
- This allows users to still add their own HTML, if required. In fact, I typically encourage users to make use of [kramdown's inline attributes], leaving it up the sanitizer to make sure they don't go crazy.
28
+ This allows users to still add their own HTML, if required. In fact, I typically encourage users to make use of [kramdown's inline attributes](http://kramdown.gettalong.org/syntax.html#inline-attribute-lists), leaving it up the sanitizer to make sure they don't go crazy.
29
29
 
30
30
  If this is not what you want, you will most likely be able to bend Slodown to your will -- it's pretty flexible.
31
31
 
@@ -149,6 +149,12 @@ If you're still set on submitting a pull request, please consider the following:
149
149
 
150
150
  ## Version History
151
151
 
152
+ ### 0.4.0 (2017-01-13)
153
+
154
+ - Feature: Block-level images are now rendered as a complete `<figure>` structure (with optional `<figcaption>`.)
155
+ - Change: The Slodown sanitizer now allows `<figure>`, `<figcaption>`, `<cite>`, `<mark>`, `<del>` and `<ins>` tags by default.
156
+ - Change: The Slodown sanitizer was stripping HTML of table tags. Tables are harmless, so they're not being stripped any longer.
157
+
152
158
  ### 0.3.0 (2016-02-22)
153
159
 
154
160
  - Removed the dependency on CodeRay. If you want syntax highlighting in your Markdown parsing, simply add CodeRay (or Rouge, or any other highlighter supported by kramdown) to your project.
@@ -4,12 +4,33 @@
4
4
  # Markdown image elements.)
5
5
  #
6
6
  class Kramdown::Converter::SlodownHtml < Kramdown::Converter::Html
7
- # Hook into image tags to allow oEmbed embeds.
7
+ # In Slodown, you can use block-level image attributes for oEmbed-based
8
+ # embeds. For this, we're hooking into #convert_p to find single block-level
9
+ # images.
8
10
  #
9
- def convert_img(el, indent)
10
- oembed = OEmbed::Providers.get(el.attr['src'])
11
- %q(<div class="embedded %s %s">%s</div>) % [oembed.type, oembed.provider_name.parameterize, oembed.html]
12
- rescue StandardError => e
13
- super
11
+ # If we can't use OEmbed, we'll assume the image is an actual image, and
12
+ # convert it into a <figure> element (with optional <figcaption>.)
13
+ #
14
+ def convert_p(el, indent)
15
+ if el.options[:transparent]
16
+ inner(el, indent)
17
+ elsif !el.children.nil? && el.children.count == 1 && el.children.first.type == :img
18
+ # Try to handle the embedded object through OEmbed; if this fails,
19
+ # handle it as an image instead and create a <figure>.
20
+ child = el.children.first
21
+
22
+ begin
23
+ oembed = OEmbed::Providers.get(child.attr['src'])
24
+ %q(<div class="embedded %s %s">%s</div>) % [oembed.type, oembed.provider_name.downcase.gsub(/\W+/, '-'), oembed.html]
25
+ rescue OEmbed::NotFound => e
26
+ convert_figure(child, indent)
27
+ end
28
+ else
29
+ super
30
+ end
31
+ end
32
+
33
+ def convert_figure(el, indent)
34
+ "#{' '*indent}<figure><img#{html_attributes(el.attr)} />#{(el.attr['title'] ? "<figcaption>#{el.attr['title']}</figcaption>" : "")}</figure>\n"
14
35
  end
15
36
  end
@@ -84,12 +84,15 @@ module Slodown
84
84
  elements: %w(
85
85
  p br a span sub sup strong em div hr abbr s
86
86
  ul ol li
87
- blockquote pre code kbd
87
+ blockquote cite pre code kbd
88
88
  h1 h2 h3 h4 h5 h6
89
89
  img object param del
90
+ table tr td th thead tbody
91
+ figure figcaption
92
+ mark del ins
90
93
  ),
91
94
  attributes: {
92
- :all => ['class', 'style', 'title', 'id'],
95
+ :all => ['class', 'style', 'title', 'id', 'datetime'],
93
96
  'a' => ['href', 'rel', 'name'],
94
97
  'li' => ['id'],
95
98
  'sup' => ['id'],
@@ -97,7 +100,9 @@ module Slodown
97
100
  'object' => ['width', 'height'],
98
101
  'param' => ['name', 'value'],
99
102
  'embed' => ['allowscriptaccess', 'width', 'height', 'src'],
100
- 'iframe' => ['width', 'height', 'src']
103
+ 'iframe' => ['width', 'height', 'src'],
104
+ 'td' => ['colspan', 'rowspan'],
105
+ 'th' => ['colspan', 'rowspan']
101
106
  },
102
107
  protocols: {
103
108
  'a' => { 'href' => ['ftp', 'http', 'https', 'mailto', '#fn', '#fnref', :relative] },
@@ -1,3 +1,3 @@
1
1
  module Slodown
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ def render(text)
4
+ Slodown::Formatter.new(text).complete.to_s
5
+ end
6
+
7
+ describe 'basic formatting syntax' do
8
+ it "converts a block-level image to a <figure> structure" do
9
+ expect(render %[check it out:\n\n![image](image.jpg "Cute Kitten!")])
10
+ .to eq %[<p>check it out:</p>\n\n<figure><img src="image.jpg" alt="image" title="Cute Kitten!"><figcaption>Cute Kitten!</figcaption></figure>\n]
11
+ end
12
+
13
+ it "doesn't affect OEmbed-enabled embeds" do
14
+ expect(render %[check it out:\n\n![video](https://www.youtube.com/watch?v=KilehMXMxo0)])
15
+ .to eq %[<p>check it out:</p>\n\n<div class="embedded video youtube"><iframe width="480" height="270" src="https://www.youtube.com/embed/KilehMXMxo0?feature=oembed" frameborder="0" allowfullscreen=""></iframe></div>]
16
+ end
17
+
18
+ it "doesn't affect inline images" do
19
+ expect(render %[here's an inline image: ![image](image.jpg)])
20
+ .to eq %[<p>here’s an inline image: <img src="image.jpg" alt="image"></p>\n]
21
+ end
22
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slodown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hendrik Mans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-22 00:00:00.000000000 Z
11
+ date: 2017-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown
@@ -129,6 +129,7 @@ files:
129
129
  - lib/slodown/version.rb
130
130
  - slodown.gemspec
131
131
  - spec/basic_formatting_spec.rb
132
+ - spec/image_figures_spec.rb
132
133
  - spec/metadata_extraction_spec.rb
133
134
  - spec/spec_helper.rb
134
135
  homepage: https://github.com/hmans/slodown
@@ -150,12 +151,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
151
  version: '0'
151
152
  requirements: []
152
153
  rubyforge_project:
153
- rubygems_version: 2.5.1
154
+ rubygems_version: 2.6.8
154
155
  signing_key:
155
156
  specification_version: 4
156
157
  summary: Markdown + oEmbed + Sanitize + Syntax Highlighting = the ultimate user input
157
158
  rendering pipeline.
158
159
  test_files:
159
160
  - spec/basic_formatting_spec.rb
161
+ - spec/image_figures_spec.rb
160
162
  - spec/metadata_extraction_spec.rb
161
163
  - spec/spec_helper.rb