Last active
August 29, 2015 14:23
-
-
Save 0cch/775e4a8a94be175cae9c to your computer and use it in GitHub Desktop.
This file contains 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
def string_rsub(str, pattern, replacement) | |
last_match = nil | |
while true | |
pos = last_match.nil? ? 0 : last_match.end(0) | |
m = pattern.match(str, pos) | |
break if m.nil? | |
ast_match = m | |
end | |
last_match ? (last_match.pre_match + replacement + last_match.post_match) : str | |
end | |
def add_code_tag(code) | |
# Add nested <code> tags to code blocks | |
code = code.sub(/<pre>\n*/,'<pre><code class="language-' + @lang.to_s.gsub("+", "-") + '" data-lang="' + @lang.to_s + '">') | |
code = string_rsub(code, /\n*<\/pre>/,"</code></pre>") | |
code.strip | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment