This is a "fact finding" question to understand how difficult it would be to create ColdFusion UDF to analyze markup on the server using the showdown.js parser . There is already a java implementation that uses showdown.js (see the code at the end of this post), and I want to see how to do this for ColdFusion. I have no experience in Java, and I would not call myself a "programmer", but I do not want this to stop me from trying.
Summary
I want to run Shadown.js on the server side to convert markdown to HTML.
Why?
Saving two versions of the user record, one in markdown format and the other in HTML, allows us to display the original version of markdown to the end user in case they want to edit their record.
Why not use a server-side parser?
For two reasons:
- No ColdFusion parsers currently exist for this specific purpose.
- Using Showdown.js on the client side and then another server-side parser will result in inconsistent markup between previewing the client and the version stored in the database. Given that markdowns are poorly defined, most parser implementations will have subtle differences.
There is a very good blog post discussing issues.
Why not do all client-side parsing and publish both versions?
This does not make me a safe solution. I also think that users will potentially be able to submit markdowns with HTML that does not match.
Are there any existing implementations?
There is one implementation called CFShowdown , but this is not for this specific purpose. Rather, it is designed to handle the output on a page. The comments section of the aforementioned blog contains a pure Java implementation written by a user called David:
ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine jsEngine = manager.getEngineByName("js"); try { jsEngine.eval(new InputStreamReader(getClass().getResourceAsStream("showdown.js"))); showdownConverter = jsEngine.eval("new Showdown.converter()"); } catch (Exception e) { log.error("could not create showdown converter", e); } try { return ((Invocable) jsEngine).invokeMethod( showdownConverter, "makeHtml", markdownString ) + ""; } catch (Exception e) { log.error("error while converting markdown to html", e); return "[could not convert input]"; }
goal
Create a java class that allows us to use this implementation with ColdFusion UDF or a custom tag inside the component, something like strings <cfset html = getMarkdown(string)>
Since I have no experience with Java, I want to get some tips and information from users on where and how to get started with this task. I created