Created
July 29, 2015 08:55
Revisions
-
eungjun-yi created this gist
Jul 29, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ // Try to render and wait at most 5 seconds. final String[] rendered = new String[1]; @SuppressWarnings("deprecation") Thread marked = new Thread() { @Override public void run() { try { rendered[0] = (String) ((Invocable) engine).invokeFunction( "marked", source, options); } catch (Exception e) { play.Logger.error("[Markdown] Failed to render: " + source, e); } } }; marked.start(); marked.join(5000); if (rendered[0] == null) { // This is the only way to stop the script engine. Thread.interrupt does not work. marked.stop(); return "〈pre〉" + StringEscapeUtils.escapeHtml(source) + "〈/pre〉"; } else { return rendered[0]; }