Skip to content

Commit

Permalink
markdown: Change code highlighting method
Browse files Browse the repository at this point in the history
From now on, the front will be responsible for code highlighting.
  • Loading branch information
doortts committed Apr 16, 2017
1 parent 02ca7ec commit dbf9700
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
16 changes: 8 additions & 8 deletions app/utils/Markdown.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ private static ScriptEngine buildEngine() {
reader = new InputStreamReader(is, Config.getCharset());
_engine.eval(reader);

is = Thread.currentThread().getContextClassLoader().getResourceAsStream(HIGHLIGHT_JS_FILE);
reader = new InputStreamReader(is, Config.getCharset());
_engine.eval(reader);
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
Expand Down Expand Up @@ -135,11 +132,14 @@ private static String renderWithHighlight(String source, boolean breaks) {
return ZipUtil.decompress(cached);
}
try {
Object options = engine.eval("new Object({gfm: true, tables: true, breaks: " + breaks + ", " +
"pedantic: false, sanitize: false, smartLists: true," +
"highlight : function(sCode, sLang) { " +
"if(sLang) { try { return hljs.highlight(sLang.toLowerCase(), sCode).value;" +
" } catch(oException) { return sCode; } } }});");
Object options = engine.eval("new Object({ "
+ " gfm: true, "
+ " tables: true, "
+ " breaks: true, "
+ " pedantic: false, "
+ " sanitize: false, "
+ " smartLists: true "
+ "}) ");
String rendered = renderByMarked(source, options);
rendered = removeJavascriptInHref(rendered);
rendered = checkReferrer(rendered);
Expand Down
2 changes: 2 additions & 0 deletions app/views/common/markdown.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<script type="text/javascript" src="@routes.Assets.at("javascripts/lib/marked.js")"></script>
<script type="text/javascript">
$(document).ready(function(){
hljs.configure({languages: []});
hljs.initHighlightingOnLoad();
var htOptions = {};

@if(project != null){
Expand Down
3 changes: 3 additions & 0 deletions public/javascripts/common/yobi.Markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ yobi.Markdown = (function(htOptions){
"data": JSON.stringify(source),
"success": function(data){
welTarget.html(data);
$('pre code').each(function(i, block) {
hljs.highlightBlock(block);
});
}
});
}
Expand Down
6 changes: 3 additions & 3 deletions public/javascripts/yona-lib.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dbf9700

Please sign in to comment.