code_junkie

How to validate Markdown?

Nov 11th, 2011
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. protected:
  2.  
  3. def validate
  4. bc = BlueCloth.new(your_markdown_string_attribute)
  5. begin
  6. bc.to_html
  7. rescue
  8. errors.add(:your_markdown_string_attribute, 'has invalid markdown syntax')
  9. end
  10. end
  11.  
  12. begin
  13. require "rdiscount"
  14. BlueCloth = RDiscount
  15. rescue LoadError
  16. # BlueCloth is still the our fallback,
  17. # if RDiscount is not available
  18. require 'bluecloth'
  19. end
Add Comment
Please, Sign In to add comment