Skip to content
This repository has been archived by the owner on May 20, 2021. It is now read-only.

Commit

Permalink
Merge pull request #81 from ShyykoSerhiy/dev
Browse files Browse the repository at this point in the history
fixes #80
  • Loading branch information
ShyykoSerhiy committed Sep 15, 2015
2 parents 113979a + 783a51e commit f0d2529
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ public void run() {
final WebView webView = ((BrowserFx) browser).getWebView(); //FIXME refactor somehow
final WebEngine webEngine = webView.getEngine();
final String script = "document.getElementById('title').innerHTML = window.java.getTitle();" +
"document.querySelector('.markdown-body.entry-content').innerHTML = window.java.getMarkdown();";
"document.querySelector('.markdown-body.entry-content').innerHTML = window.java.getMarkdown();" +
"Array.prototype.slice.apply(document.querySelectorAll('pre code')).forEach(function(block){" +
" hljs.highlightBlock(block);" +
"});";
JSObject jsobj = (JSObject) webEngine.executeScript("window");
jsobj.setMember("java", new JSMarkdownBridge(markdown, title));
if (webEngine.getLoadWorker().getState() == Worker.State.SUCCEEDED) {
Expand Down
33 changes: 20 additions & 13 deletions src/main/java/com/github/shyykoserhiy/gfm/editor/GfmPreviewJX.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import java.io.File;

public class GfmPreviewJX extends ModernGfmPreview {
private String markdown;
private String title;


public GfmPreviewJX(@NotNull VirtualFile markdownFile, @NotNull Document document) {
super(markdownFile, document);
Expand All @@ -38,27 +41,31 @@ protected GfmRequestDoneListener getRequestDoneListener() {
private class RequestDoneListener implements GfmRequestDoneListener {
@Override
public void onRequestDone(final File result) {
browser.loadUrl("file:" + result.getAbsolutePath());
onceUpdated = true;
}

@Override
public void onRequestDone(final String title, final String markdown) {
Browser browser = ((BrowserJx) GfmPreviewJX.this.browser).getWebView().getBrowser();
browser.unregisterFunction("getMarkdown");
browser.unregisterFunction("getTitle");
browser.registerFunction("getMarkdown", new BrowserFunction() {
((BrowserJx) GfmPreviewJX.this.browser).getWebView().getBrowser().registerFunction("getMarkdownZ", new BrowserFunction() {
public JSValue invoke(JSValue... args) {
return JSValue.create(markdown);
}
});
browser.registerFunction("getTitle", new BrowserFunction() {
((BrowserJx) GfmPreviewJX.this.browser).getWebView().getBrowser().registerFunction("getTitleZ", new BrowserFunction() {
public JSValue invoke(JSValue... args) {
return JSValue.create(title);
}
});
browser.executeJavaScript("document.getElementById('title').innerHTML = getTitle();" +
"document.querySelector('.markdown-body.entry-content').innerHTML = getMarkdown();");
browser.loadUrl("file:" + result.getAbsolutePath());
onceUpdated = true;
}

@Override
public void onRequestDone(final String title, final String markdown) {
Browser browser = ((BrowserJx) GfmPreviewJX.this.browser).getWebView().getBrowser();
GfmPreviewJX.this.markdown = markdown;
GfmPreviewJX.this.title = title;

browser.executeJavaScript("document.getElementById('title').innerHTML = getTitleZ();" +
"document.querySelector('.markdown-body.entry-content').innerHTML = getMarkdownZ();" +
"Array.prototype.slice.apply(document.querySelectorAll('pre code')).forEach(function(block){" +
" hljs.highlightBlock(block);" +
"});");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ private TemplateManager() {
HashMap<String, Object> markdownParams = new HashMap<String, Object>();
URL githubCss;
URL githubCss2;
URL highlightGithubCss;
URL highlightPackJs;
try {
githubCss = new File(outputFile, FileUtil.join("css", "github-fff66249e57e12b5b264967f6a4d21f8923d59247f86c4419d1e3092660fe54b.css")).toURI().toURL();
githubCss2 = new File(outputFile, FileUtil.join("css", "github2-ade0148a562b52311cf36a8e5f019126eb5ef7054bf2a0463ea00c536a358d33.css")).toURI().toURL();
highlightGithubCss = new File(outputFile, FileUtil.join("css", "highlightjs8_8_0", "github.css")).toURI().toURL();
highlightPackJs = new File(outputFile, FileUtil.join("css", "highlightjs8_8_0", "highlight.pack.js")).toURI().toURL();

markdownParams.put("github.css", githubCss.toExternalForm());
markdownParams.put("github2.css", githubCss2.toExternalForm());
markdownParams.put("highlight.github.css", highlightGithubCss.toExternalForm());
markdownParams.put("highlight.pack.js", highlightPackJs.toExternalForm());
} catch (MalformedURLException e) {
e.printStackTrace(); //todo?
}
Expand Down
Binary file modified src/main/resources/com/github/shyykoserhiy/gfm/html/css.zip
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
github.com style (c) Vasily Polovnyov <[email protected]>
*/

.hljs {
display: block;
overflow-x: auto;
padding: 0.5em;
color: #333;
background: #f8f8f8;
-webkit-text-size-adjust: none;
}

.hljs-comment,
.diff .hljs-header {
color: #998;
font-style: italic;
}

.hljs-keyword,
.css .rule .hljs-keyword,
.hljs-winutils,
.nginx .hljs-title,
.hljs-subst,
.hljs-request,
.hljs-status {
color: #333;
font-weight: bold;
}

.hljs-number,
.hljs-hexcolor,
.ruby .hljs-constant {
color: #008080;
}

.hljs-string,
.hljs-tag .hljs-value,
.hljs-doctag,
.tex .hljs-formula {
color: #d14;
}

.hljs-title,
.hljs-id,
.scss .hljs-preprocessor {
color: #900;
font-weight: bold;
}

.hljs-list .hljs-keyword,
.hljs-subst {
font-weight: normal;
}

.hljs-class .hljs-title,
.hljs-type,
.vhdl .hljs-literal,
.tex .hljs-command {
color: #458;
font-weight: bold;
}

.hljs-tag,
.hljs-tag .hljs-title,
.hljs-rule .hljs-property,
.django .hljs-tag .hljs-keyword {
color: #000080;
font-weight: normal;
}

.hljs-attribute,
.hljs-variable,
.lisp .hljs-body,
.hljs-name {
color: #008080;
}

.hljs-regexp {
color: #009926;
}

.hljs-symbol,
.ruby .hljs-symbol .hljs-string,
.lisp .hljs-keyword,
.clojure .hljs-keyword,
.scheme .hljs-keyword,
.tex .hljs-special,
.hljs-prompt {
color: #990073;
}

.hljs-built_in {
color: #0086b3;
}

.hljs-preprocessor,
.hljs-pragma,
.hljs-pi,
.hljs-doctype,
.hljs-shebang,
.hljs-cdata {
color: #999;
font-weight: bold;
}

.hljs-deletion {
background: #fdd;
}

.hljs-addition {
background: #dfd;
}

.diff .hljs-change {
background: #0086b3;
}

.hljs-chunk {
color: #aaa;
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
}
{additionalCss}
</style>
<link rel="stylesheet"
href="{highlight.github.css}"/>
<script src="{highlight.pack.js}"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body>
<div class="page">
Expand Down

This file was deleted.

0 comments on commit f0d2529

Please sign in to comment.