middleman-syntax 2.1.0 → 3.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c40d443bb7ade438430edef6ea27fef606d2056b
4
- data.tar.gz: 9c07e674417d80c403b3e6cfbf0ce0a15211f25a
3
+ metadata.gz: f4eb136031946fc9e1302df15f1158482e797ec3
4
+ data.tar.gz: 2b2e3b0abf60b2390a39dfa9c133b0fc780c0861
5
5
  SHA512:
6
- metadata.gz: 27794aa28183988c42ea1074e305caaaa57cf756f50828682713d115fb0c9b93873107502a7adef19feb003e75fba2ab2aff6178e5d8c0f246c3d80c316e829f
7
- data.tar.gz: b0e820698e90a582dcd0a0c12a8afd09e6150e267895cc9e6bb60a47d6d69611710092e3ecef07e133ed04a750f26084aca6e19b08557807f7eadb46079a41a6
6
+ metadata.gz: dd0bb555b69b28ec3e6dcf97e47c4ce932fde862513c06aa24f34d180b30f4e9271695179de0c0ca8fdc83477ece51a373a46dc008af080f79208f43bf5c0fba
7
+ data.tar.gz: 7a6f2f02432c48e1c0a89dbe0e45c26c4ce5bd848da62404ebada8b33b85489ba5b657793b76e9601fcaf73936ab879ce8f1532b96134be6efb24dda6daedcb3
@@ -1,3 +1,10 @@
1
+ 3.0.0
2
+ -----
3
+
4
+ * Upgrade to Rouge 2.0. #66.
5
+ * Added the ability to disable the line numbers on a specific code block when using Markdown and Redcarpet. #63.
6
+ * Lexer options are properly passed down to the highlighter.
7
+
1
8
  2.1.0
2
9
  -----
3
10
 
data/README.md CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  `middleman-syntax` is an extension for the [Middleman] static site generator that adds syntax highlighting via [Rouge](https://github.com/jayferd/rouge).
4
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]
5
+ [![Gem Version](https://badge.fury.io/rb/middleman-syntax.svg)][gem]
6
+ [![Build Status](https://travis-ci.org/middleman/middleman-syntax.svg)][travis]
7
+ [![Dependency Status](https://gemnasium.com/middleman/middleman-syntax.svg?travis)][gemnasium]
8
+ [![Code Quality](https://codeclimate.com/github/middleman/middleman-syntax.svg)][codeclimate]
9
9
 
10
10
  ## Installation
11
11
 
@@ -121,6 +121,18 @@ end
121
121
  ```
122
122
  </pre>
123
123
 
124
+ You can also disable the line numbers on a specific code block. However, this is Middleman-syntax specific feature, which only works when using Redcarpert.
125
+
126
+ Disabling the line numbers on a code block:
127
+
128
+ <pre>
129
+ ```ruby?line_numbers=false
130
+ def my_cool_method(message)
131
+ puts message
132
+ end
133
+ ```
134
+ </pre>
135
+
124
136
  or with Kramdown:
125
137
 
126
138
  <pre>
@@ -0,0 +1,13 @@
1
+ Feature: Code blocks with line numbers in markdown
2
+ @nojava
3
+ Scenario: Disabled line numbers with Redcarpet
4
+ Given a fixture app "test-app"
5
+ And a file named "config.rb" with:
6
+ """
7
+ set :markdown_engine, :redcarpet
8
+ set :markdown, :fenced_code_blocks => true
9
+ activate :syntax, :line_numbers => true
10
+ """
11
+ Given the Server is running at "test-app"
12
+ When I go to "/code_with_disabled_line_numbers.html"
13
+ Then I should not see line numbers markup
@@ -0,0 +1,13 @@
1
+ Feature: Code blocks with line numbers in markdown
2
+ @nojava
3
+ Scenario: Line numbers enabled with Redcarpet
4
+ Given a fixture app "test-app"
5
+ And a file named "config.rb" with:
6
+ """
7
+ set :markdown_engine, :redcarpet
8
+ set :markdown, :fenced_code_blocks => true
9
+ activate :syntax, :line_numbers => true
10
+ """
11
+ Given the Server is running at "test-app"
12
+ When I go to "/code_with_enabled_line_numbers.html"
13
+ Then I should see '<pre class="lineno">'
@@ -0,0 +1,4 @@
1
+ # step definition for testing line number markup
2
+ Then(/^I should not see line numbers markup$/) do
3
+ expect(page).not_to have_selector("pre.lineno")
4
+ end
@@ -0,0 +1,7 @@
1
+ # Ruby with no line numbers
2
+
3
+ ~~~ruby?line_numbers=false
4
+ def foo(bar)
5
+ puts "baz"
6
+ end
7
+ ~~~
@@ -0,0 +1,25 @@
1
+ # Ruby with line numbers
2
+
3
+ ~~~ruby?line_numbers=
4
+ def foo(bar)
5
+ puts "baz"
6
+ end
7
+ ~~~
8
+
9
+ ~~~ruby?line_numbers
10
+ def foo(bar)
11
+ puts "baz"
12
+ end
13
+ ~~~
14
+
15
+ ~~~ruby?line_numbers=flase
16
+ def foo(bar)
17
+ puts "baz"
18
+ end
19
+ ~~~
20
+
21
+ # Whatever
22
+
23
+ ~~~
24
+ This is some code
25
+ ~~~
@@ -2,6 +2,7 @@ require 'rouge'
2
2
  require 'middleman-syntax/highlighter'
3
3
  require 'middleman-syntax/redcarpet_code_renderer'
4
4
  require 'middleman-syntax/haml_monkey_patch'
5
+ require 'middleman-syntax/language_parameter_parser.rb'
5
6
 
6
7
  module Middleman
7
8
  module Syntax
@@ -15,7 +16,6 @@ module Middleman
15
16
 
16
17
  def after_configuration
17
18
  Middleman::Syntax::Highlighter.options = options
18
-
19
19
  if app.config[:markdown_engine] == :redcarpet
20
20
  require 'middleman-core/renderers/redcarpet'
21
21
  Middleman::Renderers::MiddlemanRedcarpetHTML.send :include, RedcarpetCodeRenderer
@@ -0,0 +1,27 @@
1
+ module Middleman
2
+ module Syntax
3
+ module Formatters
4
+ class HTML < Rouge::Formatter
5
+ tag 'html'
6
+
7
+ def initialize(opts={})
8
+ @formatter = if opts[:inline_theme]
9
+ Rouge::Formatters::HTMLInline.new(opts[:inline_theme])
10
+ else
11
+ Rouge::Formatters::HTML.new
12
+ end
13
+
14
+ @formatter = Rouge::Formatters::HTMLTable.new(@formatter, opts) if opts[:line_numbers]
15
+
16
+ if opts.fetch(:wrap, true)
17
+ @formatter = Rouge::Formatters::HTMLPygments.new(@formatter, opts.fetch(:css_class, 'codehilite'))
18
+ end
19
+ end
20
+
21
+ def stream(tokens, &block)
22
+ @formatter.stream(tokens, &block)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,5 @@
1
+ require 'middleman-syntax/formatters'
2
+
1
3
  module Middleman
2
4
  module Syntax
3
5
  module Highlighter
@@ -11,8 +13,8 @@ module Middleman
11
13
  highlighter_options[:css_class] = [ highlighter_options[:css_class], lexer.tag ].join(' ')
12
14
  lexer_options = highlighter_options.delete(:lexer_options)
13
15
 
14
- formatter = Rouge::Formatters::HTML.new(highlighter_options)
15
- formatter.format(lexer.lex(code, options.lexer_options))
16
+ formatter = Middleman::Syntax::Formatters::HTML.new(highlighter_options)
17
+ formatter.format(lexer.lex(code, lexer_options))
16
18
  end
17
19
  end
18
20
  end
@@ -0,0 +1,17 @@
1
+ module Middleman
2
+ module Syntax
3
+ module LanguageParameterParser
4
+ def self.parse_parameter_from_language(language = "")
5
+ language, params = language.to_s.split("?", 2)
6
+ if params and params.to_s.include? "="
7
+ attribute, value = params.to_s.split("=")
8
+ # if there are more arguments, refactor this
9
+ if attribute == "line_numbers" and value == "false"
10
+ return { line_numbers: false }
11
+ end
12
+ end
13
+ {}
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,10 +1,13 @@
1
+ require 'middleman-syntax/language_parameter_parser.rb'
2
+
1
3
  module Middleman
2
4
  module Syntax
3
5
  # A mixin for the Redcarpet Markdown renderer that will highlight
4
6
  # code.
5
7
  module RedcarpetCodeRenderer
6
8
  def block_code(code, language)
7
- Middleman::Syntax::Highlighter.highlight(code, language)
9
+ opts = Middleman::Syntax::LanguageParameterParser.parse_parameter_from_language(language)
10
+ Middleman::Syntax::Highlighter.highlight(code, language, opts)
8
11
  end
9
12
  end
10
13
  end
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module Syntax
3
- VERSION = "2.1.0"
3
+ VERSION = "3.0.0"
4
4
  end
5
5
  end
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.test_files = `git ls-files -z -- {fixtures,features}/*`.split("\0")
17
17
  s.require_paths = ["lib"]
18
18
  s.add_runtime_dependency("middleman-core", [">= 3.2"])
19
- s.add_runtime_dependency("rouge", ["~> 1.0"])
19
+ s.add_runtime_dependency("rouge", ["~> 2.0"])
20
20
  s.add_development_dependency("aruba", "~> 0.5.1")
21
21
  s.add_development_dependency("cucumber", "~> 1.3.1")
22
22
  s.add_development_dependency("fivemat")
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: 2.1.0
4
+ version: 3.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: 2015-12-19 00:00:00.000000000 Z
11
+ date: 2016-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman-core
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.0'
33
+ version: '2.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: '1.0'
40
+ version: '2.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: aruba
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -140,17 +140,24 @@ files:
140
140
  - features/haml_filter.feature
141
141
  - features/helper.feature
142
142
  - features/markdown.feature
143
+ - features/markdown_line_numbers_disabled.feature
144
+ - features/markdown_line_numbers_enabled.feature
143
145
  - features/support/env.rb
146
+ - features/support/step_definitions.rb
144
147
  - fixtures/test-app/config.rb
145
148
  - fixtures/test-app/source/code.html.markdown
146
149
  - fixtures/test-app/source/code_haml.html.haml
147
150
  - fixtures/test-app/source/code_haml_filter.html.haml
148
151
  - fixtures/test-app/source/code_html.html.erb
149
152
  - fixtures/test-app/source/code_slim.html.slim
153
+ - fixtures/test-app/source/code_with_disabled_line_numbers.html.markdown
154
+ - fixtures/test-app/source/code_with_enabled_line_numbers.html.markdown
150
155
  - lib/middleman-syntax.rb
151
156
  - lib/middleman-syntax/extension.rb
157
+ - lib/middleman-syntax/formatters.rb
152
158
  - lib/middleman-syntax/haml_monkey_patch.rb
153
159
  - lib/middleman-syntax/highlighter.rb
160
+ - lib/middleman-syntax/language_parameter_parser.rb
154
161
  - lib/middleman-syntax/middleman_extension.rb
155
162
  - lib/middleman-syntax/redcarpet_code_renderer.rb
156
163
  - lib/middleman-syntax/version.rb
@@ -183,11 +190,16 @@ test_files:
183
190
  - features/haml_filter.feature
184
191
  - features/helper.feature
185
192
  - features/markdown.feature
193
+ - features/markdown_line_numbers_disabled.feature
194
+ - features/markdown_line_numbers_enabled.feature
186
195
  - features/support/env.rb
196
+ - features/support/step_definitions.rb
187
197
  - fixtures/test-app/config.rb
188
198
  - fixtures/test-app/source/code.html.markdown
189
199
  - fixtures/test-app/source/code_haml.html.haml
190
200
  - fixtures/test-app/source/code_haml_filter.html.haml
191
201
  - fixtures/test-app/source/code_html.html.erb
192
202
  - fixtures/test-app/source/code_slim.html.slim
203
+ - fixtures/test-app/source/code_with_disabled_line_numbers.html.markdown
204
+ - fixtures/test-app/source/code_with_enabled_line_numbers.html.markdown
193
205
  has_rdoc: