Skip to content

Commit 8fc9b91

Browse files
committed
- refactor css styling update process
- clean unecessary updated files - add flatlack dark font config - fix license issue for coloring preview
1 parent 35d4077 commit 8fc9b91

11 files changed

Lines changed: 174 additions & 59 deletions

File tree

ide/libs.flexmark/nbproject/project.properties

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,6 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
file.reference.flexmark-0.64.8.jar=external/flexmark-0.64.8.jar
19-
file.reference.flexmark-ext-anchorlink-0.64.8.jar=external/flexmark-ext-anchorlink-0.64.8.jar
20-
file.reference.flexmark-ext-emoji-0.64.8.jar=external/flexmark-ext-emoji-0.64.8.jar
21-
file.reference.flexmark-ext-gfm-tasklist-0.64.8.jar=external/flexmark-ext-gfm-tasklist-0.64.8.jar
22-
file.reference.flexmark-ext-tables-0.64.8.jar=external/flexmark-ext-tables-0.64.8.jar
23-
file.reference.flexmark-html2md-converter-0.64.8.jar=external/flexmark-html2md-converter-0.64.8.jar
24-
file.reference.flexmark-util-ast-0.64.8.jar=external/flexmark-util-ast-0.64.8.jar
25-
file.reference.flexmark-util-builder-0.64.8.jar=external/flexmark-util-builder-0.64.8.jar
26-
file.reference.flexmark-util-collection-0.64.8.jar=external/flexmark-util-collection-0.64.8.jar
27-
file.reference.flexmark-util-data-0.64.8.jar=external/flexmark-util-data-0.64.8.jar
28-
file.reference.flexmark-util-dependency-0.64.8.jar=external/flexmark-util-dependency-0.64.8.jar
29-
file.reference.flexmark-util-format-0.64.8.jar=external/flexmark-util-format-0.64.8.jar
30-
file.reference.flexmark-util-html-0.64.8.jar=external/flexmark-util-html-0.64.8.jar
31-
file.reference.flexmark-util-misc-0.64.8.jar=external/flexmark-util-misc-0.64.8.jar
32-
file.reference.flexmark-util-sequence-0.64.8.jar=external/flexmark-util-sequence-0.64.8.jar
33-
file.reference.flexmark-util-visitor-0.64.8.jar=external/flexmark-util-visitor-0.64.8.jar
34-
file.reference.jsoup-1.15.4.jar=external/jsoup-1.15.4.jar
3518
javac.release=11
3619
javac.compilerargs=-Xlint -Xlint:-serial
3720
release.external/flexmark-0.64.8.jar=modules/ext/flexmark-0.64.8.jar

ide/markdown/licenseinfo.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,10 @@
3434
<file>src/org/netbeans/modules/markdown/resources/Template.md</file>
3535
<license ref="Apache-2.0-ASF" />
3636
<comment type="TEMPLATE_MINIMAL_IP" />
37-
</fileset>
37+
</fileset>
38+
<fileset>
39+
<file>src/org/netbeans/modules/markdown/resources/Coloring.md</file>
40+
<license ref="Apache-2.0-ASF" />
41+
<comment type="TEMPLATE_MINIMAL_IP" />
42+
</fileset>
3843
</licenseinfo>

ide/markdown/nbproject/project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
javac.source=1.8
18+
javac.source=17
1919
javac.compilerargs=-Xlint -Xlint:-serial

ide/markdown/src/org/netbeans/modules/markdown/Bundle.properties

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ OpenIDE-Module-Name=Markdown Support
2222
OpenIDE-Module-Short-Description=Syntax highlighting for Markdown
2323

2424
CSS_DEFAULT=body {padding:40px;}\
25-
h1 a, h2 a, h3 a, h4 a, h5 a, h6 a{color:black;}\
2625
h1 code, h2 code, h3 code, h4 code, h5 code, h6 code {font-size:inherit;}\
2726
ul, li ul {margin-left: 20px;}\
2827
li {margin-bottom: 3px;padding-left:5px;}\
@@ -32,5 +31,4 @@ code {border-radius: 6px;}\
3231
pre {padding:16px;}\
3332
pre code {border-radius:0px;}\
3433
blockquote {padding: 0 16px; margin: 0px; border-left: 2px solid rgb(209, 217, 224);}\
35-
blockquote p { color:rgb(89, 99, 110);}\
3634
li blockquote {margin-bottom: 0px;}

ide/markdown/src/org/netbeans/modules/markdown/MarkdownViewerElement.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ public void changedUpdate(DocumentEvent e) {
144144
};
145145

146146
private final Task updater = RP.create(MarkdownViewerElement.this::updateView);
147+
//event for Font config update
148+
private volatile boolean fontChanged = false;
147149
private final PropertyChangeListener pcl = this::colorProfileChange;
148150
private StyledDocument source;
149151

