Created
April 16, 2009 23:21
-
-
Save mojombo/96747 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
# GitHub Flavored Markdown Layer | |
def fix_markdown_quirks(text) | |
# prevent foo_bar_baz from ending up with an italic word in the middle | |
text.gsub!(/(^(?! {4}|\t)\w+_\w+_\w[\w_]*)/) do |x| | |
x.gsub('_', '\_') if x.split('').sort.to_s[0..1] == '__' | |
end | |
# in very clear cases, let newlines become <br /> tags | |
text.gsub!(/(\A|^$\n)(^\w[^\n]*\n)(^\w[^\n]*$)+/m) do |x| | |
x.gsub(/^(.+)$/, "\\1 ") | |
end | |
text | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment