middleman / middleman-syntax

Code syntax highlighting plugin via Rouge for Middleman
https://middlemanapp.com
MIT License
179 stars 57 forks source link

How to disable line numbers on specific code block? #62

Closed tuomasj closed 8 years ago

tuomasj commented 8 years ago

Hi,

Is there a way to disable line numbers on specific code block? Generally, I want to have line numbers on my code blocks but there are occasions where I would like to disable line numbers on specific code block.

I'm using markdown with fenced code blocks.

# config.rb
set :markdown, :fenced_code_blocks => true, :smartypants => true

This is a markdown code block with ruby with line numbers, just for an example:

```ruby
# hello.rb
def hello
  puts "hello"
end

The end result is a code block with line numbers:

``` ruby
1  # hello.rb
2  def hello
3    puts "hello"
4  end

This is a markdown code block where I would like to disable line numbers:

This is just an imaginary example, there is no nolinenumbers syntax.

```nolinenumbers
middleman init MY_PROJECT
bundle exec middleman serve

The end result would be a code block without line numbers:

middleman init MY_PROJECT bundle exec middleman serve



Is there an option or parameter that would handle this?
bhollis commented 8 years ago

Not in markdown, no. If you use the code helper in another template language, you can pass parameters.

tuomasj commented 8 years ago

Here is an experiment that I tried: https://github.com/tuomasj/middleman-syntax/blob/no_linenumbers_experiment/lib/middleman-syntax/highlighter.rb#L8

This is not the way this "problem" should be fixed for production, but since I'm the only one using, this will do for me :smile:

So, now I have a syntax called "plain":

```plain
puts "Look ma, no line numbers!"
bhollis commented 8 years ago

Actually...

Try this:

```ruby?line_numbers=false
puts "Look ma, no line numbers!"
folz commented 8 years ago

Hey - I tried ?line_numbers=false but line numbers were still present. Anything else you advise?

relevant config.rb:

set :markdown_engine, :redcarpet
set :markdown, :fenced_code_blocks => true, :smartypants => true
activate :syntax, :line_numbers => true

versions: middleman: (3.3.12) middleman-blog: (3.5.3) middleman-syntax: (2.1.0) redcarpet (3.3.4)

bhollis commented 8 years ago

Yeah, looks like we'd need to make some changes for that to work.

tuomasj commented 8 years ago
```ruby?line_numbers=false
puts "Look ma, no line numbers parameter is working now!"


Here is the commit for working version with Redcarpet: https://github.com/tuomasj/middleman-syntax/commit/3d19e5b544648eddf86ae27324fa7fc1a2edba4a

When using redcarpet this language parameter approach works, but Kramdown handles the language parameter differently. Any suggestions what would be the best approach?
bhollis commented 8 years ago

Neat! Wanna send a PR? I'm not sure Kramdown will make this available.

tuomasj commented 8 years ago

Yeah, I'll send it as soon as I remove all Kramdown releated stuff

tuomasj commented 8 years ago

Created a pull request #63, closing this issue. If there are any addition discussions, the pull request is better place for it.