Skip to content

Instantly share code, notes, and snippets.

@nhh
Last active February 8, 2018 07:18
Show Gist options
  • Save nhh/7d7bc14cfa7a8f134f5290f2c1f40ca5 to your computer and use it in GitHub Desktop.
Save nhh/7d7bc14cfa7a8f134f5290f2c1f40ca5 to your computer and use it in GitHub Desktop.
module Markdown
module Fixer
def self.fix(markdown, pattern=@fix_all_pattern)
pattern.map do |key, value|
markdown.gsub!(key.to_s, value.to_s)
end
markdown
end
@fix_all_pattern = {
'title': '"title"',
'hr': 'hhr',
'\r\n': '\n',
'tags': 't a g s'
}
end
end
# Usage:
# returns: "title" hhr t a g s\n
Markdown::Fixer.fix('title hr tags\r\n')
# Provide a custom pattern:
# returns: title hr tags\n
Markdown::Fixer.fix('title hr tags\r\n', {'\r\n': '\n'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment