Skip to content

Instantly share code, notes, and snippets.

@henrik
Forked from mojombo/gfm.rb
Created April 16, 2009 23:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save henrik/96749 to your computer and use it in GitHub Desktop.
GitHub Flavored Markdown
# 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!(/(\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\n)(^\w[^\n]*\n)(^\w[^\n]*\n)+/m) do |x|
x.gsub(/^(.+)\n/, "\\1 \n")
end
text
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment