middleman-syntax 1.1.1 → 1.2.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: 31ff85827507a7caad10ae8dccff687f547edced
4
- data.tar.gz: d31823eb1983846b162e3de7bcea55f31499926a
3
+ metadata.gz: b4d472a90adef6ca025bcac82d3f00f6546d0083
4
+ data.tar.gz: 72e518ba6b0ee79bcbd16c9382bad88d3cffad25
5
5
  SHA512:
6
- metadata.gz: d5d1a42e3270f30f5537293a0832daeddf3f0686199ca8eb5cfa006ced13d9d5cd4afae1a552286d5efa8c9eebd13c04d6c5572458e277cb2527a2b8576db5ed
7
- data.tar.gz: fbcb4c67df6efac0c072f1033f15286cb3faf92501fdff115709956a472743be7041012ada7d98a07da2e291a7588f3f4295ee61ace1de319df7f7c94a4b3f11
6
+ metadata.gz: 854f1f201cf18fe0d765a3e20a6106466e2bd743475228aebcb32747a067daa0961442bfd1ffada7f0e64d6f3f9c38bf6785658c76a2992585074975db95fc82
7
+ data.tar.gz: 09db1d1c2d64c46ac851b5fd99595086a7f914ccdb192f54d95de7b8658501e7cafdb04c52a1ce6f9daa68df5cff70ff51f644a361cf24fa9d7cd9384bde080e
data/.travis.yml CHANGED
@@ -1,15 +1,10 @@
1
1
  rvm:
2
2
  - 1.8.7
3
- - 1.9.2
4
3
  - 1.9.3
4
+ - 2.0.0
5
5
  - jruby-18mode
6
6
  - jruby-19mode
7
7
 
8
8
  script: "bundle exec rake test"
9
9
 
10
10
  env: TEST=true TRAVIS=true
11
-
12
- matrix:
13
- allow_failures:
14
- - rvm: jruby-18mode
15
- - rvm: jruby-19mode
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ 1.2.0
2
+ ------
3
+
4
+ * Support Kramdown as Markdown engine in addition to Redcarpet.
5
+ * Switch to Rouge from Pygments.rb
6
+ * Fix bugs around setting language options.
7
+
8
+ 1.1.1
9
+ -----
10
+
11
+ * Properly merge language attribute for Markdown. #14
12
+
1
13
  1.1.0
2
14
  -----
3
15
 
data/Gemfile CHANGED
@@ -1,23 +1,23 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  git "git://github.com/middleman/middleman.git" do
4
- # gem "middleman"
5
4
  gem "middleman-core"
6
- # gem "middleman-more"
7
5
  end
8
6
 
9
7
  # Specify your gem's dependencies in middleman-blog.gemspec
10
8
  gemspec
11
9
 
12
- group :development do
13
- gem "rake", "~> 0.9.2"
14
- gem "rdoc", "~> 3.9"
15
- gem "yard", "~> 0.8.0"
16
- end
10
+ gem 'padrino-helpers'
11
+ gem 'kramdown'
17
12
 
18
- group :test do
19
- gem "cucumber", "~> 1.2.0"
20
- gem "fivemat"
21
- gem "aruba", "~> 0.4.11"
22
- gem "rspec", "~> 2.7"
13
+ platforms :ruby do
14
+ gem 'redcarpet'
23
15
  end
16
+
17
+ gem "rake", "~> 0.9.2"
18
+ gem "rdoc", "~> 3.9"
19
+ gem "yard", "~> 0.8.0"
20
+ gem "cucumber", "~> 1.2.0"
21
+ gem "fivemat"
22
+ gem "aruba", "~> 0.4.11"
23
+ gem "rspec", "~> 2.7"
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # middleman-syntax
2
2
 
