Created
March 30, 2012 22:34
-
-
Save ashrewdmint/2256560 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
module Jekyll | |
# This is probably bad. Should I be doing this? | |
class MarkdownConverter < Converter | |
alias :old_convert :convert | |
def convert(content) | |
old_convert(content).gsub(/<h([1-6])>(.+?<\/)/) do |match| | |
n = $1 | |
text = $2 | |
"<h#{n} id=\"#{slugify(text)}\">#{text}" | |
end | |
end | |
def slugify(text) | |
text.strip.downcase. | |
gsub(/[^a-z0-9]+/, '-'). # Replace non-alphanumeric characters with - | |
gsub(/-$|^-/, '') # Remove trailing and leading -'s | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment