Skip to content

Instantly share code, notes, and snippets.

@zerowidth
Created April 8, 2013 03:20
Show Gist options
  • Save zerowidth/5334029 to your computer and use it in GitHub Desktop.
Save zerowidth/5334029 to your computer and use it in GitHub Desktop.
Jekyll monkeypatch to strip leading space from indented `highlight` liquid blocks
Jekyll::Tags::HighlightBlock.module_eval do
def render(context)
code = strip_leading_space_from super
if context.registers[:site].pygments
render_pygments(context, code)
else
render_codehighlighter(context, code)
end
end
def strip_leading_space_from(code)
leading = code.split("\n").map { |l| /^(\s*)/.match(l)[1].size }
leading.shift # first line is blank, always (liquid?)
if leading.min > 0
code = code.split("\n").map do |line|
line.sub!(/^\s{#{leading.min}}/, "")
end.join("\n")
end
code
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment