Created
April 8, 2013 03:20
-
-
Save zerowidth/5334029 to your computer and use it in GitHub Desktop.
Jekyll monkeypatch to strip leading space from indented `highlight` liquid blocks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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