Skip to content

Commit

Permalink
Settings for preview theme. Filter out coderay colors in darcula theme
Browse files Browse the repository at this point in the history
  • Loading branch information
ahus1 committed Oct 29, 2016
1 parent 3483310 commit 8960259
Show file tree
Hide file tree
Showing 16 changed files with 266 additions and 138 deletions.
3 changes: 2 additions & 1 deletion META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin version="2" url="https://github.com/asciidoctor/asciidoctor-intellij-plugin">
<id>org.asciidoctor.intellij.asciidoc</id>
<name>AsciiDoc</name>
<version>0.16.2</version>
<version>0.16.3</version>
<vendor email="erik.pragt@jworks.nl" url="http://asciidoctor.org">Asciidoctor Project</vendor>

<description><![CDATA[
Expand All @@ -18,6 +18,7 @@

<change-notes><![CDATA[
<ul>
<li>0.16.3 Theme in preview can be switched from light to darcula independent of IDE theme</li>
<li>0.16.2 Handling of Linux and MacOS file names for image preview in JavaFX</li>
<li>0.16.1 Added darcula theme for JavaFX preview
<br />clicking on JavaFX preview will set cursor position in editor (thanks to @kastork for the idea)</li>
Expand Down
6 changes: 5 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ See https://intellij-support.jetbrains.com/hc/en-us/articles/206544879-Selecting

== Release notes

=== 0.16.2 (preview, available from Github releases)
=== 0.16.3 (preview, available from Github releases)

Theme in preview can be switched from light to darcula independent of IDE theme

=== 0.16.2

- Handling of Linux and MacOS file names for image preview in JavaFX

Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/asciidoc/intellij/editor/AsciiDocHtmlPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.intellij.openapi.Disposable;
import com.intellij.openapi.editor.Editor;
import org.asciidoc.intellij.AsciiDocBundle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -36,4 +37,22 @@ public Editor getEditor() {
public void setEditor(Editor editor) {
this.editor = editor;
}

public enum PreviewTheme {
INTELLIJ(AsciiDocBundle.message("asciidoc.preview.intellij")),
ASCIIDOC(AsciiDocBundle.message("asciidoc.preview.asciidoc")),
DARCULA(AsciiDocBundle.message("asciidoc.preview.darcula"));

public final String presentationName;

PreviewTheme(String presentationName) {
this.presentationName = presentationName;
}

@Override
public String toString() {
return presentationName;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private AsciiDocHtmlPanelProvider retrievePanelProvider(@NotNull AsciiDocApplica

if (provider.isAvailable() != AsciiDocHtmlPanelProvider.AvailabilityInfo.AVAILABLE) {
settings.setAsciiDocPreviewSettings(new AsciiDocPreviewSettings(settings.getAsciiDocPreviewSettings().getSplitEditorLayout(),
AsciiDocPreviewSettings.DEFAULT.getHtmlPanelProviderInfo()));
AsciiDocPreviewSettings.DEFAULT.getHtmlPanelProviderInfo(), settings.getAsciiDocPreviewSettings().getPreviewTheme()));

/* the following will not work, IntellIJ will show the error "parent must be showing" when this is
tiggered during startup. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public void run() {
if (isSuccess) {
asciiDocApplicationSettings.setAsciiDocPreviewSettings(new AsciiDocPreviewSettings(
oldPreviewSettings.getSplitEditorLayout(),
new JavaFxHtmlPanelProvider().getProviderInfo()
new JavaFxHtmlPanelProvider().getProviderInfo(),
oldPreviewSettings.getPreviewTheme()
));
EditorNotifications.updateAll();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.commons.io.IOUtils;
import org.asciidoc.intellij.editor.AsciiDocHtmlPanel;
import org.asciidoc.intellij.editor.AsciiDocPreviewEditor;
import org.asciidoc.intellij.settings.AsciiDocApplicationSettings;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -71,6 +72,8 @@ protected String compute() {
private WebView myWebView;
@Nullable
private String myInlineCss;
@Nullable
private String myInlineCssDarcula;
@NotNull
private final ScrollPreservingListener myScrollPreservingListener = new ScrollPreservingListener();
@NotNull
Expand All @@ -92,9 +95,9 @@ public JavaFxHtmlPanel(Document document) {

try {
myInlineCss = IOUtils.toString(JavaFxHtmlPanel.class.getResourceAsStream("default.css"));
if(UIUtil.isUnderDarcula()) {
myInlineCss += IOUtils.toString(JavaFxHtmlPanel.class.getResourceAsStream("darcula.css"));
}
myInlineCssDarcula = myInlineCss + IOUtils.toString(JavaFxHtmlPanel.class.getResourceAsStream("darcula.css"));
myInlineCssDarcula += IOUtils.toString(JavaFxHtmlPanel.class.getResourceAsStream("coderay-darcula.css"));
myInlineCss += IOUtils.toString(JavaFxHtmlPanel.class.getResourceAsStream("coderay.css"));
}
catch (IOException e) {
String message = "Error rendering asciidoctor: " + e.getMessage();
Expand Down Expand Up @@ -157,6 +160,20 @@ private void runInPlatformWhenAvailable(@NotNull final Runnable runnable) {
}


private boolean isDarcula() {
final AsciiDocApplicationSettings settings = AsciiDocApplicationSettings.getInstance();
switch (settings.getAsciiDocPreviewSettings().getPreviewTheme()) {
case INTELLIJ:
return UIUtil.isUnderDarcula();
case ASCIIDOC:
return false;
case DARCULA:
return true;
default:
return false;
}
}

private static void updateFontSmoothingType(@NotNull WebView view, boolean isGrayscale) {
final FontSmoothingType typeToSet;
if (isGrayscale) {
Expand All @@ -176,6 +193,11 @@ public JComponent getComponent() {

@Override
public void setHtml(@NotNull String html) {
if (isDarcula()) {
// clear out coderay inline CSS colors as they are barely readable in darcula theme
html = html.replaceAll("<span style=\"color:#[a-zA-Z0-9]*;?", "<span style=\"");
html = html.replaceAll("<span style=\"background-color:#[a-zA-Z0-9]*;?", "<span style=\"");
}
html = "<html><head></head><body>" + html + "</body>";
final String htmlToRender = prepareHtml(html);

Expand Down Expand Up @@ -205,7 +227,7 @@ private String prepareHtml(@NotNull String html) {

/* Add CSS line and JavaScript for auto-scolling and clickable links */
return html
.replace("<head>", "<head>" + getCssLines(myInlineCss))
.replace("<head>", "<head>" + getCssLines(isDarcula() ? myInlineCssDarcula : myInlineCss))
.replace("</body>", getScriptingLines() + "</body>");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* Stylesheet for CodeRay to match GitHub theme | MIT License | http://foundation.zurb.com */
/* there is currently darcula set of colors. use only font weights for now */
.CodeRay .line-numbers{border-right:1px solid #d8d8d8;padding:0 0.5em 0 .25em}
.CodeRay span.line-numbers{display:inline-block;margin-right:.5em;}
table.CodeRay{border-collapse:separate;border-spacing:0;margin-bottom:0;border:0}
table.CodeRay td{vertical-align: top;line-height:1.45}
table.CodeRay td.line-numbers{text-align:right}
table.CodeRay td.line-numbers>pre{padding:0;}
table.CodeRay td.code{padding:0 0 0 .5em}
table.CodeRay td.code>pre{padding:0}
.CodeRay .comment{font-style:italic}
.CodeRay .class{font-weight:bold}
.CodeRay .exception{color:inherit}
.CodeRay .function{font-weight:bold}
.CodeRay .important{font-weight:bold}
.CodeRay .directive{font-weight:bold}
.CodeRay .type{font-weight:bold}
.CodeRay .reserved,.CodeRay .keyword {font-weight:bold}
.CodeRay .regexp .function{font-weight:bold}
89 changes: 89 additions & 0 deletions src/main/java/org/asciidoc/intellij/editor/javafx/coderay.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/* Stylesheet for CodeRay to match GitHub theme | MIT License | http://foundation.zurb.com */
/*pre.CodeRay {background-color:#f7f7f8;}*/
.CodeRay .line-numbers{border-right:1px solid #d8d8d8;padding:0 0.5em 0 .25em}
.CodeRay span.line-numbers{display:inline-block;margin-right:.5em;color:rgba(0,0,0,.3)}
.CodeRay .line-numbers strong{color:rgba(0,0,0,.4)}
table.CodeRay{border-collapse:separate;border-spacing:0;margin-bottom:0;border:0;background:none}
table.CodeRay td{vertical-align: top;line-height:1.45}
table.CodeRay td.line-numbers{text-align:right}
table.CodeRay td.line-numbers>pre{padding:0;color:rgba(0,0,0,.3)}
table.CodeRay td.code{padding:0 0 0 .5em}
table.CodeRay td.code>pre{padding:0}
.CodeRay .debug{color:#fff !important;background:#000080 !important}
.CodeRay .annotation{color:#007}
.CodeRay .attribute-name{color:#000080}
.CodeRay .attribute-value{color:#700}
.CodeRay .binary{color:#509}
.CodeRay .comment{color:#998;font-style:italic}
.CodeRay .char{color:#04d}
.CodeRay .char .content{color:#04d}
.CodeRay .char .delimiter{color:#039}
.CodeRay .class{color:#458;font-weight:bold}
.CodeRay .complex{color:#a08}
.CodeRay .constant,.CodeRay .predefined-constant{color:#008080}
.CodeRay .color{color:#099}
.CodeRay .class-variable{color:#369}
.CodeRay .decorator{color:#b0b}
.CodeRay .definition{color:#099}
.CodeRay .delimiter{color:#000}
.CodeRay .doc{color:#970}
.CodeRay .doctype{color:#34b}
.CodeRay .doc-string{color:#d42}
.CodeRay .escape{color:#666}
.CodeRay .entity{color:#800}
.CodeRay .error{color:#808}
.CodeRay .exception{color:inherit}
.CodeRay .filename{color:#099}
.CodeRay .function{color:#900;font-weight:bold}
.CodeRay .global-variable{color:#008080}
.CodeRay .hex{color:#058}
.CodeRay .integer,.CodeRay .float{color:#099}
.CodeRay .include{color:#555}
.CodeRay .inline{color:#000}
.CodeRay .inline .inline{background:#ccc}
.CodeRay .inline .inline .inline{background:#bbb}
.CodeRay .inline .inline-delimiter{color:#d14}
.CodeRay .inline-delimiter{color:#d14}
.CodeRay .important{color:#555;font-weight:bold}
.CodeRay .interpreted{color:#b2b}
.CodeRay .instance-variable{color:#008080}
.CodeRay .label{color:#970}
.CodeRay .local-variable{color:#963}
.CodeRay .octal{color:#40e}
.CodeRay .predefined{color:#369}
.CodeRay .preprocessor{color:#579}
.CodeRay .pseudo-class{color:#555}
.CodeRay .directive{font-weight:bold}
.CodeRay .type{font-weight:bold}
.CodeRay .predefined-type{color:inherit}
.CodeRay .reserved,.CodeRay .keyword {color:#000;font-weight:bold}
.CodeRay .key{color:#808}
.CodeRay .key .delimiter{color:#606}
.CodeRay .key .char{color:#80f}
.CodeRay .value{color:#088}
.CodeRay .regexp .delimiter{color:#808}
.CodeRay .regexp .content{color:#808}
.CodeRay .regexp .modifier{color:#808}
.CodeRay .regexp .char{color:#d14}
.CodeRay .regexp .function{color:#404;font-weight:bold}
.CodeRay .string{color:#d20}
.CodeRay .string .string .string{background:#ffd0d0}
.CodeRay .string .content{color:#d14}
.CodeRay .string .char{color:#d14}
.CodeRay .string .delimiter{color:#d14}
.CodeRay .shell{color:#d14}
.CodeRay .shell .delimiter{color:#d14}
.CodeRay .symbol{color:#990073}
.CodeRay .symbol .content{color:#a60}
.CodeRay .symbol .delimiter{color:#630}
.CodeRay .tag{color:#008080}
.CodeRay .tag-special{color:#d70}
.CodeRay .variable{color:#036}
.CodeRay .insert{background:#afa}
.CodeRay .delete{background:#faa}
.CodeRay .change{color:#aaf;background:#007}
.CodeRay .head{color:#f8f;background:#505}
.CodeRay .insert .insert{color:#080}
.CodeRay .delete .delete{color:#800}
.CodeRay .change .change{color:#66f}
.CodeRay .head .head{color:#f4f}
91 changes: 1 addition & 90 deletions src/main/java/org/asciidoc/intellij/editor/javafx/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -373,93 +373,4 @@ p,blockquote,dt,td.content,span.alt{font-size:1.0625rem}
p{margin-bottom:1.25rem}
.sidebarblock p,.sidebarblock dt,.sidebarblock td.content,p.tableblock{font-size:1em}
.exampleblock>.content{background-color:#fffef7;border-color:#e0e0dc;-webkit-box-shadow:0 1px 4px #e0e0dc;box-shadow:0 1px 4px #e0e0dc}
.print-only{display:none!important}
/* Stylesheet for CodeRay to match GitHub theme | MIT License | http://foundation.zurb.com */
/*pre.CodeRay {background-color:#f7f7f8;}*/
.CodeRay .line-numbers{border-right:1px solid #d8d8d8;padding:0 0.5em 0 .25em}
.CodeRay span.line-numbers{display:inline-block;margin-right:.5em;color:rgba(0,0,0,.3)}
.CodeRay .line-numbers strong{color:rgba(0,0,0,.4)}
table.CodeRay{border-collapse:separate;border-spacing:0;margin-bottom:0;border:0;background:none}
table.CodeRay td{vertical-align: top;line-height:1.45}
table.CodeRay td.line-numbers{text-align:right}
table.CodeRay td.line-numbers>pre{padding:0;color:rgba(0,0,0,.3)}
table.CodeRay td.code{padding:0 0 0 .5em}
table.CodeRay td.code>pre{padding:0}
.CodeRay .debug{color:#fff !important;background:#000080 !important}
.CodeRay .annotation{color:#007}
.CodeRay .attribute-name{color:#000080}
.CodeRay .attribute-value{color:#700}
.CodeRay .binary{color:#509}
.CodeRay .comment{color:#998;font-style:italic}
.CodeRay .char{color:#04d}
.CodeRay .char .content{color:#04d}
.CodeRay .char .delimiter{color:#039}
.CodeRay .class{color:#458;font-weight:bold}
.CodeRay .complex{color:#a08}
.CodeRay .constant,.CodeRay .predefined-constant{color:#008080}
.CodeRay .color{color:#099}
.CodeRay .class-variable{color:#369}
.CodeRay .decorator{color:#b0b}
.CodeRay .definition{color:#099}
.CodeRay .delimiter{color:#000}
.CodeRay .doc{color:#970}
.CodeRay .doctype{color:#34b}
.CodeRay .doc-string{color:#d42}
.CodeRay .escape{color:#666}
.CodeRay .entity{color:#800}
.CodeRay .error{color:#808}
.CodeRay .exception{color:inherit}
.CodeRay .filename{color:#099}
.CodeRay .function{color:#900;font-weight:bold}
.CodeRay .global-variable{color:#008080}
.CodeRay .hex{color:#058}
.CodeRay .integer,.CodeRay .float{color:#099}
.CodeRay .include{color:#555}
.CodeRay .inline{color:#000}
.CodeRay .inline .inline{background:#ccc}
.CodeRay .inline .inline .inline{background:#bbb}
.CodeRay .inline .inline-delimiter{color:#d14}
.CodeRay .inline-delimiter{color:#d14}
.CodeRay .important{color:#555;font-weight:bold}
.CodeRay .interpreted{color:#b2b}
.CodeRay .instance-variable{color:#008080}
.CodeRay .label{color:#970}
.CodeRay .local-variable{color:#963}
.CodeRay .octal{color:#40e}
.CodeRay .predefined{color:#369}
.CodeRay .preprocessor{color:#579}
.CodeRay .pseudo-class{color:#555}
.CodeRay .directive{font-weight:bold}
.CodeRay .type{font-weight:bold}
.CodeRay .predefined-type{color:inherit}
.CodeRay .reserved,.CodeRay .keyword {color:#000;font-weight:bold}
.CodeRay .key{color:#808}
.CodeRay .key .delimiter{color:#606}
.CodeRay .key .char{color:#80f}
.CodeRay .value{color:#088}
.CodeRay .regexp .delimiter{color:#808}
.CodeRay .regexp .content{color:#808}
.CodeRay .regexp .modifier{color:#808}
.CodeRay .regexp .char{color:#d14}
.CodeRay .regexp .function{color:#404;font-weight:bold}
.CodeRay .string{color:#d20}
.CodeRay .string .string .string{background:#ffd0d0}
.CodeRay .string .content{color:#d14}
.CodeRay .string .char{color:#d14}
.CodeRay .string .delimiter{color:#d14}
.CodeRay .shell{color:#d14}
.CodeRay .shell .delimiter{color:#d14}
.CodeRay .symbol{color:#990073}
.CodeRay .symbol .content{color:#a60}
.CodeRay .symbol .delimiter{color:#630}
.CodeRay .tag{color:#008080}
.CodeRay .tag-special{color:#d70}
.CodeRay .variable{color:#036}
.CodeRay .insert{background:#afa}
.CodeRay .delete{background:#faa}
.CodeRay .change{color:#aaf;background:#007}
.CodeRay .head{color:#f8f;background:#505}
.CodeRay .insert .insert{color:#080}
.CodeRay .delete .delete{color:#800}
.CodeRay .change .change{color:#66f}
.CodeRay .head .head{color:#f4f}
.print-only{display:none!important}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.intellij.util.ui.UIUtil;
import org.asciidoc.intellij.editor.AsciiDocHtmlPanel;
import org.asciidoc.intellij.editor.AsciiDocPreviewEditor;
import org.asciidoc.intellij.settings.AsciiDocApplicationSettings;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
Expand Down Expand Up @@ -44,7 +45,7 @@ public JeditorHtmlPanel(Document document) {

// Create an AsciiDoc style, based on the default stylesheet supplied by UiUtil.getHTMLEditorKit()
// since it contains fix for incorrect styling of tooltips
final String cssFile = UIUtil.isUnderDarcula() ? "darcula.css" : "preview.css";
final String cssFile = isDarcula() ? "darcula.css" : "preview.css";
final StyleSheet customStyle = loadStyleSheet(JeditorHtmlPanel.class.getResource(cssFile));
final StyleSheet style = UIUtil.getHTMLEditorKit().getStyleSheet();
style.addStyleSheet(customStyle);
Expand All @@ -57,6 +58,20 @@ public JeditorHtmlPanel(Document document) {
((DefaultCaret)jEditorPane.getCaret()).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
}

private boolean isDarcula() {
final AsciiDocApplicationSettings settings = AsciiDocApplicationSettings.getInstance();
switch (settings.getAsciiDocPreviewSettings().getPreviewTheme()) {
case INTELLIJ:
return UIUtil.isUnderDarcula();
case ASCIIDOC:
return false;
case DARCULA:
return true;
default:
return false;
}
}

@Override
@NotNull
public JComponent getComponent() {
Expand Down
Loading

0 comments on commit 8960259

Please sign in to comment.