From 1982844a52c78f27add25f51baa85d8254db096c Mon Sep 17 00:00:00 2001 From: Bogdan Haidu Date: Fri, 27 Feb 2026 20:01:49 +0200 Subject: [PATCH 1/4] markdown document preview improvements Closes #6652 - hardcoded swing html renderer compatible css styling - custom
tag renderer - strikethrough extension - uniform mime_type - update vscode regex for striketrhough detection --- ide/libs.flexmark/external/binaries-list | 1 + ide/libs.flexmark/manifest.mf | 2 +- .../nbproject/project.properties | 18 +++++ ide/libs.flexmark/nbproject/project.xml | 68 ++++++++++--------- .../modules/markdown/MarkdownDataObject.java | 4 +- .../markdown/MarkdownViewerElement.java | 10 ++- .../modules/markdown/markdown.tmLanguage.json | 4 +- .../ui/preview/MarkdownEditorKit.java | 67 +++++++++++++++++- .../ui/preview/views/HorizontalRuleView.java | 55 +++++++++++++++ .../ui/preview/views/MarkdownViewFactory.java | 2 + 10 files changed, 191 insertions(+), 40 deletions(-) create mode 100644 ide/markdown/src/org/netbeans/modules/markdown/ui/preview/views/HorizontalRuleView.java diff --git a/ide/libs.flexmark/external/binaries-list b/ide/libs.flexmark/external/binaries-list index 76b2667dc273..9fba964a4608 100644 --- a/ide/libs.flexmark/external/binaries-list +++ b/ide/libs.flexmark/external/binaries-list @@ -30,4 +30,5 @@ A3F92ABD0ACBB4D1F12DFD3D6128F73D245D6BA9 com.vladsch.flexmark:flexmark-util-data 985913246DF64FE7E768EB0664B45DEDEA7536CF com.vladsch.flexmark:flexmark-util-sequence:0.64.8 A8178BA6DFD7A958353A60B3A51FE7EDB1578B49 com.vladsch.flexmark:flexmark-util-visitor:0.64.8 4ADC75ADA3D870908BDBFFB76650D19305250D3C com.vladsch.flexmark:flexmark-ext-gfm-tasklist:0.64.8 +1851E124C6D85C5C7F3FDBBE066D30A76AD6BE44 com.vladsch.flexmark:flexmark-ext-gfm-strikethrough:0.64.8 CD56EB47DCD4590EF6451F87E5EC33BDDD1A9A51 org.jsoup:jsoup:1.15.4 diff --git a/ide/libs.flexmark/manifest.mf b/ide/libs.flexmark/manifest.mf index 4f6866796a25..78acbb9fc942 100644 --- a/ide/libs.flexmark/manifest.mf +++ b/ide/libs.flexmark/manifest.mf @@ -2,5 +2,5 @@ Manifest-Version: 1.0 AutoUpdate-Show-In-Client: true OpenIDE-Module: org.netbeans.libs.flexmark OpenIDE-Module-Localizing-Bundle: org/netbeans/libs/flexmark/Bundle.properties -OpenIDE-Module-Specification-Version: 1.25 +OpenIDE-Module-Specification-Version: 1.26 diff --git a/ide/libs.flexmark/nbproject/project.properties b/ide/libs.flexmark/nbproject/project.properties index a5b37dfe8353..5737f6c58233 100644 --- a/ide/libs.flexmark/nbproject/project.properties +++ b/ide/libs.flexmark/nbproject/project.properties @@ -15,6 +15,23 @@ # specific language governing permissions and limitations # under the License. +file.reference.flexmark-0.64.8.jar=external/flexmark-0.64.8.jar +file.reference.flexmark-ext-anchorlink-0.64.8.jar=external/flexmark-ext-anchorlink-0.64.8.jar +file.reference.flexmark-ext-emoji-0.64.8.jar=external/flexmark-ext-emoji-0.64.8.jar +file.reference.flexmark-ext-gfm-tasklist-0.64.8.jar=external/flexmark-ext-gfm-tasklist-0.64.8.jar +file.reference.flexmark-ext-tables-0.64.8.jar=external/flexmark-ext-tables-0.64.8.jar +file.reference.flexmark-html2md-converter-0.64.8.jar=external/flexmark-html2md-converter-0.64.8.jar +file.reference.flexmark-util-ast-0.64.8.jar=external/flexmark-util-ast-0.64.8.jar +file.reference.flexmark-util-builder-0.64.8.jar=external/flexmark-util-builder-0.64.8.jar +file.reference.flexmark-util-collection-0.64.8.jar=external/flexmark-util-collection-0.64.8.jar +file.reference.flexmark-util-data-0.64.8.jar=external/flexmark-util-data-0.64.8.jar +file.reference.flexmark-util-dependency-0.64.8.jar=external/flexmark-util-dependency-0.64.8.jar +file.reference.flexmark-util-format-0.64.8.jar=external/flexmark-util-format-0.64.8.jar +file.reference.flexmark-util-html-0.64.8.jar=external/flexmark-util-html-0.64.8.jar +file.reference.flexmark-util-misc-0.64.8.jar=external/flexmark-util-misc-0.64.8.jar +file.reference.flexmark-util-sequence-0.64.8.jar=external/flexmark-util-sequence-0.64.8.jar +file.reference.flexmark-util-visitor-0.64.8.jar=external/flexmark-util-visitor-0.64.8.jar +file.reference.jsoup-1.15.4.jar=external/jsoup-1.15.4.jar javac.release=11 javac.compilerargs=-Xlint -Xlint:-serial release.external/flexmark-0.64.8.jar=modules/ext/flexmark-0.64.8.jar @@ -33,6 +50,7 @@ release.external/flexmark-ext-emoji-0.64.8.jar=modules/ext/flexmark-ext-emoji-0. release.external/flexmark-ext-anchorlink-0.64.8.jar=modules/ext/flexmark-ext-anchorlink-0.64.8.jar release.external/flexmark-ext-tables-0.64.8.jar=modules/ext/flexmark-ext-tables-0.64.8.jar release.external/flexmark-ext-gfm-tasklist-0.64.8.jar=modules/ext/flexmark-ext-gfm-tasklist-0.64.8.jar +release.external/flexmark-ext-gfm-strikethrough-0.64.8.jar=modules/ext/flexmark-ext-gfm-strikethrough-0.64.8.jar release.external/jsoup-1.15.4.jar=modules/ext/jsoup-1.15.4.jar # Sigtest seems to have issues with some Java 11 class files, better to disable it. diff --git a/ide/libs.flexmark/nbproject/project.xml b/ide/libs.flexmark/nbproject/project.xml index d2d8e0ca6227..64f4f141192b 100644 --- a/ide/libs.flexmark/nbproject/project.xml +++ b/ide/libs.flexmark/nbproject/project.xml @@ -30,72 +30,76 @@ org.jsoup - ext/flexmark-html2md-converter-0.64.8.jar - external/flexmark-html2md-converter-0.64.8.jar - - - ext/jsoup-1.15.4.jar - external/jsoup-1.15.4.jar - - - ext/flexmark-util-ast-0.64.8.jar - external/flexmark-util-ast-0.64.8.jar + ext/flexmark-util-misc-0.64.8.jar + external/flexmark-util-misc-0.64.8.jar - ext/flexmark-util-builder-0.64.8.jar - external/flexmark-util-builder-0.64.8.jar + ext/flexmark-util-dependency-0.64.8.jar + external/flexmark-util-dependency-0.64.8.jar - ext/flexmark-util-collection-0.64.8.jar - external/flexmark-util-collection-0.64.8.jar + ext/flexmark-util-visitor-0.64.8.jar + external/flexmark-util-visitor-0.64.8.jar - ext/flexmark-util-data-0.64.8.jar - external/flexmark-util-data-0.64.8.jar + ext/flexmark-ext-anchorlink-0.64.8.jar + external/flexmark-ext-anchorlink-0.64.8.jar - ext/flexmark-util-dependency-0.64.8.jar - external/flexmark-util-dependency-0.64.8.jar + ext/flexmark-ext-gfm-tasklist-0.64.8.jar + external/flexmark-ext-gfm-tasklist-0.64.8.jar - ext/flexmark-util-format-0.64.8.jar - external/flexmark-util-format-0.64.8.jar + ext/flexmark-util-builder-0.64.8.jar + external/flexmark-util-builder-0.64.8.jar ext/flexmark-util-html-0.64.8.jar external/flexmark-util-html-0.64.8.jar - ext/flexmark-util-misc-0.64.8.jar - external/flexmark-util-misc-0.64.8.jar + ext/jsoup-1.15.4.jar + external/jsoup-1.15.4.jar - ext/flexmark-util-sequence-0.64.8.jar - external/flexmark-util-sequence-0.64.8.jar + ext/flexmark-util-format-0.64.8.jar + external/flexmark-util-format-0.64.8.jar - ext/flexmark-util-visitor-0.64.8.jar - external/flexmark-util-visitor-0.64.8.jar + ext/flexmark-html2md-converter-0.64.8.jar + external/flexmark-html2md-converter-0.64.8.jar ext/flexmark-ext-emoji-0.64.8.jar external/flexmark-ext-emoji-0.64.8.jar - ext/flexmark-ext-anchorlink-0.64.8.jar - external/flexmark-ext-anchorlink-0.64.8.jar + ext/flexmark-0.64.8.jar + external/flexmark-0.64.8.jar + + + ext/flexmark-util-ast-0.64.8.jar + external/flexmark-util-ast-0.64.8.jar + + + ext/flexmark-util-data-0.64.8.jar + external/flexmark-util-data-0.64.8.jar ext/flexmark-ext-tables-0.64.8.jar external/flexmark-ext-tables-0.64.8.jar - ext/flexmark-0.64.8.jar - external/flexmark-0.64.8.jar + ext/flexmark-util-collection-0.64.8.jar + external/flexmark-util-collection-0.64.8.jar - ext/flexmark-ext-gfm-tasklist-0.64.8.jar - external/flexmark-ext-gfm-tasklist-0.64.8.jar + ext/flexmark-util-sequence-0.64.8.jar + external/flexmark-util-sequence-0.64.8.jar + + + ext/flexmark-ext-gfm-strikethrough-0.64.8.jar + external/flexmark-ext-gfm-strikethrough-0.64.8.jar diff --git a/ide/markdown/src/org/netbeans/modules/markdown/MarkdownDataObject.java b/ide/markdown/src/org/netbeans/modules/markdown/MarkdownDataObject.java index 8629433abec4..5a6c862d460c 100644 --- a/ide/markdown/src/org/netbeans/modules/markdown/MarkdownDataObject.java +++ b/ide/markdown/src/org/netbeans/modules/markdown/MarkdownDataObject.java @@ -105,11 +105,11 @@ @GrammarRegistration(mimeType=MarkdownDataObject.MIME_TYPE, grammar="markdown.tmLanguage.json") public class MarkdownDataObject extends MultiDataObject { - public static final String MIME_TYPE = "text/x-markdown-nb"; + public static final String MIME_TYPE = "text/x-markdown"; public MarkdownDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException { super(pf, loader); - registerEditor("text/x-markdown", true); + registerEditor(MIME_TYPE, true); } @Override diff --git a/ide/markdown/src/org/netbeans/modules/markdown/MarkdownViewerElement.java b/ide/markdown/src/org/netbeans/modules/markdown/MarkdownViewerElement.java index db65b2a5d9e9..27c296cb1509 100644 --- a/ide/markdown/src/org/netbeans/modules/markdown/MarkdownViewerElement.java +++ b/ide/markdown/src/org/netbeans/modules/markdown/MarkdownViewerElement.java @@ -19,6 +19,7 @@ package org.netbeans.modules.markdown; import com.vladsch.flexmark.ext.anchorlink.AnchorLinkExtension; +import com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughExtension; import com.vladsch.flexmark.ext.gfm.tasklist.TaskListExtension; import com.vladsch.flexmark.ext.tables.TablesExtension; import com.vladsch.flexmark.html.HtmlRenderer; @@ -49,6 +50,7 @@ import org.netbeans.core.spi.multiview.CloseOperationState; import org.netbeans.core.spi.multiview.MultiViewElement; import org.netbeans.core.spi.multiview.MultiViewElementCallback; +import static org.netbeans.modules.markdown.MarkdownDataObject.MIME_TYPE; import org.netbeans.modules.markdown.ui.preview.MarkdownEditorKit; import org.openide.awt.HtmlBrowser; import org.openide.awt.UndoRedo; @@ -71,7 +73,7 @@ @MultiViewElement.Registration( displayName = "#LBL_MarkdownViewer", iconBase = "org/netbeans/modules/markdown/markdown.png", - mimeType = "text/x-markdown", + mimeType = MIME_TYPE, persistenceType = TopComponent.PERSISTENCE_NEVER, preferredID = "MarkdownViewer", position = 2000 @@ -94,7 +96,8 @@ public class MarkdownViewerElement implements MultiViewElement { .set(Parser.EXTENSIONS, Arrays.asList( AnchorLinkExtension.create(), TablesExtension.create(), - TaskListExtension.create() + TaskListExtension.create(), + StrikethroughExtension.create() )) .set(HtmlRenderer.INDENT_SIZE, 2) .set(HtmlRenderer.RENDER_HEADER_ID, true) @@ -111,6 +114,9 @@ public class MarkdownViewerElement implements MultiViewElement { .set(TablesExtension.APPEND_MISSING_COLUMNS, true) .set(TablesExtension.DISCARD_EXTRA_COLUMNS, true) .set(TablesExtension.HEADER_SEPARATOR_COLUMN_MATCH, true) + // Strikethrough change from del to s tag + .set(StrikethroughExtension.STRIKETHROUGH_STYLE_HTML_OPEN, "") + .set(StrikethroughExtension.STRIKETHROUGH_STYLE_HTML_CLOSE, "") .toImmutable(); final Parser parser = Parser.builder(OPTIONS).build(); diff --git a/ide/markdown/src/org/netbeans/modules/markdown/markdown.tmLanguage.json b/ide/markdown/src/org/netbeans/modules/markdown/markdown.tmLanguage.json index 463a3fbbbdec..f28917c770af 100644 --- a/ide/markdown/src/org/netbeans/modules/markdown/markdown.tmLanguage.json +++ b/ide/markdown/src/org/netbeans/modules/markdown/markdown.tmLanguage.json @@ -4,7 +4,7 @@ "If you want to provide a fix or improvement, please create a pull request against the original repository.", "Once accepted there, we are happy to receive an update request." ], - "version": "https://github.com/microsoft/vscode-markdown-tm-grammar/commit/7418dd20d76c72e82fadee2909e03239e9973b35", + "version": "https://github.com/microsoft/vscode-markdown-tm-grammar/commit/548ccb91ef58ba40ac745b400d889933ccd5eb4d", "name": "Markdown", "scopeName": "text.html.markdown", "patterns": [ @@ -3084,7 +3084,7 @@ "name": "punctuation.definition.strikethrough.markdown" } }, - "match": "(? Date: Tue, 3 Mar 2026 11:18:50 +0200 Subject: [PATCH 2/4] update flexmark license for strikethrough jar --- ide/libs.flexmark/external/flexmark-0.64.8-license.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ide/libs.flexmark/external/flexmark-0.64.8-license.txt b/ide/libs.flexmark/external/flexmark-0.64.8-license.txt index 454986f6a8b7..3613e9233a19 100644 --- a/ide/libs.flexmark/external/flexmark-0.64.8-license.txt +++ b/ide/libs.flexmark/external/flexmark-0.64.8-license.txt @@ -3,7 +3,7 @@ Version: 0.64.8 License: BSD-flexmark Description: FlexMark library Origin: https://github.com/vsch/flexmark-java -Files: flexmark-0.64.8.jar flexmark-ext-anchorlink-0.64.8.jar flexmark-ext-emoji-0.64.8.jar flexmark-ext-tables-0.64.8.jar flexmark-html2md-converter-0.64.8.jar flexmark-util-ast-0.64.8.jar flexmark-util-builder-0.64.8.jar flexmark-util-collection-0.64.8.jar flexmark-util-data-0.64.8.jar flexmark-util-dependency-0.64.8.jar flexmark-util-format-0.64.8.jar flexmark-util-html-0.64.8.jar flexmark-util-misc-0.64.8.jar flexmark-util-sequence-0.64.8.jar flexmark-util-visitor-0.64.8.jar flexmark-ext-gfm-tasklist-0.64.8.jar +Files: flexmark-0.64.8.jar flexmark-ext-anchorlink-0.64.8.jar flexmark-ext-emoji-0.64.8.jar flexmark-ext-tables-0.64.8.jar flexmark-html2md-converter-0.64.8.jar flexmark-util-ast-0.64.8.jar flexmark-util-builder-0.64.8.jar flexmark-util-collection-0.64.8.jar flexmark-util-data-0.64.8.jar flexmark-util-dependency-0.64.8.jar flexmark-util-format-0.64.8.jar flexmark-util-html-0.64.8.jar flexmark-util-misc-0.64.8.jar flexmark-util-sequence-0.64.8.jar flexmark-util-visitor-0.64.8.jar flexmark-ext-gfm-tasklist-0.64.8.jar flexmark-ext-gfm-strikethrough-0.64.8.jar Copyright (c) 2015-2016, Atlassian Pty Ltd All rights reserved. From 35d40772dd1d75271ab0575467710a3fe9f365d1 Mon Sep 17 00:00:00 2001 From: Bogdan Haidu Date: Wed, 4 Mar 2026 22:48:13 +0200 Subject: [PATCH 3/4] - move basic Css in bundle - link element styling to font config - add update view event on font profile change --- .../nbproject/project.xml | 1 + ide/markdown/manifest.mf | 1 + ide/markdown/nbproject/project.xml | 27 ++++ .../modules/markdown/Bundle.properties | 14 +++ .../markdown/MarkdownViewerElement.java | 17 +++ .../netbeans/modules/markdown/StyleUtils.java | 119 ++++++++++++++++++ .../markdown/resources/Bundle.properties | 18 +++ .../resources/FontAndColors-bluetheme.xml | 34 +++++ .../resources/FontAndColors-citylights.xml | 34 +++++ .../markdown/resources/FontAndColors.xml | 34 +++++ .../modules/markdown/resources/coloring.md | 56 +++++++++ .../modules/markdown/resources/layer.xml | 68 ++++++++++ .../ui/preview/MarkdownEditorKit.java | 43 +------ 13 files changed, 426 insertions(+), 40 deletions(-) create mode 100644 ide/markdown/src/org/netbeans/modules/markdown/StyleUtils.java create mode 100644 ide/markdown/src/org/netbeans/modules/markdown/resources/Bundle.properties create mode 100644 ide/markdown/src/org/netbeans/modules/markdown/resources/FontAndColors-bluetheme.xml create mode 100644 ide/markdown/src/org/netbeans/modules/markdown/resources/FontAndColors-citylights.xml create mode 100644 ide/markdown/src/org/netbeans/modules/markdown/resources/FontAndColors.xml create mode 100644 ide/markdown/src/org/netbeans/modules/markdown/resources/coloring.md create mode 100644 ide/markdown/src/org/netbeans/modules/markdown/resources/layer.xml diff --git a/ide/editor.settings.storage/nbproject/project.xml b/ide/editor.settings.storage/nbproject/project.xml index 83a372138070..762c7fc295de 100644 --- a/ide/editor.settings.storage/nbproject/project.xml +++ b/ide/editor.settings.storage/nbproject/project.xml @@ -175,6 +175,7 @@ org.netbeans.modules.gsf org.netbeans.modules.jvi org.netbeans.modules.languages + org.netbeans.modules.markdown org.netbeans.modules.options.editor org.netbeans.modules.editor.fold org.netbeans.modules.editor.fold.nbui diff --git a/ide/markdown/manifest.mf b/ide/markdown/manifest.mf index fe00e45399b8..44aa92cd5218 100644 --- a/ide/markdown/manifest.mf +++ b/ide/markdown/manifest.mf @@ -1,6 +1,7 @@ Manifest-Version: 1.0 AutoUpdate-Show-In-Client: true OpenIDE-Module: org.netbeans.modules.markdown +OpenIDE-Module-Layer: org/netbeans/modules/markdown/resources/layer.xml OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/markdown/Bundle.properties OpenIDE-Module-Specification-Version: 1.20 diff --git a/ide/markdown/nbproject/project.xml b/ide/markdown/nbproject/project.xml index 2634c03dc1fd..ab3649a59c34 100644 --- a/ide/markdown/nbproject/project.xml +++ b/ide/markdown/nbproject/project.xml @@ -50,6 +50,33 @@ 1.15 + + org.netbeans.modules.editor.mimelookup + + + + 1 + 1.72 + + + + org.netbeans.modules.editor.settings + + + + 1 + 1.89 + + + + org.netbeans.modules.editor.settings.storage + + + + 1 + 1.84 + + org.netbeans.modules.textmate.lexer diff --git a/ide/markdown/src/org/netbeans/modules/markdown/Bundle.properties b/ide/markdown/src/org/netbeans/modules/markdown/Bundle.properties index 0f3cccabdc15..bfaeaa91317e 100644 --- a/ide/markdown/src/org/netbeans/modules/markdown/Bundle.properties +++ b/ide/markdown/src/org/netbeans/modules/markdown/Bundle.properties @@ -20,3 +20,17 @@ OpenIDE-Module-Long-Description=\ Syntax highlighting for Markdown. OpenIDE-Module-Name=Markdown Support OpenIDE-Module-Short-Description=Syntax highlighting for Markdown + +CSS_DEFAULT=body {padding:40px;}\ +h1 a, h2 a, h3 a, h4 a, h5 a, h6 a{color:black;}\ +h1 code, h2 code, h3 code, h4 code, h5 code, h6 code {font-size:inherit;}\ +ul, li ul {margin-left: 20px;}\ +li {margin-bottom: 3px;padding-left:5px;}\ +table {border-spacing:0;}\ +th, td {border:1px solid rgb(209, 217, 224); padding:10px;}\ +code {border-radius: 6px;}\ +pre {padding:16px;}\ +pre code {border-radius:0px;}\ +blockquote {padding: 0 16px; margin: 0px; border-left: 2px solid rgb(209, 217, 224);}\ +blockquote p { color:rgb(89, 99, 110);}\ +li blockquote {margin-bottom: 0px;} \ No newline at end of file diff --git a/ide/markdown/src/org/netbeans/modules/markdown/MarkdownViewerElement.java b/ide/markdown/src/org/netbeans/modules/markdown/MarkdownViewerElement.java index 27c296cb1509..61b75c31192f 100644 --- a/ide/markdown/src/org/netbeans/modules/markdown/MarkdownViewerElement.java +++ b/ide/markdown/src/org/netbeans/modules/markdown/MarkdownViewerElement.java @@ -28,6 +28,8 @@ import com.vladsch.flexmark.util.data.MutableDataSet; import java.awt.BorderLayout; import java.awt.Rectangle; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import java.io.IOException; import java.io.Reader; import java.io.StringReader; @@ -50,6 +52,7 @@ import org.netbeans.core.spi.multiview.CloseOperationState; import org.netbeans.core.spi.multiview.MultiViewElement; import org.netbeans.core.spi.multiview.MultiViewElementCallback; +import org.netbeans.modules.editor.settings.storage.api.EditorSettings; import static org.netbeans.modules.markdown.MarkdownDataObject.MIME_TYPE; import org.netbeans.modules.markdown.ui.preview.MarkdownEditorKit; import org.openide.awt.HtmlBrowser; @@ -64,6 +67,7 @@ import org.openide.util.NbBundle.Messages; import org.openide.util.RequestProcessor; import org.openide.util.RequestProcessor.Task; +import org.openide.util.WeakListeners; import org.openide.windows.TopComponent; /** @@ -140,6 +144,7 @@ public void changedUpdate(DocumentEvent e) { }; private final Task updater = RP.create(MarkdownViewerElement.this::updateView); + private final PropertyChangeListener pcl = this::colorProfileChange; private StyledDocument source; public MarkdownViewerElement(Lookup lookup) { @@ -149,6 +154,7 @@ public MarkdownViewerElement(Lookup lookup) { @Override public JComponent getVisualRepresentation() { if (component == null) { + EditorSettings.getDefault().addPropertyChangeListener(WeakListeners.propertyChange(pcl, this)); viewer = new JEditorPane(); viewer.setEditorKit(new MarkdownEditorKit()); viewer.setEditable(false); @@ -295,4 +301,15 @@ private void linkHandler(HyperlinkEvent evt) { } } } + + /** + * redraw document if profile changes + * @param evt + */ + public void colorProfileChange(PropertyChangeEvent evt) { + if (EditorSettings.PROP_CURRENT_FONT_COLOR_PROFILE.equals(evt.getPropertyName())) { + viewer.setEditorKit(new MarkdownEditorKit()); + updateView(); + } + } } diff --git a/ide/markdown/src/org/netbeans/modules/markdown/StyleUtils.java b/ide/markdown/src/org/netbeans/modules/markdown/StyleUtils.java new file mode 100644 index 000000000000..7f76240f6199 --- /dev/null +++ b/ide/markdown/src/org/netbeans/modules/markdown/StyleUtils.java @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.markdown; + +import java.awt.Color; +import java.util.Collection; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import javax.swing.text.AttributeSet; +import javax.swing.text.StyleConstants; +import javax.swing.text.html.StyleSheet; +import org.netbeans.api.editor.mimelookup.MimeLookup; +import org.netbeans.api.editor.mimelookup.MimePath; +import org.netbeans.modules.editor.settings.storage.api.EditorSettings; +import org.netbeans.api.editor.settings.FontColorSettings; +import org.netbeans.modules.editor.settings.storage.api.FontColorSettingsFactory; +import org.openide.util.NbBundle; + +/** + * + * @author bhaidu + */ +public class StyleUtils { + + private static final Map fontConfig2tagMapping = new HashMap() { + { + put("body", "body"); + put("code", "code"); + put("pre", "pre"); + put("heading1", "h1, h1 a"); + put("heading2", "h2, h2 a"); + put("heading3", "h3, h3 a"); + put("heading4", "h4, h4 a"); + put("heading5", "h5, h5 a"); + put("heading6", "h6, h6 a"); + } + }; + + public static void addNbSyles(StyleSheet ss) { + String profile = EditorSettings.getDefault().getCurrentFontColorProfile(); + String defaultRules = NbBundle.getMessage(StyleUtils.class, "CSS_DEFAULT"); + ss.addRule(defaultRules); + FontColorSettings fcs = (MimeLookup.getLookup(MimePath.get(MarkdownDataObject.MIME_TYPE)).lookup(FontColorSettings.class)); + AttributeSet defaultAttributes = fcs.getFontColors("default"); // NOI18N + FontColorSettingsFactory fcsf = EditorSettings.getDefault().getFontColorSettings(new String[]{MarkdownDataObject.MIME_TYPE}); + Collection attributes = fcsf.getAllFontColors(profile); + Iterator attributesIt = attributes.iterator(); + while (attributesIt.hasNext()) { + AttributeSet attributeSet = attributesIt.next(); + Enumeration en = attributeSet.getAttributeNames(); + + while (en.hasMoreElements()) { + Object key = en.nextElement(); + + if (key instanceof StyleConstants) { + addRule(ss, attributeSet, defaultAttributes); + } + } + } + } + + public static void addRule(StyleSheet ss, AttributeSet attributeSet, AttributeSet defaultAttributes) { + String nameAttr = (String) attributeSet.getAttribute(StyleConstants.NameAttribute); + StringBuilder cssRule = new StringBuilder(); + String htmlTag = fontConfig2tagMapping.get(nameAttr); + if (htmlTag == null) { + return; + } + cssRule.append(htmlTag); + cssRule.append(" {"); + + cssRule.append(rgbStyling("color", getThemeColor(attributeSet, defaultAttributes, StyleConstants.ColorConstants.Foreground ))); // NOI18N + cssRule.append(rgbStyling("background-color", getThemeColor(attributeSet, defaultAttributes, StyleConstants.ColorConstants.Background))); // NOI18N + cssRule.append("}"); + ss.addRule(cssRule.toString()); + } + + public static Color getThemeColor(AttributeSet attributeSet, AttributeSet defaultAttributes, Object constant ) { + Color color = (Color) attributeSet.getAttribute(constant); + if (color == null && defaultAttributes != null) { + color = (Color) defaultAttributes.getAttribute(constant); + } + return color; + } + + public static String rgbStyling(String property, Color color) { + StringBuilder cssRule = new StringBuilder(); + if (color != null) { + cssRule.append(property); + cssRule.append(":rgb("); // NOI18N + cssRule.append(color.getRed()); + cssRule.append(","); // NOI18N + cssRule.append(color.getGreen()); + cssRule.append(","); // NOI18N + cssRule.append(color.getBlue()); + cssRule.append(");"); // NOI18N + } + + return cssRule.toString(); + } +} diff --git a/ide/markdown/src/org/netbeans/modules/markdown/resources/Bundle.properties b/ide/markdown/src/org/netbeans/modules/markdown/resources/Bundle.properties new file mode 100644 index 000000000000..d92551e15de7 --- /dev/null +++ b/ide/markdown/src/org/netbeans/modules/markdown/resources/Bundle.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +Editors/text/x-markdown=Markdown diff --git a/ide/markdown/src/org/netbeans/modules/markdown/resources/FontAndColors-bluetheme.xml b/ide/markdown/src/org/netbeans/modules/markdown/resources/FontAndColors-bluetheme.xml new file mode 100644 index 000000000000..aab01d2809a7 --- /dev/null +++ b/ide/markdown/src/org/netbeans/modules/markdown/resources/FontAndColors-bluetheme.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + diff --git a/ide/markdown/src/org/netbeans/modules/markdown/resources/FontAndColors-citylights.xml b/ide/markdown/src/org/netbeans/modules/markdown/resources/FontAndColors-citylights.xml new file mode 100644 index 000000000000..aab01d2809a7 --- /dev/null +++ b/ide/markdown/src/org/netbeans/modules/markdown/resources/FontAndColors-citylights.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + diff --git a/ide/markdown/src/org/netbeans/modules/markdown/resources/FontAndColors.xml b/ide/markdown/src/org/netbeans/modules/markdown/resources/FontAndColors.xml new file mode 100644 index 000000000000..50d1eaac3c31 --- /dev/null +++ b/ide/markdown/src/org/netbeans/modules/markdown/resources/FontAndColors.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + diff --git a/ide/markdown/src/org/netbeans/modules/markdown/resources/coloring.md b/ide/markdown/src/org/netbeans/modules/markdown/resources/coloring.md new file mode 100644 index 000000000000..c505d267e199 --- /dev/null +++ b/ide/markdown/src/org/netbeans/modules/markdown/resources/coloring.md @@ -0,0 +1,56 @@ +No preview for the moment +# Markdown Cheat Sheet (Example File) + +This is a **generic Markdown template** showcasing essential formatting features. + +--- + +## 1. Headers +# H1 (Largest) +## H2 +### H3 +#### H4 +##### H5 +###### H6 (Smallest) + +--- + +## 2. Text Formatting +- **Bold** (`**text**` or `__text__`) +- *Italic* (`*text*` or `_text_`) +- ~~Strikethrough~~ (`~~text~~`) +- `Inline Code` (`` `code` ``) +- > Blockquote (prefix with `>`) + +--- + +## 3. Lists +### Unordered List +- Item 1 +- Item 2 + - Nested Item (indent with 2 spaces) + +### Ordered List +1. First item +2. Second item + 1. Nested item (indent with 3 spaces) + +### Task List +- [x] Completed task +- [ ] Pending task (`[ ]`) + +--- + +## 4. Links +- [Hyperlink](https://example.com) (`[text](url)`) + +--- + +## 5. Code Blocks +```java +# Syntax-highlighted block (java) +class HelloWorld { + public static main(String... args) { + System.out.println("Hello markdown"); + } +} diff --git a/ide/markdown/src/org/netbeans/modules/markdown/resources/layer.xml b/ide/markdown/src/org/netbeans/modules/markdown/resources/layer.xml new file mode 100644 index 000000000000..643c93a293ab --- /dev/null +++ b/ide/markdown/src/org/netbeans/modules/markdown/resources/layer.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ide/markdown/src/org/netbeans/modules/markdown/ui/preview/MarkdownEditorKit.java b/ide/markdown/src/org/netbeans/modules/markdown/ui/preview/MarkdownEditorKit.java index e08e2da48a00..0f3d9e6f78cf 100644 --- a/ide/markdown/src/org/netbeans/modules/markdown/ui/preview/MarkdownEditorKit.java +++ b/ide/markdown/src/org/netbeans/modules/markdown/ui/preview/MarkdownEditorKit.java @@ -24,6 +24,8 @@ import javax.swing.text.html.HTMLDocument; import javax.swing.text.html.HTMLEditorKit; import javax.swing.text.html.StyleSheet; +import org.netbeans.modules.editor.settings.storage.api.EditorSettings; +import org.netbeans.modules.markdown.StyleUtils; /** * @@ -51,7 +53,7 @@ public Document createDefaultDocument() { //default style override ss.addStyleSheet(styles); - addCustomStyleRules(ss); + StyleUtils.addNbSyles(ss); HTMLDocument doc = new HTMLDocument(ss); doc.setParser(getParser()); @@ -65,43 +67,4 @@ public ViewFactory getViewFactory() { return viewFactory; } - /** - * Hardcoded styling customization asa a quick fix for improving - * dispaly of markdown previews - * - * Note some css rules are not recognized in Swing - * - * Existing swing html CSS limitations - * - hr no styling - * - code element no padding - * - table no border collapse - * - no nth-child selector - * - * @param ss - */ - private void addCustomStyleRules(StyleSheet ss) { - //body - ss.addRule("body {padding:40px;background-color:white}"); // NOI18N - //headings - ss.addRule("h1 a, h2 a, h3 a, h4 a, h5 a, h6 a{color:black;}"); // NOI18N - ss.addRule("h1 code, h2 code, h3 code, h4 code, h5 code, h6 code {font-size:inherit;}"); // NOI18N - //list - ss.addRule("ul, li ul {margin-left: 20px;}"); // NOI18N - ss.addRule("li {margin-bottom: 3px;padding-left:5px;}"); // NOI18N - - //table - ss.addRule("table {border-spacing:0;}"); // NOI18N - ss.addRule("th, td {border:1px solid rgb(209, 217, 224); padding:10px;}"); // NOI18N - - //code related styling - ss.addRule("code {border-radius: 6px; background-color: rgba(129, 139, 152, 0.12);}"); // NOI18N - ss.addRule("pre {padding:16px; background-color: rgb(246, 248, 250);}"); // NOI18N - ss.addRule("pre code {border-radius:0px; background-color:rgb(246, 248, 250);}"); - - //blockquote - ss.addRule("blockquote {padding: 0 16px; margin: 0px; border-left: 2px solid rgb(209, 217, 224);}"); // NOI18N - ss.addRule("blockquote p { color:rgb(89, 99, 110);}"); // NOI18N - ss.addRule("pre, blockquote {margin-bottom: 10px;}"); // NOI18N - ss.addRule("li blockquote {margin-bottom: 0px;}"); // NOI18N - } } From 120d595515cbb109578b7620842482bc3f8d26dd Mon Sep 17 00:00:00 2001 From: Bogdan Haidu Date: Fri, 6 Mar 2026 11:39:47 +0200 Subject: [PATCH 4/4] - refactor css styling update process - clean unecessary updated files - add flatlack dark font config - fix license issue for coloring preview --- .../nbproject/project.properties | 17 ---- ide/markdown/licenseinfo.xml | 7 +- ide/markdown/nbproject/project.properties | 2 +- .../modules/markdown/Bundle.properties | 2 - .../markdown/MarkdownViewerElement.java | 10 +- .../netbeans/modules/markdown/StyleUtils.java | 92 ++++++++++++------- .../markdown/resources/Bundle.properties | 11 +++ .../resources/{coloring.md => Coloring.md} | 8 +- .../resources/FontAndColors-earth.xml | 34 +++++++ .../resources/FontAndColors-flatlafdark.xml | 34 +++++++ .../modules/markdown/resources/layer.xml | 16 +++- 11 files changed, 174 insertions(+), 59 deletions(-) rename ide/markdown/src/org/netbeans/modules/markdown/resources/{coloring.md => Coloring.md} (90%) create mode 100644 ide/markdown/src/org/netbeans/modules/markdown/resources/FontAndColors-earth.xml create mode 100644 ide/markdown/src/org/netbeans/modules/markdown/resources/FontAndColors-flatlafdark.xml diff --git a/ide/libs.flexmark/nbproject/project.properties b/ide/libs.flexmark/nbproject/project.properties index 5737f6c58233..3eaf3b253be5 100644 --- a/ide/libs.flexmark/nbproject/project.properties +++ b/ide/libs.flexmark/nbproject/project.properties @@ -15,23 +15,6 @@ # specific language governing permissions and limitations # under the License. -file.reference.flexmark-0.64.8.jar=external/flexmark-0.64.8.jar -file.reference.flexmark-ext-anchorlink-0.64.8.jar=external/flexmark-ext-anchorlink-0.64.8.jar -file.reference.flexmark-ext-emoji-0.64.8.jar=external/flexmark-ext-emoji-0.64.8.jar -file.reference.flexmark-ext-gfm-tasklist-0.64.8.jar=external/flexmark-ext-gfm-tasklist-0.64.8.jar -file.reference.flexmark-ext-tables-0.64.8.jar=external/flexmark-ext-tables-0.64.8.jar -file.reference.flexmark-html2md-converter-0.64.8.jar=external/flexmark-html2md-converter-0.64.8.jar -file.reference.flexmark-util-ast-0.64.8.jar=external/flexmark-util-ast-0.64.8.jar -file.reference.flexmark-util-builder-0.64.8.jar=external/flexmark-util-builder-0.64.8.jar -file.reference.flexmark-util-collection-0.64.8.jar=external/flexmark-util-collection-0.64.8.jar -file.reference.flexmark-util-data-0.64.8.jar=external/flexmark-util-data-0.64.8.jar -file.reference.flexmark-util-dependency-0.64.8.jar=external/flexmark-util-dependency-0.64.8.jar -file.reference.flexmark-util-format-0.64.8.jar=external/flexmark-util-format-0.64.8.jar -file.reference.flexmark-util-html-0.64.8.jar=external/flexmark-util-html-0.64.8.jar -file.reference.flexmark-util-misc-0.64.8.jar=external/flexmark-util-misc-0.64.8.jar -file.reference.flexmark-util-sequence-0.64.8.jar=external/flexmark-util-sequence-0.64.8.jar -file.reference.flexmark-util-visitor-0.64.8.jar=external/flexmark-util-visitor-0.64.8.jar -file.reference.jsoup-1.15.4.jar=external/jsoup-1.15.4.jar javac.release=11 javac.compilerargs=-Xlint -Xlint:-serial release.external/flexmark-0.64.8.jar=modules/ext/flexmark-0.64.8.jar diff --git a/ide/markdown/licenseinfo.xml b/ide/markdown/licenseinfo.xml index 0c60cbe82bf3..775ccedd758d 100644 --- a/ide/markdown/licenseinfo.xml +++ b/ide/markdown/licenseinfo.xml @@ -34,5 +34,10 @@ src/org/netbeans/modules/markdown/resources/Template.md - + + + src/org/netbeans/modules/markdown/resources/Coloring.md + + + diff --git a/ide/markdown/nbproject/project.properties b/ide/markdown/nbproject/project.properties index 5137752915a4..f1bd7ebfa963 100644 --- a/ide/markdown/nbproject/project.properties +++ b/ide/markdown/nbproject/project.properties @@ -15,5 +15,5 @@ # specific language governing permissions and limitations # under the License. -javac.source=1.8 +javac.source=17 javac.compilerargs=-Xlint -Xlint:-serial diff --git a/ide/markdown/src/org/netbeans/modules/markdown/Bundle.properties b/ide/markdown/src/org/netbeans/modules/markdown/Bundle.properties index bfaeaa91317e..57a78a2eaa8d 100644 --- a/ide/markdown/src/org/netbeans/modules/markdown/Bundle.properties +++ b/ide/markdown/src/org/netbeans/modules/markdown/Bundle.properties @@ -22,7 +22,6 @@ OpenIDE-Module-Name=Markdown Support OpenIDE-Module-Short-Description=Syntax highlighting for Markdown CSS_DEFAULT=body {padding:40px;}\ -h1 a, h2 a, h3 a, h4 a, h5 a, h6 a{color:black;}\ h1 code, h2 code, h3 code, h4 code, h5 code, h6 code {font-size:inherit;}\ ul, li ul {margin-left: 20px;}\ li {margin-bottom: 3px;padding-left:5px;}\ @@ -32,5 +31,4 @@ code {border-radius: 6px;}\ pre {padding:16px;}\ pre code {border-radius:0px;}\ blockquote {padding: 0 16px; margin: 0px; border-left: 2px solid rgb(209, 217, 224);}\ -blockquote p { color:rgb(89, 99, 110);}\ li blockquote {margin-bottom: 0px;} \ No newline at end of file diff --git a/ide/markdown/src/org/netbeans/modules/markdown/MarkdownViewerElement.java b/ide/markdown/src/org/netbeans/modules/markdown/MarkdownViewerElement.java index 61b75c31192f..f9c8ebe79874 100644 --- a/ide/markdown/src/org/netbeans/modules/markdown/MarkdownViewerElement.java +++ b/ide/markdown/src/org/netbeans/modules/markdown/MarkdownViewerElement.java @@ -144,6 +144,8 @@ public void changedUpdate(DocumentEvent e) { }; private final Task updater = RP.create(MarkdownViewerElement.this::updateView); + //event for Font config update + private volatile boolean fontChanged = false; private final PropertyChangeListener pcl = this::colorProfileChange; private StyledDocument source; @@ -307,7 +309,13 @@ private void linkHandler(HyperlinkEvent evt) { * @param evt */ public void colorProfileChange(PropertyChangeEvent evt) { - if (EditorSettings.PROP_CURRENT_FONT_COLOR_PROFILE.equals(evt.getPropertyName())) { + //TODO check some context + if (!fontChanged && "fontColors".equals(evt.getPropertyName())) { // NOI18N + //not very safe + //fontChanged = true; + } + if (fontChanged || EditorSettings.PROP_CURRENT_FONT_COLOR_PROFILE.equals(evt.getPropertyName())) { + fontChanged = false; viewer.setEditorKit(new MarkdownEditorKit()); updateView(); } diff --git a/ide/markdown/src/org/netbeans/modules/markdown/StyleUtils.java b/ide/markdown/src/org/netbeans/modules/markdown/StyleUtils.java index 7f76240f6199..0fdff16bd77c 100644 --- a/ide/markdown/src/org/netbeans/modules/markdown/StyleUtils.java +++ b/ide/markdown/src/org/netbeans/modules/markdown/StyleUtils.java @@ -19,7 +19,6 @@ package org.netbeans.modules.markdown; import java.awt.Color; -import java.util.Collection; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; @@ -42,39 +41,27 @@ public class StyleUtils { private static final Map fontConfig2tagMapping = new HashMap() { { - put("body", "body"); - put("code", "code"); - put("pre", "pre"); - put("heading1", "h1, h1 a"); - put("heading2", "h2, h2 a"); - put("heading3", "h3, h3 a"); - put("heading4", "h4, h4 a"); - put("heading5", "h5, h5 a"); - put("heading6", "h6, h6 a"); + put("body", "body"); // NOI18N + put("code", "code"); // NOI18N + put("pre", "pre"); // NOI18N + put("blockquote", "blockquote p"); // NOI18N + put("heading1", "h1, h1 a"); // NOI18N + put("heading2", "h2, h2 a"); // NOI18N + put("heading3", "h3, h3 a"); // NOI18N + put("heading4", "h4, h4 a"); // NOI18N + put("heading5", "h5, h5 a"); // NOI18N + put("heading6", "h6, h6 a"); // NOI18N + put("heading6", "h6, h6 a"); // NOI18N } }; public static void addNbSyles(StyleSheet ss) { - String profile = EditorSettings.getDefault().getCurrentFontColorProfile(); - String defaultRules = NbBundle.getMessage(StyleUtils.class, "CSS_DEFAULT"); - ss.addRule(defaultRules); - FontColorSettings fcs = (MimeLookup.getLookup(MimePath.get(MarkdownDataObject.MIME_TYPE)).lookup(FontColorSettings.class)); - AttributeSet defaultAttributes = fcs.getFontColors("default"); // NOI18N - FontColorSettingsFactory fcsf = EditorSettings.getDefault().getFontColorSettings(new String[]{MarkdownDataObject.MIME_TYPE}); - Collection attributes = fcsf.getAllFontColors(profile); - Iterator attributesIt = attributes.iterator(); - while (attributesIt.hasNext()) { - AttributeSet attributeSet = attributesIt.next(); - Enumeration en = attributeSet.getAttributeNames(); - while (en.hasMoreElements()) { - Object key = en.nextElement(); + //main css + appendDefaultMarkdownCssRules(ss); - if (key instanceof StyleConstants) { - addRule(ss, attributeSet, defaultAttributes); - } - } - } + //coloring & font settings + appendColoringCssRulesFromFontConfigs(ss); } public static void addRule(StyleSheet ss, AttributeSet attributeSet, AttributeSet defaultAttributes) { @@ -85,22 +72,21 @@ public static void addRule(StyleSheet ss, AttributeSet attributeSet, AttributeSe return; } cssRule.append(htmlTag); - cssRule.append(" {"); - - cssRule.append(rgbStyling("color", getThemeColor(attributeSet, defaultAttributes, StyleConstants.ColorConstants.Foreground ))); // NOI18N + cssRule.append(" {"); // NOI18N + cssRule.append(rgbStyling("color", getThemeColor(attributeSet, defaultAttributes, StyleConstants.ColorConstants.Foreground))); // NOI18N cssRule.append(rgbStyling("background-color", getThemeColor(attributeSet, defaultAttributes, StyleConstants.ColorConstants.Background))); // NOI18N - cssRule.append("}"); + cssRule.append("}"); // NOI18N ss.addRule(cssRule.toString()); } - public static Color getThemeColor(AttributeSet attributeSet, AttributeSet defaultAttributes, Object constant ) { + public static Color getThemeColor(AttributeSet attributeSet, AttributeSet defaultAttributes, Object constant) { Color color = (Color) attributeSet.getAttribute(constant); if (color == null && defaultAttributes != null) { color = (Color) defaultAttributes.getAttribute(constant); } return color; } - + public static String rgbStyling(String property, Color color) { StringBuilder cssRule = new StringBuilder(); if (color != null) { @@ -113,7 +99,43 @@ public static String rgbStyling(String property, Color color) { cssRule.append(color.getBlue()); cssRule.append(");"); // NOI18N } - + return cssRule.toString(); } + + private static void appendDefaultMarkdownCssRules(StyleSheet ss) { + String defaultRules = NbBundle.getMessage(StyleUtils.class, "CSS_DEFAULT"); // NOI18N + ss.addRule(defaultRules); + } + + private static Iterator loadCustomizedMarkdownFontAttributes() { + String profile = EditorSettings.getDefault().getCurrentFontColorProfile(); + FontColorSettingsFactory fcsf = EditorSettings.getDefault().getFontColorSettings(new String[]{MarkdownDataObject.MIME_TYPE}); + return fcsf.getAllFontColors(profile).iterator(); + } + + private static AttributeSet loadDefaultNbMarkdownFontAttributes() { + FontColorSettings fcs = (MimeLookup.getLookup(MimePath.get(MarkdownDataObject.MIME_TYPE)).lookup(FontColorSettings.class)); + return fcs.getFontColors("default"); // NOI18N + } + + private static void appendColoringCssRulesFromFontConfigs(StyleSheet ss) { + //contains the default / fallback values of fontConfigs + AttributeSet defaultAttributes = loadDefaultNbMarkdownFontAttributes(); + + //contains the full list of fontConfigs but populated only with custom values + Iterator attributesIt = loadCustomizedMarkdownFontAttributes(); + while (attributesIt.hasNext()) { + AttributeSet attributeSet = attributesIt.next(); + Enumeration en = attributeSet.getAttributeNames(); + + while (en.hasMoreElements()) { + Object key = en.nextElement(); + + if (key instanceof StyleConstants) { + addRule(ss, attributeSet, defaultAttributes); + } + } + } + } } diff --git a/ide/markdown/src/org/netbeans/modules/markdown/resources/Bundle.properties b/ide/markdown/src/org/netbeans/modules/markdown/resources/Bundle.properties index d92551e15de7..cbfe1caab011 100644 --- a/ide/markdown/src/org/netbeans/modules/markdown/resources/Bundle.properties +++ b/ide/markdown/src/org/netbeans/modules/markdown/resources/Bundle.properties @@ -16,3 +16,14 @@ # under the License. Editors/text/x-markdown=Markdown + +body = Body +heading1 = H1 +heading2 = H2 +heading3 = H3 +heading4 = H4 +heading5 = H5 +heading6 = H6 + +pre = Code block +code = Inline code \ No newline at end of file diff --git a/ide/markdown/src/org/netbeans/modules/markdown/resources/coloring.md b/ide/markdown/src/org/netbeans/modules/markdown/resources/Coloring.md similarity index 90% rename from ide/markdown/src/org/netbeans/modules/markdown/resources/coloring.md rename to ide/markdown/src/org/netbeans/modules/markdown/resources/Coloring.md index c505d267e199..7d397a0c63d5 100644 --- a/ide/markdown/src/org/netbeans/modules/markdown/resources/coloring.md +++ b/ide/markdown/src/org/netbeans/modules/markdown/resources/Coloring.md @@ -1,4 +1,10 @@ -No preview for the moment + +========================= +``` +COLORING PREVIEW NOT ENABLED +``` +========================= + # Markdown Cheat Sheet (Example File) This is a **generic Markdown template** showcasing essential formatting features. diff --git a/ide/markdown/src/org/netbeans/modules/markdown/resources/FontAndColors-earth.xml b/ide/markdown/src/org/netbeans/modules/markdown/resources/FontAndColors-earth.xml new file mode 100644 index 000000000000..aab01d2809a7 --- /dev/null +++ b/ide/markdown/src/org/netbeans/modules/markdown/resources/FontAndColors-earth.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + diff --git a/ide/markdown/src/org/netbeans/modules/markdown/resources/FontAndColors-flatlafdark.xml b/ide/markdown/src/org/netbeans/modules/markdown/resources/FontAndColors-flatlafdark.xml new file mode 100644 index 000000000000..fe7c8c3bb9ae --- /dev/null +++ b/ide/markdown/src/org/netbeans/modules/markdown/resources/FontAndColors-flatlafdark.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + diff --git a/ide/markdown/src/org/netbeans/modules/markdown/resources/layer.xml b/ide/markdown/src/org/netbeans/modules/markdown/resources/layer.xml index 643c93a293ab..5395cc928587 100644 --- a/ide/markdown/src/org/netbeans/modules/markdown/resources/layer.xml +++ b/ide/markdown/src/org/netbeans/modules/markdown/resources/layer.xml @@ -47,6 +47,20 @@ + + + + + + + + + + + + + + @@ -61,7 +75,7 @@ - +