<p>It's possible to write <a href="http://en.wikipedia.org/wiki/Markdown" rel="noreferrer">Markdown</a> content with invalid syntax. Invalid means that the <a href="http://www.deveiate.org/projects/BlueCloth" rel="noreferrer">BlueCloth</a> library fails to parse the content and throws an exception. The <code>markdown</code> helper in Rails doesn't catch any BlueCloth exceptions and because of that the complete page fails to render (500 Server Error page is rendered instead).</p>

<p>In my case, users are allowed to write Markdown content and save it to the database. If someone used invalid syntax, all successive rendering attempts of that content fail (Status Code 500 - Internal Server Error).</p>

<p>How do you get around this issue? Is it possible to validate the Markdown syntax at the Model-level before saving to the database?</p>

You should write your own validation method in which you would initialize BlueCloth object, and try to call
```
to_html
```
method catching any exception. If you catch an exception, validation fails, otherwise it should be ok.
In your model:
```
```
protected:

def validate
  bc = BlueCloth.new(your_markdown_string_attribute)
  begin
    bc.to_html
  rescue
    errors.add(:your_markdown_string_attribute, 'has invalid markdown syntax')
  end
end
```
```