3
- middleman-syntax is an extension for the [Middleman](http://middlemanapp.com) static site generator that adds syntax highlighting via [Pygments](http://pygments.org/).
3
+ middleman-syntax is an extension for the [Middleman](http://middlemanapp.com) static site generator that adds syntax highlighting via [Rouge](https://github.com/jayferd/rouge).
4
4
 
5
5
  # Install
6
6
  If you're just getting started, install the `middleman` gem and generate a new project:
@@ -17,7 +17,7 @@ Add `middleman-syntax` to your `Gemfile`, run `bundle install`, then open your `
17
17
  activate :syntax
18
18
  ```
19
19
 
20
- You can also pass options to pygments:
20
+ You can also pass options to Rouge:
21
21
 
22
22
  ```
23
23
  activate :syntax,
@@ -26,9 +26,7 @@ activate :syntax,
26
26
  :linenostart => 2
27
27
  ```
28
28
 
29
- See the [pygments documentation](http://pygments.org/docs/formatters/) for a full list of possible options.
30
-
31
- # Usage
29
+ # Helper
32
30
 
33
31
  The extension adds a new `code` helper to Middleman that you can use from your templates:
34
32
 
@@ -40,18 +38,34 @@ end
40
38
  <% end %>
41
39
  ```
42
40
 
43
- That'll produce syntax-highlighted HTML wrapped in a `<pre>` tag, wrapped in `<div class="hightlight">`. You can style this with any CSS that works on Pygments output.
41
+ That'll produce syntax-highlighted HTML wrapped in `<pre class="highlight ruby">`.
42
+
43
+ # CSS
44
+
45
+ On a default (i.e. unstyled) Middleman project, it will appear as if `middleman-syntax` isn't working, since obviously no CSS has been applied to color your code. You can use any Pygments-compatible stylesheet to style your code.
44
46
 
45
- **Note** that on a default (i.e. unstyled) Middleman project, it will appear as if `middleman-syntax` isn't working, since none of the Pygments styles have any CSS applied! Open the browser Developer Tools to verify the code is being syntax highlighted.
47
+ You can also let Rouge generate some CSS for you by creating a new stylesheet with a `.css.erb` extension in your Middleman project, and then including:
46
48
 
47
- The extension also makes code blocks in Markdown highlight code. Make sure you're using RedCarpet as your Markdown engine (in `config.rb`):
49
+ ```erb
50
+ <%= Rouge::Themes::ThankfulEyes.render(:scope => '.highlight') %>
51
+ ```
52
+
53
+ Rouge has `ThankfulEyes`, `Colorful`, `Base16`, `Solarized` (like Octopress), and `Monokai` themes.
54
+
55
+ # Markdown
56
+
57
+ The extension also makes code blocks in Markdown produce highlighted code. Make sure you're using RedCarpet or Kramdown as your Markdown engine (in `config.rb`):
48
58
 
49
59
  ```ruby
50
60
  set :markdown_engine, :redcarpet
51
61
  set :markdown, :fenced_code_blocks => true, :smartypants => true
62
+
63
+ # OR
64
+
65
+ set :markdown_engine, :kramdown
52
66
  ```
53
67
 
54
- Now your Markdown will work just like it does [on GitHub](http://github.github.com/github-flavored-markdown/) - you can write something like this:
68
+ Now your Markdown will work just like it does [on GitHub](http://github.github.com/github-flavored-markdown/) - you can write something like this with Redcarpet:
55
69
 
56
70
  <pre>
57
71
  ```ruby
@@ -61,6 +75,16 @@ end
61
75
  ```
62
76
  </pre>
63
77
 
78
+ or with Kramdown:
79
+
80
+ <pre>
81
+ ~~~ ruby
82
+ def my_cool_method(message)
83
+ puts message
84
+ end
85
+ ~~~
86
+ </pre>
87
+
64
88
  # Bug Reports
65
89
 
66
90
  GitHub Issues are used for managing bug reports and feature requests. If you run into issues, please search the issues and submit new problems:
data/Rakefile CHANGED
@@ -4,11 +4,8 @@ Bundler::GemHelper.install_tasks
4
4
  require 'cucumber/rake/task'
5
5
 
6
6
  Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
7
- ENV["TEST"] = "true"
8
-
9
7
  exempt_tags = ""
10
8
  exempt_tags << "--tags ~@nojava" if RUBY_PLATFORM == "java"
11
-
12
9
  t.cucumber_opts = "--color --tags ~@wip #{exempt_tags} --strict --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}"
13
10
  end
14
11
 
@@ -19,4 +16,4 @@ task :test => ["cucumber"]
19
16
  desc "Build HTML documentation"
20
17
  task :doc do
21
18
  sh 'bundle exec yard'
22
- end
19
+ end
@@ -0,0 +1,7 @@
1
+ Feature: Syntax highlighting with the "code" helper method
2
+
3
+ Scenario: Works from ERb
4
+ Given the Server is running at "test-app"
5
+ When I go to "/code_html.html"
6
+ Then I should see '<span class="k">def</span>'
7
+ Then I should see '<pre class="highlight text">This is some code'
@@ -0,0 +1,22 @@
1
+ Feature: Code blocks in markdown get highlighted
2
+
3
+ Scenario: Works with Kramdown
4
+ Given the Server is running at "test-app"
5
+ When I go to "/code.html"
6
+ Then I should see '<span class="k">def</span>'
7
+ Then I should see '<pre class="highlight text">This is some code'
8
+
9
+ @nojava
10
+ Scenario: Works with RedCarpet
11
+ Given a fixture app "test-app"
12
+ And a file named "config.rb" with:
13
+ """
14
+ set :markdown_engine, :redcarpet
15
+ set :markdown, :fenced_code_blocks => true
16
+ activate :syntax
17
+ """
18
+ Given the Server is running at "test-app"
19
+ When I go to "/code.html"
20
+ Then I should see '<span class="k">def</span>'
21
+ Then I should see '<pre class="highlight text">This is some code'
22
+
@@ -0,0 +1,6 @@
1
+ PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
2
+ ENV['TEST'] = 'true'
3
+ require "middleman-core"
4
+ require "middleman-core/step_definitions"
5
+ require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-syntax')
6
+
@@ -0,0 +1 @@
1
+ activate :syntax
@@ -0,0 +1,13 @@
1
+ # Ruby
2
+
3
+ ~~~ruby
4
+ def foo(bar)
5
+ puts "baz"
6
+ end
7
+ ~~~
8
+
9
+ # Whatever
10
+
11
+ ~~~
12
+ This is some code
13
+ ~~~
@@ -0,0 +1,14 @@
1
+
2
+ <h1>Ruby</h1>
3
+
4
+ <% code('ruby') do %>
5
+ def foo(bar)
6
+ puts "baz"
7
+ end
8
+ <% end %>
9
+
10
+ <h1>Whatever</h1>
11
+
12
+ <% code do %>
13
+ This is some code
14
+ <% end %>
@@ -7,19 +7,46 @@ module Middleman
7
7
  end
8
8
 
9
9
  def registered(app, options_hash={})
10
- require 'pygments'
10
+ require 'rouge'
11
11
 
12
12
  @@options = options_hash
13
13
  yield @@options if block_given?
14
14
 
15
15
  app.send :include, Helper
16
16
 
17
- require 'middleman-core/renderers/redcarpet'
18
- Middleman::Renderers::MiddlemanRedcarpetHTML.send :include, MarkdownCodeRenderer
17
+ if app.markdown_engine == :redcarpet
18
+ begin
19
+ require 'middleman-core/renderers/redcarpet'
20
+ Middleman::Renderers::MiddlemanRedcarpetHTML.send :include, MarkdownCodeRenderer
21
+ rescue LoadError
22
+ end
23
+ else
24
+ begin
25
+ require 'kramdown'
26
+ Kramdown::Converter::Html.class_eval do
27
+ def convert_codeblock(el, indent)
28
+ attr = el.attr.dup
29
+ language = extract_code_language!(attr)
30
+ Middleman::Syntax::Highlighter.highlight(el.value, language)
31
+ end
32
+ end
33
+ rescue LoadError
34
+ end
35
+ end
19
36
  end
20
37
  alias :included :registered
21
38
  end
22
39
 
40
+ module Highlighter
41
+ # A helper module for highlighting code
42
+ def self.highlight(code, language)
43
+ opts = ::Middleman::Syntax.options.dup
44
+ lexer = Rouge::Lexer.find_fancy(language, code) || Rouge::Lexers::Text
45
+ formatter = Rouge::Formatters::HTML.new(opts.reverse_merge({ :css_class => "highlight #{lexer.tag}" }))
46
+ formatter.format(lexer.lex(code, opts))
47
+ end
48
+ end
49
+
23
50
  module Helper
24
51
 
25
52
  # Output highlighted code. Use like:
@@ -51,16 +78,13 @@ module Middleman
51
78
  @_out_buf = _buf_was
52
79
  end
53
80
 
54
- options = ::Middleman::Syntax.options.merge :lexer => language
55
- concat_content Pygments.highlight(code, :options => options)
81
+ concat_content Middleman::Syntax::Highlighter.highlight(content, language)
56
82
  end
57
83
  end
58
84
 
59
85
  module MarkdownCodeRenderer
60
86
  def block_code(code, language)
61
- options = ::Middleman::Syntax.options
62
- options.merge! :lexer => language if language
63
- Pygments.highlight(code, :options => options)
87
+ Middleman::Syntax::Highlighter.highlight(code, language)
64
88
  end
65
89
  end
66
90
  end
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module Syntax
3
- VERSION = "1.1.1"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
@@ -16,5 +16,5 @@ Gem::Specification.new do |s|
16
16
  s.require_paths = ["lib"]
17
17
 
18
18
  s.add_runtime_dependency("middleman-core", "~> 3.0")
19
- s.add_runtime_dependency("pygments.rb", "~> 0.3")
19
+ s.add_runtime_dependency("rouge", "~> 0.3.0")
20
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-syntax
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Hollis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-27 00:00:00.000000000 Z
11
+ date: 2013-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman-core
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: pygments.rb
28
+ name: rouge
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: '0.3'
33
+ version: 0.3.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: '0.3'
40
+ version: 0.3.0
41
41
  description: Syntax-highlighting helpers for Middleman
42
42
  email:
43
43
  - ben@benhollis.net
@@ -51,6 +51,12 @@ files:
51
51
  - Gemfile
52
52
  - README.md
53
53
  - Rakefile
54
+ - features/helper.feature
55
+ - features/markdown.feature
56
+ - features/support/env.rb
57
+ - fixtures/test-app/config.rb
58
+ - fixtures/test-app/source/code.html.markdown
59
+ - fixtures/test-app/source/code_html.html.erb
54
60
  - lib/middleman-syntax.rb
55
61
  - lib/middleman-syntax/extension.rb
56
62
  - lib/middleman-syntax/helper.rb
@@ -76,9 +82,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
82
  version: '0'
77
83
  requirements: []
78
84
  rubyforge_project:
79
- rubygems_version: 2.0.0
85
+ rubygems_version: 2.0.3
80
86
  signing_key:
81
87
  specification_version: 4
82
88
  summary: Syntax-highlighting helpers for Middleman
83
- test_files: []
89
+ test_files:
90
+ - features/helper.feature
91
+ - features/markdown.feature
92
+ - features/support/env.rb
93
+ - fixtures/test-app/config.rb
94
+ - fixtures/test-app/source/code.html.markdown
95
+ - fixtures/test-app/source/code_html.html.erb
84
96
  has_rdoc: