middleman / middleman-syntax

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

Generates bad highlighting #13

Closed Linuus closed 11 years ago

Linuus commented 11 years ago

Hi

I just tested this gem and it works quite bad for me.

Gemfile:
gem "middleman-syntax"
gem "redcarpet"

config.rb:
###
# Markdown
###

set :markdown_engine, :redcarpet
set :markdown, :fenced_code_blocks => true, :smartypants => true

###
# Code highlighting
###

activate :syntax

Then I use it in a .md file like this:

  ```ruby
    def index
      @cars = Car.all

      respond_to do |format|
        format.html # index.html.erb
        format.json { render json: @cars }
      end
    end

    # GET /cars/1
    # GET /cars/1.json
    def show
      @car = Car.find(params[:id])

      respond_to do |format|
        format.html # show.html.erb
        format.json { render json: @car }
      end
    end
  // I have end backticks here but I can't add them because it messes up github

It seems to highlight the code pretty bad. The output can be seen here: https://gist.github.com/Linuus/5130247

It gets error on # and pretty much only n, p and o classes otherwise.

Did I do anything wrong?

bhollis commented 11 years ago

This gem is just running the code through pygments... maybe you should file a bug against pygments instead?

Linuus commented 11 years ago

Ok. I will when I get the time. I went with rouge instead. Works great.

michaelbaudino commented 11 years ago

Hello,

I'm experiencing quite the same behaviour. I have exactly the same Gemfile and config.rb than @Linuus, and with the following markdown code :

gem 'redcarpet'

When using Pygments online demo on Pygments website, I get the following HTML code :

<pre>
  <span class="n">gem</span>
  <span class="s1">'redcarpet'</span>
</pre>

But when using my middleman server and middleman-syntax, I get the following :

<pre>
  <span class="n">gem</span>
  <span class="err">'</span>
  <span class="n">redcarpet</span>
  <span class="err">'</span>
</pre>

What may go wrong ? I don't think it might be a Pygments bug, since it's working well on their online demo. Maybe we should pass some options to Pygments or something ?

@Linuus : Any tip to use Rouge in a Middleman project ?

Linuus commented 11 years ago

@michaelbaudino Yes, it's very easy to implement Rouge in middleman actually. I will release a gem for it in a day or so to make it even easier :)

michaelbaudino commented 11 years ago

@Linuus Nice :-) Let me know if you need a hand, I'd be glad to help...

Linuus commented 11 years ago

@michaelbaudino Here it is: https://github.com/Linuus/middleman-rouge Published on rubygems as well.

Let me know how it works for you.

bhollis commented 11 years ago

@michaelbaudino

What happens when you use this markdown instead:

```ruby
gem 'redcarpet'
michaelbaudino commented 11 years ago

@bhollis Sorry, my message was not clear (I failed at embedding markdown inside markdown...) ! But that's exactly what I've been using.

In the mean time, I've tried Rouge and @Linuus' https://github.com/Linuus/middleman-rouge and it's working great.

But let me know if you need me to do any test, I can roll back to middleman-syntax, I'd be glad to help.