postmarkdown 0.0.8 → 0.0.9

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: 6d1259762f115e6a4e14f0332a811e0021535cbc
4
- data.tar.gz: 75c1cf02cdd1949f674fd295664e6aa723cc3854
3
+ metadata.gz: 39584271054fe1a1f30ce61cde326c8c068c9f81
4
+ data.tar.gz: b4cd96a67850bda71f46f55d1b0650942e6affa4
5
5
  SHA512:
6
- metadata.gz: 314879f2b718f06915f50e76a4f01d8ee2913ee6a94c6f787a37edca586aa1c7d0404f6f545690014bf51d482abc5c6d198d35eef30087afb2935a01a585b73f
7
- data.tar.gz: 7850455b8b7522e47eb06c6a34f3ab2f5b5f76292f500f7021a484f5ee6d67aa7837d54443b8ffee97142d59f1d8cc19e6f2b4f13f0f0e671f1ab4492a4063a7
6
+ metadata.gz: febf77d5f33061acf85b890173af01111b9fd92eb72e53ae9c201a5a882fa04060be035f45fb8d7ac0b736c949d4bc4e2f465208a1f0b16f90d94c5ace87259d
7
+ data.tar.gz: 675831ce290bc902294d845041d4ce51268f39dd3ad4b10b26bac2753c317012cd0f24ce9323d85c8df2a348cc78bb06278a8f3f6e3cbac8c9a25d5e25c6bf5b
data/README.markdown CHANGED
@@ -86,6 +86,42 @@ Postmarkdown comes with minimal built-in theme for your convenience.
86
86
 
87
87
  Postmarkdown::Config.options[:layout] = 'postmarkdown'
88
88
 
