middleman-syntax 1.2.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -4
- data/CHANGELOG.md +10 -0
- data/CONTRIBUTING.md +44 -0
- data/Gemfile +17 -15
- data/LICENSE.md +20 -0
- data/README.md +88 -21
- data/Rakefile +14 -1
- data/features/haml_filter.feature +13 -0
- data/features/helper.feature +13 -1
- data/features/markdown.feature +9 -3
- data/fixtures/test-app/source/code_haml.html.haml +12 -0
- data/fixtures/test-app/source/code_haml_filter.html.haml +12 -0
- data/fixtures/test-app/source/code_slim.html.slim +13 -0
- data/lib/middleman-syntax.rb +2 -2
- data/lib/middleman-syntax/extension.rb +92 -66
- data/lib/middleman-syntax/version.rb +1 -1
- data/middleman-syntax.gemspec +15 -15
- metadata +29 -19
- data/lib/middleman-syntax/helper.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aaea147a35d96f79a1262dedd8cedf4f23e922b5
|
4
|
+
data.tar.gz: 3fa14ae2cfc06539e836fb4811b399fef247bfbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6077c385b77b2c272b4be65f0b5038101bdc89bf2360ec0c26b8f9ec084062ca783a6eb33f77a53b2d9e4181b18b0179a48940650a6c25bf97665d3b1256df19
|
7
|
+
data.tar.gz: bf1524cd553efb103bb8b2f7b9c51f0637c671f72629b82834eb47f30b7c41cd7a59619c433b1a634b66c7ac600c38529207dfefc9627dd2cf50b0cbea9e85f6
|
data/.travis.yml
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
rvm:
|
2
|
-
- 1.8.7
|
3
2
|
- 1.9.3
|
4
3
|
- 2.0.0
|
5
|
-
-
|
4
|
+
- 2.1.0
|
6
5
|
- jruby-19mode
|
7
|
-
|
6
|
+
|
7
|
+
# Bug in jRuby w/ Rouge: https://github.com/jruby/jruby/issues/1392
|
8
|
+
matrix:
|
9
|
+
allow_failures:
|
10
|
+
- rvm: jruby-19mode
|
11
|
+
|
8
12
|
script: "bundle exec rake test"
|
9
13
|
|
10
|
-
env: TEST=true
|
14
|
+
env: TEST=true
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
2.0.0 (master)
|
2
|
+
-----
|
3
|
+
|
4
|
+
* Update to a new-style Middleman extension, dropping compatibility with Middleman versions older than 3.2.x.
|
5
|
+
* Setting the :css_class option will no longer prevent the language tag from being added as a class as well.
|
6
|
+
* Rouge lexer options should now be set via the :lexer_options option.
|
7
|
+
* It is now possible to override options when calling the `code` helper by passing them as the second argument.
|
8
|
+
* Using the `code` helper from Slim templates no longer escapes the output.
|
9
|
+
* Added a `:code` filter for Haml as a more whitespace-friendly alternative to the `code` helper.
|
10
|
+
|
1
11
|
1.2.1
|
2
12
|
-----
|
3
13
|
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Contributing
|
2
|
+
In the spirit of [free software][free-sw], **everyone** is encouraged to help
|
3
|
+
improve this project.
|
4
|
+
|
5
|
+
[free-sw]: http://www.fsf.org/licensing/essays/free-sw.html
|
6
|
+
|
7
|
+
Here are some ways *you* can contribute:
|
8
|
+
|
9
|
+
* by using alpha, beta, and prerelease versions
|
10
|
+
* by reporting bugs
|
11
|
+
* by suggesting new features
|
12
|
+
* by writing or editing documentation
|
13
|
+
* by writing specifications
|
14
|
+
* by writing code (**no patch is too small**: fix typos, add comments, clean up
|
15
|
+
inconsistent whitespace)
|
16
|
+
* by refactoring code
|
17
|
+
* by closing [issues][]
|
18
|
+
* by reviewing patches
|
19
|
+
|
20
|
+
[issues]: https://github.com/middleman/middleman-syntax/issues
|
21
|
+
|
22
|
+
## Submitting an Issue
|
23
|
+
We use the [GitHub issue tracker][issues] to track bugs and features. Before
|
24
|
+
submitting a bug report or feature request, check to make sure it hasn't
|
25
|
+
already been submitted. When submitting a bug report, please include a [Gist][]
|
26
|
+
that includes a stack trace and any details that may be necessary to reproduce
|
27
|
+
the bug, including your gem version, Ruby version, and operating system.
|
28
|
+
Ideally, a bug report should include a pull request with failing specs.
|
29
|
+
|
30
|
+
[gist]: https://gist.github.com/
|
31
|
+
|
32
|
+
## Submitting a Pull Request
|
33
|
+
1. [Fork the repository.][fork]
|
34
|
+
2. [Create a topic branch.][branch]
|
35
|
+
3. Add specs for your unimplemented feature or bug fix.
|
36
|
+
4. Run `bundle exec rake test`. If your specs pass, return to step 3.
|
37
|
+
5. Implement your feature or bug fix.
|
38
|
+
6. Run `bundle exec rake test`. If your specs fail, return to step 5.
|
39
|
+
7. Add, commit, and push your changes.
|
40
|
+
8. [Submit a pull request.][pr]
|
41
|
+
|
42
|
+
[fork]: http://help.github.com/fork-a-repo/
|
43
|
+
[branch]: http://learn.github.com/p/branching.html
|
44
|
+
[pr]: http://help.github.com/send-pull-requests/
|
data/Gemfile
CHANGED
@@ -1,23 +1,25 @@
|
|
1
|
-
source
|
1
|
+
source "https://rubygems.org"
|
2
2
|
|
3
|
-
|
4
|
-
gem "middleman-core"
|
5
|
-
end
|
3
|
+
gem "middleman", :github => "middleman/middleman", :branch => 'v3-stable'
|
6
4
|
|
7
|
-
# Specify your gem's dependencies in middleman-
|
5
|
+
# Specify your gem's dependencies in middleman-syntax.gemspec
|
8
6
|
gemspec
|
9
7
|
|
10
|
-
gem
|
11
|
-
gem
|
8
|
+
gem "rake", "~> 10.0.3", :require => false
|
9
|
+
gem "yard", "~> 0.8.0", :require => false
|
10
|
+
|
11
|
+
# Test tools
|
12
|
+
gem "cucumber", "~> 1.3.1"
|
13
|
+
gem "fivemat"
|
14
|
+
gem "aruba", "~> 0.5.1"
|
15
|
+
gem "rspec", "~> 2.12"
|
12
16
|
|
13
17
|
platforms :ruby do
|
14
|
-
gem
|
18
|
+
gem "redcarpet"
|
15
19
|
end
|
16
20
|
|
17
|
-
gem "
|
18
|
-
gem "
|
19
|
-
|
20
|
-
|
21
|
-
gem "
|
22
|
-
gem "aruba", "~> 0.4.11"
|
23
|
-
gem "rspec", "~> 2.7"
|
21
|
+
gem "kramdown"
|
22
|
+
gem "slim"
|
23
|
+
|
24
|
+
# Code Quality
|
25
|
+
gem "cane", :platforms => [:mri_19, :mri_20], :require => false
|
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012-2013 Benjamin Hollis
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,32 +1,40 @@
|
|
1
|
-
#
|
1
|
+
# Middleman-Syntax
|
2
2
|
|
3
|
-
middleman-syntax is an extension for the [Middleman]
|
3
|
+
`middleman-syntax` is an extension for the [Middleman] static site generator that adds syntax highlighting via [Rouge](https://github.com/jayferd/rouge).
|
4
|
+
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/middleman-syntax.png)][gem]
|
6
|
+
[![Build Status](https://travis-ci.org/middleman/middleman-syntax.png)][travis]
|
7
|
+
[![Dependency Status](https://gemnasium.com/middleman/middleman-syntax.png?travis)][gemnasium]
|
8
|
+
[![Code Quality](https://codeclimate.com/github/middleman/middleman-syntax.png)][codeclimate]
|
9
|
+
|
10
|
+
## Installation
|
4
11
|
|
5
|
-
# Install
|
6
12
|
If you're just getting started, install the `middleman` gem and generate a new project:
|
7
13
|
|
8
|
-
```
|
14
|
+
```bash
|
9
15
|
gem install middleman
|
10
16
|
middleman init MY_PROJECT
|
11
17
|
```
|
12
18
|
|
13
|
-
If you already have a Middleman project:
|
14
|
-
Add `middleman-syntax` to your `Gemfile`, run `bundle install`, then open your `config.rb` and add:
|
19
|
+
If you already have a Middleman project: Add `gem "middleman-syntax"` to your `Gemfile` and run `bundle install`.
|
15
20
|
|
16
|
-
|
21
|
+
**This plugin will not work on Ruby 1.8!** Rouge requires 1.9+, so we do too.
|
22
|
+
|
23
|
+
## Configuration
|
24
|
+
|
25
|
+
```ruby
|
17
26
|
activate :syntax
|
18
27
|
```
|
19
28
|
|
20
29
|
You can also pass options to Rouge:
|
21
30
|
|
31
|
+
```ruby
|
32
|
+
activate :syntax, :line_numbers => true
|
22
33
|
```
|
23
|
-
activate :syntax,
|
24
|
-
:linenos => 'inline',
|
25
|
-
:anchorlinenos => true,
|
26
|
-
:linenostart => 2
|
27
|
-
```
|
28
34
|
|
29
|
-
|
35
|
+
The full set of options can be seen on your preview server's `/__middleman/config/` page.
|
36
|
+
|
37
|
+
## Helper
|
30
38
|
|
31
39
|
The extension adds a new `code` helper to Middleman that you can use from your templates:
|
32
40
|
|
@@ -40,7 +48,7 @@ end
|
|
40
48
|
|
41
49
|
That'll produce syntax-highlighted HTML wrapped in `<pre class="highlight ruby">`.
|
42
50
|
|
43
|
-
|
51
|
+
## CSS
|
44
52
|
|
45
53
|
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.
|
46
54
|
|
@@ -50,9 +58,9 @@ You can also let Rouge generate some CSS for you by creating a new stylesheet wi
|
|
50
58
|
<%= Rouge::Themes::ThankfulEyes.render(:scope => '.highlight') %>
|
51
59
|
```
|
52
60
|
|
53
|
-
Rouge has `ThankfulEyes`, `Colorful`, `Base16`, `Solarized` (like Octopress), and `Monokai` themes.
|
61
|
+
Rouge has `ThankfulEyes`, `Colorful`, `Github`, `Base16`, `Base16::Solarized` (like Octopress), `Base16::Monokai`, and `Monokai` themes.
|
54
62
|
|
55
|
-
|
63
|
+
## Markdown
|
56
64
|
|
57
65
|
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`):
|
58
66
|
|
@@ -60,7 +68,7 @@ The extension also makes code blocks in Markdown produce highlighted code. Make
|
|
60
68
|
set :markdown_engine, :redcarpet
|
61
69
|
set :markdown, :fenced_code_blocks => true, :smartypants => true
|
62
70
|
|
63
|
-
|
71
|
+
## OR
|
64
72
|
|
65
73
|
set :markdown_engine, :kramdown
|
66
74
|
```
|
@@ -85,10 +93,69 @@ end
|
|
85
93
|
~~~
|
86
94
|
</pre>
|
87
95
|
|
88
|
-
|
96
|
+
## Haml
|
97
|
+
|
98
|
+
When using Haml, a `:code` filter is exposed for outputting highlighted code. Because Haml filters don't allow arguments, you must use a special comment to indicate the language of the code to be highlighted (or let Rouge guess):
|
99
|
+
|
100
|
+
```haml
|
101
|
+
#example
|
102
|
+
:code
|
103
|
+
# lang: ruby
|
104
|
+
|
105
|
+
def foo
|
106
|
+
puts 'bar'
|
107
|
+
end
|
108
|
+
```
|
109
|
+
|
110
|
+
With the special `# lang: <language tag>` comment on the first line, the `:code` filter is just like calling the `code` helper, but without the indentation problems that Haml might otherwise have. However, if you prefer, you can use the `code` helper along with the `:preserve` filter, as explained below.
|
111
|
+
|
112
|
+
## Indentation Problems
|
113
|
+
|
114
|
+
Some templating languages, like Haml, will indent your HTML for you,
|
115
|
+
which will mess up code formatted in `<pre>` tags. When
|
116
|
+
using Haml, either use the `:code` filter (recommended), use the
|
117
|
+
[`:preserve`](http://haml.info/docs/yardoc/file.REFERENCE.html#preserve-filter)
|
118
|
+
filter, or add `set :haml, { ugly: true }` in your `config.rb` to turn off
|
119
|
+
Haml's automatic indentation.
|
120
|
+
|
121
|
+
Example of using `:preserve`:
|
122
|
+
|
123
|
+
```haml
|
124
|
+
- code('ruby') do
|
125
|
+
:preserve
|
126
|
+
def foo
|
127
|
+
puts 'bar'
|
128
|
+
end
|
129
|
+
```
|
130
|
+
|
131
|
+
## Community
|
132
|
+
|
133
|
+
The official community forum is available at: http://forum.middlemanapp.com
|
134
|
+
|
135
|
+
## Bug Reports
|
136
|
+
|
137
|
+
Github Issues are used for managing bug reports and feature requests. If you run into issues, please search the issues and submit new problems: https://github.com/middleman/middleman-syntax/issues
|
138
|
+
|
139
|
+
The best way to get quick responses to your issues and swift fixes to your bugs is to submit detailed bug reports, include test cases and respond to developer questions in a timely manner. Even better, if you know Ruby, you can submit [Pull Requests](https://help.github.com/articles/using-pull-requests) containing Cucumber Features which describe how your feature should work or exploit the bug you are submitting.
|
140
|
+
|
141
|
+
## How to Run Cucumber Tests
|
142
|
+
|
143
|
+
1. Checkout Repository: `git clone https://github.com/middleman/middleman-syntax.git`
|
144
|
+
2. Install Bundler: `gem install bundler`
|
145
|
+
3. Run `bundle install` inside the project root to install the gem dependencies.
|
146
|
+
4. Run test cases: `bundle exec rake test`
|
147
|
+
|
148
|
+
## Donate
|
149
|
+
|
150
|
+
[Click here to lend your support to Middleman](https://spacebox.io/s/4dXbHBorC3)
|
89
151
|
|
90
|
-
|
152
|
+
## License
|
91
153
|
|
92
|
-
|
154
|
+
Copyright (c) 2012-2013 Benjamin Hollis. MIT Licensed, see [LICENSE] for details.
|
93
155
|
|
94
|
-
|
156
|
+
[middleman]: http://middlemanapp.com
|
157
|
+
[gem]: https://rubygems.org/gems/middleman-syntax
|
158
|
+
[travis]: http://travis-ci.org/middleman/middleman-syntax
|
159
|
+
[gemnasium]: https://gemnasium.com/middleman/middleman-syntax
|
160
|
+
[codeclimate]: https://codeclimate.com/github/middleman/middleman-syntax
|
161
|
+
[LICENSE]: https://github.com/middleman/middleman-syntax/blob/master/LICENSE.md
|
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ require 'cucumber/rake/task'
|
|
5
5
|
|
6
6
|
Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
|
7
7
|
exempt_tags = ""
|
8
|
-
exempt_tags << "--tags ~@nojava" if RUBY_PLATFORM == "java"
|
8
|
+
exempt_tags << "--tags ~@nojava " if RUBY_PLATFORM == "java"
|
9
9
|
t.cucumber_opts = "--color --tags ~@wip #{exempt_tags} --strict --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}"
|
10
10
|
end
|
11
11
|
|
@@ -13,6 +13,19 @@ require 'rake/clean'
|
|
13
13
|
|
14
14
|
task :test => ["cucumber"]
|
15
15
|
|
16
|
+
begin
|
17
|
+
require 'cane/rake_task'
|
18
|
+
|
19
|
+
desc "Run cane to check quality metrics"
|
20
|
+
Cane::RakeTask.new(:quality) do |cane|
|
21
|
+
cane.no_style = true
|
22
|
+
cane.no_doc = true
|
23
|
+
cane.abc_glob = "lib/middleman-syntax/**/*.rb"
|
24
|
+
end
|
25
|
+
rescue LoadError
|
26
|
+
# warn "cane not available, quality task not provided."
|
27
|
+
end
|
28
|
+
|
16
29
|
desc "Build HTML documentation"
|
17
30
|
task :doc do
|
18
31
|
sh 'bundle exec yard'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Feature: Haml :code filter.
|
2
|
+
|
3
|
+
Scenario: Filter works and preserved indentation
|
4
|
+
Given a fixture app "test-app"
|
5
|
+
And a file named "config.rb" with:
|
6
|
+
"""
|
7
|
+
set :haml, { :ugly => false }
|
8
|
+
activate :syntax
|
9
|
+
"""
|
10
|
+
Given the Server is running at "test-app"
|
11
|
+
When I go to "/code_haml_filter.html"
|
12
|
+
Then I should see '<span class="k">def</span>'
|
13
|
+
Then I should see '<pre class="highlight plaintext">This is some code'
|
data/features/helper.feature
CHANGED
@@ -4,4 +4,16 @@ Feature: Syntax highlighting with the "code" helper method
|
|
4
4
|
Given the Server is running at "test-app"
|
5
5
|
When I go to "/code_html.html"
|
6
6
|
Then I should see '<span class="k">def</span>'
|
7
|
-
Then I should see '<pre class="highlight
|
7
|
+
Then I should see '<pre class="highlight plaintext">This is some code'
|
8
|
+
|
9
|
+
Scenario: Works from Haml
|
10
|
+
Given the Server is running at "test-app"
|
11
|
+
When I go to "/code_haml.html"
|
12
|
+
Then I should see '<span class="k">def</span>'
|
13
|
+
Then I should see '<pre class="highlight plaintext">This is some code'
|
14
|
+
|
15
|
+
Scenario: Works from Slim
|
16
|
+
Given the Server is running at "test-app"
|
17
|
+
When I go to "/code_slim.html"
|
18
|
+
Then I should see '<span class="k">def</span>'
|
19
|
+
Then I should see '<pre class="highlight plaintext">This is some code'
|
data/features/markdown.feature
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
Feature: Code blocks in markdown get highlighted
|
2
2
|
|
3
3
|
Scenario: Works with Kramdown
|
4
|
+
Given a fixture app "test-app"
|
5
|
+
And a file named "config.rb" with:
|
6
|
+
"""
|
7
|
+
set :markdown_engine, :kramdown
|
8
|
+
activate :syntax
|
9
|
+
"""
|
4
10
|
Given the Server is running at "test-app"
|
5
11
|
When I go to "/code.html"
|
6
12
|
Then I should see '<span class="k">def</span>'
|
7
|
-
Then I should see '<pre class="highlight
|
13
|
+
Then I should see '<pre class="highlight plaintext">This is some code'
|
8
14
|
|
9
15
|
@nojava
|
10
16
|
Scenario: Works with RedCarpet
|
@@ -18,5 +24,5 @@ Feature: Code blocks in markdown get highlighted
|
|
18
24
|
Given the Server is running at "test-app"
|
19
25
|
When I go to "/code.html"
|
20
26
|
Then I should see '<span class="k">def</span>'
|
21
|
-
Then I should see '<pre class="highlight
|
22
|
-
|
27
|
+
Then I should see '<pre class="highlight plaintext">This is some code'
|
28
|
+
|
data/lib/middleman-syntax.rb
CHANGED
@@ -1,87 +1,113 @@
|
|
1
|
+
require 'rouge'
|
2
|
+
|
1
3
|
module Middleman
|
2
4
|
module Syntax
|
3
|
-
class
|
5
|
+
class SyntaxExtension < Extension
|
6
|
+
option :css_class, 'highlight', 'Class name applied to the syntax-highlighted output.'
|
7
|
+
option :line_numbers, false, 'Generate line numbers.'
|
8
|
+
option :inline_theme, nil, 'A Rouge::CSSTheme that will be used to highlight the output with inline styles instead of using CSS classes.'
|
9
|
+
option :wrap, true, 'Wrap the highlighted content in a container (<pre> or <div>, depending on whether :line_numbers is on).'
|
10
|
+
option :lexer_options, {}, 'Options for the Rouge lexers.'
|
4
11
|
|
5
|
-
def
|
6
|
-
|
7
|
-
end
|
12
|
+
def after_configuration
|
13
|
+
Middleman::Syntax::Highlighter.options = options
|
8
14
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
require 'middleman-core/renderers/redcarpet'
|
20
|
-
Middleman::Renderers::MiddlemanRedcarpetHTML.send :include, MarkdownCodeRenderer
|
21
|
-
elsif markdown_engine == :kramdown
|
22
|
-
require 'kramdown'
|
23
|
-
Kramdown::Converter::Html.class_eval do
|
24
|
-
def convert_codeblock(el, indent)
|
25
|
-
attr = el.attr.dup
|
26
|
-
language = extract_code_language!(attr)
|
27
|
-
Middleman::Syntax::Highlighter.highlight(el.value, language)
|
28
|
-
end
|
15
|
+
if app.config[:markdown_engine] == :redcarpet
|
16
|
+
require 'middleman-core/renderers/redcarpet'
|
17
|
+
Middleman::Renderers::MiddlemanRedcarpetHTML.send :include, RedcarpetCodeRenderer
|
18
|
+
elsif app.config[:markdown_engine] == :kramdown
|
19
|
+
require 'kramdown'
|
20
|
+
Kramdown::Converter::Html.class_eval do
|
21
|
+
def convert_codeblock(el, indent)
|
22
|
+
attr = el.attr.dup
|
23
|
+
language = extract_code_language!(attr)
|
24
|
+
Middleman::Syntax::Highlighter.highlight(el.value, language)
|
29
25
|
end
|
30
26
|
end
|
31
27
|
end
|
32
28
|
end
|
33
|
-
alias :included :registered
|
34
|
-
end
|
35
29
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
30
|
+
helpers do
|
31
|
+
# Output highlighted code. Use like:
|
32
|
+
#
|
33
|
+
# <% code('ruby') do %>
|
34
|
+
# my code
|
35
|
+
# <% end %>
|
36
|
+
#
|
37
|
+
# To produce the following structure:
|
38
|
+
#
|
39
|
+
# <div class="highlight">
|
40
|
+
# <pre>#{your code}
|
41
|
+
# </pre>
|
42
|
+
# </div>
|
43
|
+
#
|
44
|
+
# @param [String] language the Rouge lexer to use
|
45
|
+
# @param [Hash] Options to pass to the Rouge formatter & lexer, overriding global options set by :highlighter_options.
|
46
|
+
def code(language=nil, options={}, &block)
|
47
|
+
raise 'The code helper requires a block to be provided.' unless block_given?
|
45
48
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
# To produce the following structure:
|
55
|
-
#
|
56
|
-
# <div class="highlight">
|
57
|
-
# <pre>#{your code}
|
58
|
-
# </pre>
|
59
|
-
# </div>
|
60
|
-
#
|
61
|
-
# @param [String] language the Pygments lexer to use
|
62
|
-
def code(language=nil, &block)
|
63
|
-
# Save current buffer for later
|
64
|
-
@_out_buf, _buf_was = "", @_out_buf
|
65
|
-
|
66
|
-
begin
|
67
|
-
content = if block_given?
|
68
|
-
capture_html(&block)
|
69
|
-
else
|
70
|
-
""
|
49
|
+
# Save current buffer for later
|
50
|
+
@_out_buf, _buf_was = "", @_out_buf
|
51
|
+
|
52
|
+
begin
|
53
|
+
content = capture_html(&block)
|
54
|
+
ensure
|
55
|
+
# Reset stored buffer
|
56
|
+
@_out_buf = _buf_was
|
71
57
|
end
|
72
|
-
|
73
|
-
# Reset stored buffer
|
74
|
-
@_out_buf = _buf_was
|
75
|
-
end
|
58
|
+
content = content.encode(Encoding::UTF_8)
|
76
59
|
|
77
|
-
|
60
|
+
concat_content Middleman::Syntax::Highlighter.highlight(content, language).html_safe
|
61
|
+
end
|
78
62
|
end
|
79
63
|
end
|
80
64
|
|
81
|
-
|
65
|
+
# A mixin for the Redcarpet Markdown renderer that will highlight
|
66
|
+
# code.
|
67
|
+
module RedcarpetCodeRenderer
|
82
68
|
def block_code(code, language)
|
83
69
|
Middleman::Syntax::Highlighter.highlight(code, language)
|
84
70
|
end
|
85
71
|
end
|
72
|
+
|
73
|
+
module Highlighter
|
74
|
+
mattr_accessor :options
|
75
|
+
|
76
|
+
# A helper module for highlighting code
|
77
|
+
def self.highlight(code, language=nil, opts={})
|
78
|
+
lexer = Rouge::Lexer.find_fancy(language, code) || Rouge::Lexers::PlainText
|
79
|
+
|
80
|
+
highlighter_options = options.to_h.merge(opts)
|
81
|
+
highlighter_options[:css_class] = [ highlighter_options[:css_class], lexer.tag ].join(' ')
|
82
|
+
lexer_options = highlighter_options.delete(:lexer_options)
|
83
|
+
|
84
|
+
formatter = Rouge::Formatters::HTML.new(highlighter_options)
|
85
|
+
formatter.format(lexer.lex(code, options.lexer_options))
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# If Haml is around, define a :code filter that can be used to more conveniently output highlighted code.
|
92
|
+
if defined? Haml
|
93
|
+
module Haml
|
94
|
+
module Filters
|
95
|
+
module Code
|
96
|
+
include Base
|
97
|
+
|
98
|
+
def render(code)
|
99
|
+
code = code.encode(Encoding::UTF_8)
|
100
|
+
|
101
|
+
# Allow language to be specified via a special comment like:
|
102
|
+
# # lang: ruby
|
103
|
+
if code.lines.first =~ /\A\s*#\s*lang:\s*(\w+)$/
|
104
|
+
language = $1
|
105
|
+
code = code.lines.to_a[1..-1].join # Strip first line
|
106
|
+
end
|
107
|
+
|
108
|
+
Middleman::Syntax::Highlighter.highlight(code, language)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
86
112
|
end
|
87
113
|
end
|
data/middleman-syntax.gemspec
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "middleman-syntax/version"
|
3
4
|
|
4
5
|
Gem::Specification.new do |s|
|
5
|
-
s.name
|
6
|
-
s.version
|
7
|
-
s.platform
|
8
|
-
s.authors
|
9
|
-
s.email
|
10
|
-
s.homepage
|
11
|
-
s.summary
|
12
|
-
s.description = %q{
|
13
|
-
|
14
|
-
s.files
|
15
|
-
s.test_files
|
6
|
+
s.name = "middleman-syntax"
|
7
|
+
s.version = Middleman::Syntax::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Ben Hollis"]
|
10
|
+
s.email = ["ben@benhollis.net"]
|
11
|
+
s.homepage = "https://github.com/middleman/middleman-syntax"
|
12
|
+
s.summary = %q{Code syntax highlighting plugin via rouge for Middleman}
|
13
|
+
s.description = %q{Code syntax highlighting plugin via rouge for Middleman}
|
14
|
+
s.license = "MIT"
|
15
|
+
s.files = `git ls-files -z`.split("\0")
|
16
|
+
s.test_files = `git ls-files -z -- {fixtures,features}/*`.split("\0")
|
16
17
|
s.require_paths = ["lib"]
|
17
|
-
|
18
|
-
s.add_runtime_dependency("
|
19
|
-
s.add_runtime_dependency("rouge", "~> 0.3.0")
|
18
|
+
s.add_runtime_dependency("middleman-core", ["~> 3.2"])
|
19
|
+
s.add_runtime_dependency("rouge", ["~> 1.0"])
|
20
20
|
end
|
metadata
CHANGED
@@ -1,70 +1,76 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-syntax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.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:
|
11
|
+
date: 2014-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: middleman-core
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '3.
|
19
|
+
version: '3.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '3.
|
26
|
+
version: '3.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rouge
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '1.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:
|
41
|
-
description:
|
40
|
+
version: '1.0'
|
41
|
+
description: Code syntax highlighting plugin via rouge for Middleman
|
42
42
|
email:
|
43
43
|
- ben@benhollis.net
|
44
44
|
executables: []
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
- .gitignore
|
49
|
-
- .travis.yml
|
48
|
+
- ".gitignore"
|
49
|
+
- ".travis.yml"
|
50
50
|
- CHANGELOG.md
|
51
|
+
- CONTRIBUTING.md
|
51
52
|
- Gemfile
|
53
|
+
- LICENSE.md
|
52
54
|
- README.md
|
53
55
|
- Rakefile
|
56
|
+
- features/haml_filter.feature
|
54
57
|
- features/helper.feature
|
55
58
|
- features/markdown.feature
|
56
59
|
- features/support/env.rb
|
57
60
|
- fixtures/test-app/config.rb
|
58
61
|
- fixtures/test-app/source/code.html.markdown
|
62
|
+
- fixtures/test-app/source/code_haml.html.haml
|
63
|
+
- fixtures/test-app/source/code_haml_filter.html.haml
|
59
64
|
- fixtures/test-app/source/code_html.html.erb
|
65
|
+
- fixtures/test-app/source/code_slim.html.slim
|
60
66
|
- lib/middleman-syntax.rb
|
61
67
|
- lib/middleman-syntax/extension.rb
|
62
|
-
- lib/middleman-syntax/helper.rb
|
63
68
|
- lib/middleman-syntax/middleman_extension.rb
|
64
69
|
- lib/middleman-syntax/version.rb
|
65
70
|
- middleman-syntax.gemspec
|
66
71
|
homepage: https://github.com/middleman/middleman-syntax
|
67
|
-
licenses:
|
72
|
+
licenses:
|
73
|
+
- MIT
|
68
74
|
metadata: {}
|
69
75
|
post_install_message:
|
70
76
|
rdoc_options: []
|
@@ -72,25 +78,29 @@ require_paths:
|
|
72
78
|
- lib
|
73
79
|
required_ruby_version: !ruby/object:Gem::Requirement
|
74
80
|
requirements:
|
75
|
-
- -
|
81
|
+
- - ">="
|
76
82
|
- !ruby/object:Gem::Version
|
77
83
|
version: '0'
|
78
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
85
|
requirements:
|
80
|
-
- -
|
86
|
+
- - ">="
|
81
87
|
- !ruby/object:Gem::Version
|
82
88
|
version: '0'
|
83
89
|
requirements: []
|
84
90
|
rubyforge_project:
|
85
|
-
rubygems_version: 2.0.
|
91
|
+
rubygems_version: 2.2.0.rc.1
|
86
92
|
signing_key:
|
87
93
|
specification_version: 4
|
88
|
-
summary:
|
94
|
+
summary: Code syntax highlighting plugin via rouge for Middleman
|
89
95
|
test_files:
|
96
|
+
- features/haml_filter.feature
|
90
97
|
- features/helper.feature
|
91
98
|
- features/markdown.feature
|
92
99
|
- features/support/env.rb
|
93
100
|
- fixtures/test-app/config.rb
|
94
101
|
- fixtures/test-app/source/code.html.markdown
|
102
|
+
- fixtures/test-app/source/code_haml.html.haml
|
103
|
+
- fixtures/test-app/source/code_haml_filter.html.haml
|
95
104
|
- fixtures/test-app/source/code_html.html.erb
|
105
|
+
- fixtures/test-app/source/code_slim.html.slim
|
96
106
|
has_rdoc:
|
File without changes
|