Skip to content

Instantly share code, notes, and snippets.

@mojombo
Created April 16, 2009 23:21
Show Gist options
  • Save mojombo/96747 to your computer and use it in GitHub Desktop.
Save mojombo/96747 to your computer and use it in GitHub Desktop.
# 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