Find your content:

Search form

You are here

Markdown in Apex?

 
Share

Has anyone built a Markdown parser in Apex? Looking to do something like this:

String raw = 'This is a *Markdown* string.  Large, multiline, has links & headings';
Markdown mdParser = new Markdown();
String parsed = mdParser.parse(raw);
System.debug(parsed);

// ==> 'This is a <em>Markdown</em> string.  Large, multiline, has links & headings'

Attribution to: Benj

Possible Suggestion/Solution #1

I would recommend using an API to parse your markdown and return back html. One service I found that looks like it would work is from Github: https://developer.github.com/v3/markdown/.


Attribution to: Daniel Hoechst

Possible Suggestion/Solution #2

No, there's not currently any markdown support in apex, although it's conceivably possible to write one with enough effort.

As Daniel Hoechst suggested making a callout to an external markdown rendering service is very likely the easiest and fastest way of handling this.

On top of that it's very likely that any custom markdown rendering engine would have some compatibility bugs or security holes (depending on markdown flavor you can include raw HTML) unless you build an utterly amazing test suite.


Attribution to: ca_peterson
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/30593

My Block Status

My Block Content