CF Markdown provides a convenient wrapper for the Flexmark Java library. It provides simple HTML conversion or more complex document manipulation using Jsoup (optional).
Ensure Flexmark the flexmark jar is loadable by your app. This can either be by putting it into your server's Java classpath or in a path defined in application.javaSettings.loadPaths
. The latter is recommended.
Download this repository to a component path and test your install by trying to create a new flexmark component.
flexmark = new markdown.flexmark();
You should now be able to use the toHtml()
method to convert markdown to HTML.
To use the more advance functions such as TOC creation, you can install Jsoup in the same way as the Flexmark library and ensure it loads.
jSoupClass = createObject( "java", "org.jsoup.Jsoup" );
If you install JSoup you will also need ColdSoup. Install to a component path.
Test your install by trying to create a new coldsoup component.
coldsoup = new coldsoup.coldsoup();
Initiate as a singleton pattern component in a persistent scope and then call the toHTML method.
application.flexmark = new markdown.flexmark();
data = {};
html = application.flexmark.toHTML(markdown,data);
data
will contain any YAML data you have added.
Each of the major extensions can be loaded by supplying arguments to the init function. Most are loaded by default and you'll need to turn them off if you don't want them.
Extension | Default |
---|---|
abbreviation | true |
admonition | true |
anchorlink | true |
anchorlinks_wrap_text | true |
attributes | false |
autolink | true |
definition | true |
emoji | true |
escapedcharacter | true |
footnote | true |
strikethrough | true |
softbreaks | false |
macros | true |
typographic | false |
tasklist | true |
yaml | true |
An additional option unwrapAnchors
copes with a bug with the anchorlink extension. Leave this on.
Yaml meta data is on by default. It is returned in the data
struct passed as an argument.
For more advanced meta data, you can use the markdown()
method which examines the IDs of elements and constructs a TOC and other meta data.