middleman / middleman-syntax

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

erb indentation problems #39

Closed olliekyan closed 10 years ago

olliekyan commented 10 years ago

I'm not sure why this is happening, and I can't find a workaround. I'm trying to put code examples into erb files but it's preserving my space indentation (2 spaces) within the code block. e.g. this...

 <div class="col span3">
  <% code("html") do %>
    <h1>This is a default heading 1 style</h1>
  <% end %>
 </div>

Is showing as

screen shot 2014-04-03 at 11 12 04

But if I remove all my indentation the examples work properly (although everything is left aligned so it doesn't make for very nice code examples), any ideas? Does it only work when using markdown files and not in erb templates?

bhollis commented 10 years ago

The code helper has no way to know from ERb how indented it is. Just indent the block inside your helper exactly as much as you want it indented in the output.

olliekyan commented 10 years ago

I'm doing that, what I really need the helper to do is strip the leading/trailing whitespace before and after the code within the helper as currently it keeps this if I want my document formatting to be consistent. e.g. this is my document structure (I'll use an example that has more lines)

screen shot 2014-04-08 at 10 00 19

And this is the output from the helper...

screen shot 2014-04-08 at 10 01 09

The only way I can get it to respect ignoring the leading/trailing whitespace is to align my code helper block all left like this...

screen shot 2014-04-08 at 10 02 39

and then I get the correct output...

screen shot 2014-04-08 at 10 07 04

I just wondered if there was an easy fix to strip this whitespace out? I can use the left formatted code blocks as it's not a deal breaker, it would just be nice to keep all my code formatted correctly. I tried passing the block within a another helper and gsub the whitespace but it was stripping the CSS classes.

Thanks for the great extension btw, so handy for pattern libraries :+1:

bhollis commented 10 years ago

Yeah, you need to left-align it like that. ERb is not indentation-aware. If you love indentation, use Haml - it'll work fine.

olliekyan commented 10 years ago

Ah okay cool, no problem. Thanks for replying.