@@ -307,7 +309,13 @@ private void linkHandler(HyperlinkEvent evt) {
307309
* @param evt
308310
*/
309311
public void colorProfileChange(PropertyChangeEvent evt) {
310-
if (EditorSettings.PROP_CURRENT_FONT_COLOR_PROFILE.equals(evt.getPropertyName())) {
312+
//TODO check some context
313+
if (!fontChanged && "fontColors".equals(evt.getPropertyName())) { // NOI18N
314+
//not very safe
315+
fontChanged = true;
316+
}
317+
if (fontChanged || EditorSettings.PROP_CURRENT_FONT_COLOR_PROFILE.equals(evt.getPropertyName())) {
318+
fontChanged = false;
311319
viewer.setEditorKit(new MarkdownEditorKit());
312320
updateView();
313321
}

ide/markdown/src/org/netbeans/modules/markdown/StyleUtils.java

Lines changed: 57 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.netbeans.modules.markdown;
2020

2121
import java.awt.Color;
22-
import java.util.Collection;
2322
import java.util.Enumeration;
2423
import java.util.HashMap;
2524
import java.util.Iterator;
@@ -42,39 +41,27 @@ public class StyleUtils {
4241

4342
private static final Map<String, String> fontConfig2tagMapping = new HashMap<String, String>() {
4443
{
45-
put("body", "body");
46-
put("code", "code");
47-
put("pre", "pre");
48-
put("heading1", "h1, h1 a");
49-
put("heading2", "h2, h2 a");
50-
put("heading3", "h3, h3 a");
51-
put("heading4", "h4, h4 a");
52-
put("heading5", "h5, h5 a");
53-
put("heading6", "h6, h6 a");
44+
put("body", "body"); // NOI18N
45+
put("code", "code"); // NOI18N
46+
put("pre", "pre"); // NOI18N
47+
put("blockquote", "blockquote p"); // NOI18N
48+
put("heading1", "h1, h1 a"); // NOI18N
49+
put("heading2", "h2, h2 a"); // NOI18N
50+
put("heading3", "h3, h3 a"); // NOI18N
51+
put("heading4", "h4, h4 a"); // NOI18N
52+
put("heading5", "h5, h5 a"); // NOI18N
53+
put("heading6", "h6, h6 a"); // NOI18N
54+
put("heading6", "h6, h6 a"); // NOI18N
5455
}
5556
};
5657

5758
public static void addNbSyles(StyleSheet ss) {
58-
String profile = EditorSettings.getDefault().getCurrentFontColorProfile();
59-
String defaultRules = NbBundle.getMessage(StyleUtils.class, "CSS_DEFAULT");
60-
ss.addRule(defaultRules);
61-
FontColorSettings fcs = (MimeLookup.getLookup(MimePath.get(MarkdownDataObject.MIME_TYPE)).lookup(FontColorSettings.class));
62-
AttributeSet defaultAttributes = fcs.getFontColors("default"); // NOI18N
63-
FontColorSettingsFactory fcsf = EditorSettings.getDefault().getFontColorSettings(new String[]{MarkdownDataObject.MIME_TYPE});
64-
Collection<AttributeSet> attributes = fcsf.getAllFontColors(profile);
65-
Iterator<AttributeSet> attributesIt = attributes.iterator();
66-
while (attributesIt.hasNext()) {
67-
AttributeSet attributeSet = attributesIt.next();
68-
Enumeration<?> en = attributeSet.getAttributeNames();
6959

70-
while (en.hasMoreElements()) {
71-
Object key = en.nextElement();
60+
//main css
61+
appendDefaultMarkdownCssRules(ss);
7262

73-
if (key instanceof StyleConstants) {
74-
addRule(ss, attributeSet, defaultAttributes);
75-
}
76-
}
77-
}
63+
//coloring & font settings
64+
appendColoringCssRulesFromFontConfigs(ss);
7865
}
7966

8067
public static void addRule(StyleSheet ss, AttributeSet attributeSet, AttributeSet defaultAttributes) {
@@ -85,22 +72,21 @@ public static void addRule(StyleSheet ss, AttributeSet attributeSet, AttributeSe
8572
return;
8673
}
8774
cssRule.append(htmlTag);
88-
cssRule.append(" {");
89-
90-
cssRule.append(rgbStyling("color", getThemeColor(attributeSet, defaultAttributes, StyleConstants.ColorConstants.Foreground ))); // NOI18N
75+
cssRule.append(" {"); // NOI18N
76+
cssRule.append(rgbStyling("color", getThemeColor(attributeSet, defaultAttributes, StyleConstants.ColorConstants.Foreground))); // NOI18N
9177
cssRule.append(rgbStyling("background-color", getThemeColor(attributeSet, defaultAttributes, StyleConstants.ColorConstants.Background))); // NOI18N
92-
cssRule.append("}");
78+
cssRule.append("}"); // NOI18N
9379
ss.addRule(cssRule.toString());
9480
}
9581

96-
public static Color getThemeColor(AttributeSet attributeSet, AttributeSet defaultAttributes, Object constant ) {
82+
public static Color getThemeColor(AttributeSet attributeSet, AttributeSet defaultAttributes, Object constant) {
9783
Color color = (Color) attributeSet.getAttribute(constant);
9884
if (color == null && defaultAttributes != null) {
9985
color = (Color) defaultAttributes.getAttribute(constant);
10086
}
10187
return color;
10288
}
103-
89+
10490
public static String rgbStyling(String property, Color color) {
10591
StringBuilder cssRule = new StringBuilder();
10692
if (color != null) {
@@ -113,7 +99,43 @@ public static String rgbStyling(String property, Color color) {
11399
cssRule.append(color.getBlue());
114100
cssRule.append(");"); // NOI18N
115101
}
116-
102+
117103
return cssRule.toString();
118104
}
105+
106+
private static void appendDefaultMarkdownCssRules(StyleSheet ss) {
107+
String defaultRules = NbBundle.getMessage(StyleUtils.class, "CSS_DEFAULT"); // NOI18N
108+
ss.addRule(defaultRules);
109+
}
110+
111+
private static Iterator<AttributeSet> loadCustomizedMarkdownFontAttributes() {
112+
String profile = EditorSettings.getDefault().getCurrentFontColorProfile();
113+
FontColorSettingsFactory fcsf = EditorSettings.getDefault().getFontColorSettings(new String[]{MarkdownDataObject.MIME_TYPE});
114+
return fcsf.getAllFontColors(profile).iterator();
115+
}
116+
117+
private static AttributeSet loadDefaultNbMarkdownFontAttributes() {
118+
FontColorSettings fcs = (MimeLookup.getLookup(MimePath.get(MarkdownDataObject.MIME_TYPE)).lookup(FontColorSettings.class));
119+
return fcs.getFontColors("default"); // NOI18N
120+
}
121+
122+
private static void appendColoringCssRulesFromFontConfigs(StyleSheet ss) {
123+
//contains the default / fallback values of fontConfigs
124+
AttributeSet defaultAttributes = loadDefaultNbMarkdownFontAttributes();
125+
126+
//contains the full list of fontConfigs but populated only with custom values
127+
Iterator<AttributeSet> attributesIt = loadCustomizedMarkdownFontAttributes();
128+
while (attributesIt.hasNext()) {
129+
AttributeSet attributeSet = attributesIt.next();
130+
Enumeration<?> en = attributeSet.getAttributeNames();
131+
132+
while (en.hasMoreElements()) {
133+
Object key = en.nextElement();
134+
135+
if (key instanceof StyleConstants) {
136+
addRule(ss, attributeSet, defaultAttributes);
137+
}
138+
}
139+
}
140+
}
119141
}

ide/markdown/src/org/netbeans/modules/markdown/resources/Bundle.properties

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,14 @@
1616
# under the License.
1717

1818
Editors/text/x-markdown=Markdown
19+
20+
body = Body
21+
heading1 = H1
22+
heading2 = H2
23+
heading3 = H3
24+
heading4 = H4
25+
heading5 = H5
26+
heading6 = H6
27+
28+
pre = Code block
29+
code = Inline code

ide/markdown/src/org/netbeans/modules/markdown/resources/coloring.md renamed to ide/markdown/src/org/netbeans/modules/markdown/resources/Coloring.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
No preview for the moment
1+
2+
=========================
3+
```
4+
COLORING PREVIEW NOT ENABLED
5+
```
6+
=========================
7+
28
# Markdown Cheat Sheet (Example File)
39

410
This is a **generic Markdown template** showcasing essential formatting features.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
21+
-->
22+
<!DOCTYPE fontscolors PUBLIC "-//NetBeans//DTD Editor Fonts and Colors settings 1.1//EN" "http://www.netbeans.org/dtds/EditorFontsColors-1_1.dtd">
23+
<fontscolors>
24+
<fontcolor name="body" default="default"/>
25+
<fontcolor name="code" bgColor="38566F"/>
26+
<fontcolor name="pre" bgColor="38566F"/>
27+
<fontcolor name="heading1"/>
28+
<fontcolor name="heading2" default="heading1"/>
29+
<fontcolor name="heading3" default="heading1"/>
30+
<fontcolor name="heading4" default="heading1"/>
31+
<fontcolor name="heading5" default="heading1"/>
32+
<fontcolor name="heading6" default="heading1"/>
33+
</fontscolors>
34+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
21+
-->
22+
<!DOCTYPE fontscolors PUBLIC "-//NetBeans//DTD Editor Fonts and Colors settings 1.1//EN" "http://www.netbeans.org/dtds/EditorFontsColors-1_1.dtd">
23+
<fontscolors>
24+
<fontcolor name="body" default="default"/>
25+
<fontcolor name="code" bgColor="364135"/>
26+
<fontcolor name="pre" bgColor="364135"/>
27+
<fontcolor name="heading1"/>
28+
<fontcolor name="heading2" default="heading1"/>
29+
<fontcolor name="heading3" default="heading1"/>
30+
<fontcolor name="heading4" default="heading1"/>
31+
<fontcolor name="heading5" default="heading1"/>
32+
<fontcolor name="heading6" default="heading1"/>
33+
</fontscolors>
34+

0 commit comments

Comments
 (0)