middleman-syntax 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -6
- data/CHANGELOG.md +12 -0
- data/Gemfile +13 -13
- data/README.md +33 -9
- data/Rakefile +1 -4
- data/features/helper.feature +7 -0
- data/features/markdown.feature +22 -0
- data/features/support/env.rb +6 -0
- data/fixtures/test-app/config.rb +1 -0
- data/fixtures/test-app/source/code.html.markdown +13 -0
- data/fixtures/test-app/source/code_html.html.erb +14 -0
- data/lib/middleman-syntax/extension.rb +32 -8
- data/lib/middleman-syntax/version.rb +1 -1
- data/middleman-syntax.gemspec +1 -1
- metadata +19 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4d472a90adef6ca025bcac82d3f00f6546d0083
|
4
|
+
data.tar.gz: 72e518ba6b0ee79bcbd16c9382bad88d3cffad25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 854f1f201cf18fe0d765a3e20a6106466e2bd743475228aebcb32747a067daa0961442bfd1ffada7f0e64d6f3f9c38bf6785658c76a2992585074975db95fc82
|
7
|
+
data.tar.gz: 09db1d1c2d64c46ac851b5fd99595086a7f914ccdb192f54d95de7b8658501e7cafdb04c52a1ce6f9daa68df5cff70ff51f644a361cf24fa9d7cd9384bde080e
|
data/.travis.yml
CHANGED
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
|
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
|
-
|
13
|
-
|
14
|
-
gem "rdoc", "~> 3.9"
|
15
|
-
gem "yard", "~> 0.8.0"
|
16
|
-
end
|
10
|
+
gem 'padrino-helpers'
|
11
|
+
gem 'kramdown'
|
17
12
|
|
18
|
-
|
19
|
-
gem
|
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 [
|
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
|
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
|
-
|
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
|
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
|
-
|
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
|
-
|
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 @@
|
|
1
|
+
activate :syntax
|
@@ -7,19 +7,46 @@ module Middleman
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def registered(app, options_hash={})
|
10
|
-
require '
|
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
|
-
|
18
|
-
|
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
|
-
|
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
|
-
|
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
|
data/middleman-syntax.gemspec
CHANGED
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.
|
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-
|
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:
|
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: 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:
|
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.
|
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:
|