89
+ ## Syntax Highlighting
90
+
91
+ Postmarkdown supports fenced code blocks which allows you to add syntax
92
+ highlighting with an optional language identifier. For example, to
93
+ syntax highlight Ruby code:
94
+
95
+ ```ruby
96
+ require 'some_gem'
97
+ class RubyClass
98
+ def some_method
99
+ puts "string"
100
+ end
101
+ end
102
+ ```
103
+
104
+ This will add CSS classes to the HTML, but you still need to a
105
+ stylesheet to visually highlight the code. Postmarkdown ships with a
106
+ GitHub-like set of styles.
107
+
108
+ In your `app/assets/stylesheets/application.css`, include the CSS file:
109
+
110
+ ```css
111
+ /*
112
+ *= require postmarkdown/syntax/github
113
+ */
114
+ ```
115
+
116
+ Or if you're using SCSS:
117
+
118
+ ```scss
119
+ @import "postmarkdown/syntax/github";
120
+ ```
121
+
122
+ Postmarkdown adds highlighting to your code using [Rouge](https://github.com/jayferd/rouge).
123
+ See the [demo page](http://rouge.jayferd.us/demo) for supported languages and styles.
124
+
89
125
  ## Customizing Routes
90
126
 
91
127
  By default Postmarkdown will setup all routes to go through the `/posts/*` path. For example:
@@ -15,6 +15,6 @@ module PostHelper
15
15
  end
16
16
 
17
17
  def post_content_html(post)
18
- RDiscount.new(render(:inline => post.content)).to_html.html_safe
18
+ Postmarkdown::MarkdownRenderer.new.render(render(:inline => post.content)).html_safe
19
19
  end
20
20
  end
@@ -3,6 +3,7 @@
3
3
  %head
4
4
  %title= Postmarkdown::Util.app_name
5
5
  = stylesheet_link_tag 'postmarkdown/postmarkdown'
6
+ = stylesheet_link_tag 'postmarkdown/syntax/github'
6
7
  = yield :head
7
8
  %body
8
9
  %header#header
@@ -2,7 +2,8 @@ module Postmarkdown
2
2
  require 'postmarkdown'
3
3
  require 'rails'
4
4
  require 'gravtastic'
5
- require 'rdiscount'
5
+ require 'redcarpet'
6
+ require 'rouge'
6
7
  require 'nokogiri'
7
8
  require 'action_view'
8
9
  require 'haml'
@@ -0,0 +1,17 @@
1
+ require 'rouge/plugins/redcarpet'
2
+
3
+ module Postmarkdown
4
+ class MarkdownRenderer
5
+ class HTMLWithRouge < Redcarpet::Render::HTML
6
+ include Rouge::Plugins::Redcarpet
7
+ end
8
+
9
+ def initialize
10
+ @markdown = ::Redcarpet::Markdown.new(HTMLWithRouge, :fenced_code_blocks => true)
11
+ end
12
+
13
+ def render(text)
14
+ @markdown.render(text)
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module Postmarkdown
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.9'
3
3
  end
data/lib/postmarkdown.rb CHANGED
@@ -3,3 +3,4 @@ require 'postmarkdown/config'
3
3
  require 'postmarkdown/routes'
4
4
  require 'postmarkdown/railtie'
5
5
  require 'postmarkdown/util'
6
+ require 'postmarkdown/markdown_renderer'
data/postmarkdown.gemspec CHANGED
@@ -25,8 +25,9 @@ Gem::Specification.new do |s|
25
25
  s.add_dependency 'haml', ['>= 3.1', '< 5']
26
26
  s.add_dependency 'gravtastic'
27
27
  s.add_dependency 'nokogiri'
28
- s.add_dependency 'rdiscount'
28
+ s.add_dependency 'redcarpet'
29
29
  s.add_dependency 'kaminari'
30
+ s.add_dependency 'rouge'
30
31
 
31
32
  s.add_development_dependency 'appraisal'
32
33
  s.add_development_dependency 'rspec-rails', '~> 2.8'
@@ -139,7 +139,14 @@ describe 'Post views', :type => :request do
139
139
  end
140
140
 
141
141
  it 'should preserve whitespace on code blocks' do
142
- page.source.should match '<pre><code>First line of code.&#x000A; Second line of code.&#x000A;</code></pre>'
142
+ code_block = Nokogiri::HTML(page.source).at('pre')
143
+ code_block.text.should eq "example = ->\n alert 'Example'"
144
+ end
145
+
146
+ it 'should highlight code blocks' do
147
+ code_block = Nokogiri::HTML(page.source).at('pre')
148
+ span_classes = code_block.css('span').map { |span| span[:class] }
149
+ span_classes.should include 'nx', 'o', 's'
143
150
  end
144
151
 
145
152
  it 'should allow calling Rails helpers via ERB tags' do
@@ -9,7 +9,9 @@ First paragraph of content.
9
9
 
10
10
  Second paragraph of content.
11
11
 
12
- First line of code.
13
- Second line of code.
12
+ ``` coffeescript
13
+ example = ->
14
+ alert 'Example'
15
+ ```
14
16
 
15
17
  <%= content_tag :p, "Paragraph created by Rails helper" %>
@@ -0,0 +1,61 @@
1
+ .hll { background-color: #ffffcc }
2
+ .c { color: #999988; font-style: italic } /* Comment */
3
+ .err { color: #a61717; background-color: #e3d2d2 } /* Error */
4
+ .k { color: #000000; font-weight: normal } /* Keyword */
5
+ .o { color: #000000; font-weight: normal } /* Operator */
6
+ .cm { color: #999988; font-style: italic } /* Comment.Multiline */
7
+ .cp { color: #999999; font-weight: normal; font-style: italic } /* Comment.Preproc */
8
+ .c1 { color: #999988; font-style: italic } /* Comment.Single */
9
+ .cs { color: #999999; font-weight: normal; font-style: italic } /* Comment.Special */
10
+ .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
11
+ .ge { color: #000000; font-style: italic } /* Generic.Emph */
12
+ .gr { color: #aa0000 } /* Generic.Error */
13
+ .gh { color: #999999 } /* Generic.Heading */
14
+ .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
15
+ .go { color: #888888 } /* Generic.Output */
16
+ .gp { color: #555555 } /* Generic.Prompt */
17
+ .gs { font-weight: normal } /* Generic.Strong */
18
+ .gu { color: #aaaaaa } /* Generic.Subheading */
19
+ .gt { color: #aa0000 } /* Generic.Traceback */
20
+ .kc { color: #000000; font-weight: normal } /* Keyword.Constant */
21
+ .kd { color: #000000; font-weight: normal } /* Keyword.Declaration */
22
+ .kn { color: #000000; font-weight: normal } /* Keyword.Namespace */
23
+ .kp { color: #000000; font-weight: normal } /* Keyword.Pseudo */
24
+ .kr { color: #000000; font-weight: normal } /* Keyword.Reserved */
25
+ .kt { color: #445588; font-weight: normal } /* Keyword.Type */
26
+ .m { color: #009999 } /* Literal.Number */
27
+ .s { color: #d01040 } /* Literal.String */
28
+ .na { color: #008080 } /* Name.Attribute */
29
+ .nb { color: #0086B3 } /* Name.Builtin */
30
+ .nc { color: #445588; font-weight: normal } /* Name.Class */
31
+ .no { color: #008080 } /* Name.Constant */
32
+ .nd { color: #3c5d5d; font-weight: normal } /* Name.Decorator */
33
+ .ni { color: #800080 } /* Name.Entity */
34
+ .ne { color: #990000; font-weight: normal } /* Name.Exception */
35
+ .nf { color: #990000; font-weight: normal } /* Name.Function */
36
+ .nl { color: #990000; font-weight: normal } /* Name.Label */
37
+ .nn { color: #555555 } /* Name.Namespace */
38
+ .nt { color: #000080 } /* Name.Tag */
39
+ .nv { color: #008080 } /* Name.Variable */
40
+ .ow { color: #000000; font-weight: normal } /* Operator.Word */
41
+ .w { color: #bbbbbb } /* Text.Whitespace */
42
+ .mf { color: #009999 } /* Literal.Number.Float */
43
+ .mh { color: #009999 } /* Literal.Number.Hex */
44
+ .mi { color: #009999 } /* Literal.Number.Integer */
45
+ .mo { color: #009999 } /* Literal.Number.Oct */
46
+ .sb { color: #d01040 } /* Literal.String.Backtick */
47
+ .sc { color: #d01040 } /* Literal.String.Char */
48
+ .sd { color: #d01040 } /* Literal.String.Doc */
49
+ .s2 { color: #d01040 } /* Literal.String.Double */
50
+ .se { color: #d01040 } /* Literal.String.Escape */
51
+ .sh { color: #d01040 } /* Literal.String.Heredoc */
52
+ .si { color: #d01040 } /* Literal.String.Interpol */
53
+ .sx { color: #d01040 } /* Literal.String.Other */
54
+ .sr { color: #009926 } /* Literal.String.Regex */
55
+ .s1 { color: #d01040 } /* Literal.String.Single */
56
+ .ss { color: #990073 } /* Literal.String.Symbol */
57
+ .bp { color: #999999 } /* Name.Builtin.Pseudo */
58
+ .vc { color: #008080 } /* Name.Variable.Class */
59
+ .vg { color: #008080 } /* Name.Variable.Global */
60
+ .vi { color: #008080 } /* Name.Variable.Instance */
61
+ .il { color: #009999 } /* Literal.Number.Integer.Long */
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postmarkdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Weathered
@@ -82,7 +82,7 @@ dependencies:
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  - !ruby/object:Gem::Dependency
85
- name: rdiscount
85
+ name: redcarpet
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - ">="
@@ -109,6 +109,20 @@ dependencies:
109
109
  - - ">="
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: rouge
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
112
126
  - !ruby/object:Gem::Dependency
113
127
  name: appraisal
114
128
  requirement: !ruby/object:Gem::Requirement
@@ -236,6 +250,7 @@ files:
236
250
  - lib/postmarkdown.rb
237
251
  - lib/postmarkdown/config.rb
238
252
  - lib/postmarkdown/engine.rb
253
+ - lib/postmarkdown/markdown_renderer.rb
239
254
  - lib/postmarkdown/railtie.rb
240
255
  - lib/postmarkdown/routes.rb
241
256
  - lib/postmarkdown/util.rb
@@ -273,6 +288,7 @@ files:
273
288
  - spec/support/data/posts/2015-02-13-custom-title.markdown
274
289
  - spec/support/data/posts/missing-date-from-filename.markdown
275
290
  - vendor/assets/stylesheets/postmarkdown/postmarkdown.css
291
+ - vendor/assets/stylesheets/postmarkdown/syntax/github.css
276
292
  homepage: ''
277
293
  licenses:
278
294
  - MIT