This is an automated email from the ASF dual-hosted git repository.

mbien pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 5d92f5dad6 Included flexmark-ext-gfm-tasklist to support checkbox on 
Markdown Preview
     new 9afb06a2f1 Merge pull request #6401 from moacirrf/ft-markdown-checkbox
5d92f5dad6 is described below

commit 5d92f5dad63c992df3f6061c0c6a2aecfbce4bbf
Author: Moacir da Roza Flores <[email protected]>
AuthorDate: Fri Sep 1 20:33:49 2023 -0300

    Included flexmark-ext-gfm-tasklist to support checkbox on
    Markdown Preview
    
    * Support checkbox on preview
    * A utils class to handle some Html Elements
    * A custom MarkdownEditorKit
    * A MarkdownViewFactory to create custom views for preview.
    * Update dependecy FlexMark library from 1.14 to 1.15.
    
    Fix public-packages declaration to just use subpackages.
    
    Included flexmark-ext-gfm-tasklist-0.62.2.jar to license file.
    
    Removed non necessary utility class.
---
 ide/libs.flexmark/external/binaries-list           |  1 +
 .../external/flexmark-0.62.2-license.txt           |  2 +-
 ide/libs.flexmark/nbproject/project.properties     |  1 +
 ide/libs.flexmark/nbproject/project.xml            |  4 ++
 ide/markdown/nbproject/project.xml                 |  2 +-
 .../modules/markdown/MarkdownViewerElement.java    | 17 +++---
 .../markdown/ui/preview/MarkdownEditorKit.java     | 42 +++++++++++++++
 .../markdown/ui/preview/views/CheckboxView.java    | 48 +++++++++++++++++
 .../ui/preview/views/MarkdownViewFactory.java      | 61 ++++++++++++++++++++++
 9 files changed, 167 insertions(+), 11 deletions(-)

diff --git a/ide/libs.flexmark/external/binaries-list 
b/ide/libs.flexmark/external/binaries-list
index 39492b77ad..326e9e2b77 100644
--- a/ide/libs.flexmark/external/binaries-list
+++ b/ide/libs.flexmark/external/binaries-list
@@ -29,4 +29,5 @@ AE5AFA76A669E06B3A65255C2ED775EDE5CD3EB1 
com.vladsch.flexmark:flexmark-util-depe
 18133DD81887C512E2F56FEB3C14A8A1210F30EA 
com.vladsch.flexmark:flexmark-util-misc:0.62.2
 87AF2803A63B5B07CC42D9C1D98F8ECD4F83FBCC 
com.vladsch.flexmark:flexmark-util-sequence:0.62.2
 CA49BD94860A5CCEDD82BDE96ECE831F16C66FF1 
com.vladsch.flexmark:flexmark-util-visitor:0.62.2
+1C0FD7A70AFAC3A93459E49089E2D1B2BF72E590 
com.vladsch.flexmark:flexmark-ext-gfm-tasklist:0.62.2
 36DA09A8F68484523FA2AAA100399D612B247D67 org.jsoup:jsoup:1.11.3
diff --git a/ide/libs.flexmark/external/flexmark-0.62.2-license.txt 
b/ide/libs.flexmark/external/flexmark-0.62.2-license.txt
index e433355c54..84c2f207e1 100644
--- a/ide/libs.flexmark/external/flexmark-0.62.2-license.txt
+++ b/ide/libs.flexmark/external/flexmark-0.62.2-license.txt
@@ -3,7 +3,7 @@ Version: 0.62.2
 License: BSD-flexmark
 Description: FlexMark library
 Origin: https://github.com/vsch/flexmark-java
-Files: flexmark-0.62.2.jar flexmark-ext-anchorlink-0.62.2.jar 
flexmark-ext-emoji-0.62.2.jar flexmark-ext-tables-0.62.2.jar 
flexmark-html2md-converter-0.62.2.jar flexmark-util-ast-0.62.2.jar 
flexmark-util-builder-0.62.2.jar flexmark-util-collection-0.62.2.jar 
flexmark-util-data-0.62.2.jar flexmark-util-dependency-0.62.2.jar 
flexmark-util-format-0.62.2.jar flexmark-util-html-0.62.2.jar 
flexmark-util-misc-0.62.2.jar flexmark-util-sequence-0.62.2.jar 
flexmark-util-visitor-0.62.2.jar
+Files: flexmark-0.62.2.jar flexmark-ext-anchorlink-0.62.2.jar 
flexmark-ext-emoji-0.62.2.jar flexmark-ext-tables-0.62.2.jar 
flexmark-html2md-converter-0.62.2.jar flexmark-util-ast-0.62.2.jar 
flexmark-util-builder-0.62.2.jar flexmark-util-collection-0.62.2.jar 
flexmark-util-data-0.62.2.jar flexmark-util-dependency-0.62.2.jar 
flexmark-util-format-0.62.2.jar flexmark-util-html-0.62.2.jar 
flexmark-util-misc-0.62.2.jar flexmark-util-sequence-0.62.2.jar 
flexmark-util-visitor-0.62.2.jar flexmark [...]
 
 Copyright (c) 2015-2016, Atlassian Pty Ltd
 All rights reserved.
diff --git a/ide/libs.flexmark/nbproject/project.properties 
b/ide/libs.flexmark/nbproject/project.properties
index df15ddf381..f975b17bb0 100644
--- a/ide/libs.flexmark/nbproject/project.properties
+++ b/ide/libs.flexmark/nbproject/project.properties
@@ -32,4 +32,5 @@ 
release.external/flexmark-util-visitor-0.62.2.jar=modules/ext/flexmark-util-visi
 
release.external/flexmark-ext-emoji-0.62.2.jar=modules/ext/flexmark-ext-emoji-0.62.2.jar
 
release.external/flexmark-ext-anchorlink-0.62.2.jar=modules/ext/flexmark-ext-anchorlink-0.62.2.jar
 
release.external/flexmark-ext-tables-0.62.2.jar=modules/ext/flexmark-ext-tables-0.62.2.jar
+release.external/flexmark-ext-gfm-tasklist-0.62.2.jar=modules/ext/flexmark-ext-gfm-tasklist-0.62.2.jar
 release.external/jsoup-1.11.3.jar=modules/ext/jsoup-1.11.3.jar
diff --git a/ide/libs.flexmark/nbproject/project.xml 
b/ide/libs.flexmark/nbproject/project.xml
index 835019d60a..ea9ccab5d5 100644
--- a/ide/libs.flexmark/nbproject/project.xml
+++ b/ide/libs.flexmark/nbproject/project.xml
@@ -93,6 +93,10 @@
                 
<runtime-relative-path>ext/flexmark-0.62.2.jar</runtime-relative-path>
                 <binary-origin>external/flexmark-0.62.2.jar</binary-origin>
             </class-path-extension>
+            <class-path-extension>
+                
<runtime-relative-path>ext/flexmark-ext-gfm-tasklist-0.62.2.jar</runtime-relative-path>
+                
<binary-origin>external/flexmark-ext-gfm-tasklist-0.62.2.jar</binary-origin>
+            </class-path-extension>
         </data>
     </configuration>
 </project>
diff --git a/ide/markdown/nbproject/project.xml 
b/ide/markdown/nbproject/project.xml
index 4837c76e6c..2634c03dc1 100644
--- a/ide/markdown/nbproject/project.xml
+++ b/ide/markdown/nbproject/project.xml
@@ -47,7 +47,7 @@
                     <build-prerequisite/>
                     <compile-dependency/>
                     <run-dependency>
-                        <specification-version>1.14</specification-version>
+                        <specification-version>1.15</specification-version>
                     </run-dependency>
                 </dependency>
                 <dependency>
diff --git 
a/ide/markdown/src/org/netbeans/modules/markdown/MarkdownViewerElement.java 
b/ide/markdown/src/org/netbeans/modules/markdown/MarkdownViewerElement.java
index 49124b5057..b822a2f735 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.tasklist.TaskListExtension;
 import com.vladsch.flexmark.ext.tables.TablesExtension;
 import com.vladsch.flexmark.html.HtmlRenderer;
 import com.vladsch.flexmark.parser.Parser;
@@ -48,6 +49,7 @@ import javax.swing.text.StyledDocument;
 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.markdown.ui.preview.MarkdownEditorKit;
 import org.openide.awt.HtmlBrowser;
 import org.openide.awt.UndoRedo;
 import org.openide.cookies.EditorCookie;
@@ -91,19 +93,17 @@ public class MarkdownViewerElement implements 
MultiViewElement {
     static final DataHolder OPTIONS = new MutableDataSet()
             .set(Parser.EXTENSIONS, Arrays.asList(
                     AnchorLinkExtension.create(),
-                    TablesExtension.create()
+                    TablesExtension.create(),
+                    TaskListExtension.create()
             ))
-
             .set(HtmlRenderer.INDENT_SIZE, 2)
             .set(HtmlRenderer.RENDER_HEADER_ID, true)
             .set(HtmlRenderer.FENCED_CODE_LANGUAGE_CLASS_PREFIX, "")
-
             // JEditorPane search for the name attribute
             .set(AnchorLinkExtension.ANCHORLINKS_SET_NAME, true)
             .set(AnchorLinkExtension.ANCHORLINKS_SET_ID, false)
             .set(AnchorLinkExtension.ANCHORLINKS_ANCHOR_CLASS, "")
             .set(AnchorLinkExtension.ANCHORLINKS_TEXT_PREFIX, "")
-
             // Make the table generation SWING Friendly
             .set(TablesExtension.COLUMN_SPANS, false)
             .set(TablesExtension.MIN_HEADER_ROWS, 1)
@@ -144,10 +144,10 @@ public class MarkdownViewerElement implements 
MultiViewElement {
     public JComponent getVisualRepresentation() {
         if (component == null) {
             viewer = new JEditorPane();
-            viewer.setContentType("text/html");
+            viewer.setEditorKit(new MarkdownEditorKit());
             viewer.setEditable(false);
             viewer.addHyperlinkListener(this::linkHandler);
-            
+
             JPanel panel = new JPanel(new BorderLayout());
             panel.add(new JScrollPane(viewer), BorderLayout.CENTER);
 
@@ -230,7 +230,6 @@ public class MarkdownViewerElement implements 
MultiViewElement {
         return CloseOperationState.STATE_OK;
     }
 
-
     @Messages("TXT_MarkdownViewerElement_Error=<html>Something happened during 
markdown parsing.")
     public void updateView() {
         if ((source != null) && (viewer != null)) {
@@ -241,14 +240,14 @@ public class MarkdownViewerElement implements 
MultiViewElement {
                 String html = renderer.render(parser.parse(content));
 
                 Reader htmlReader = new StringReader(html);
-                HTMLEditorKit kit = new HTMLEditorKit();
+                HTMLEditorKit kit = (HTMLEditorKit) viewer.getEditorKit();
 
                 HTMLDocument doc = (HTMLDocument) viewer.getDocument();
 
                 // Would be better to create some diff and update the changed 
elemets
                 doc.remove(0, doc.getLength());
                 kit.read(htmlReader, doc, 0);
-                
+
                 viewer.scrollRectToVisible(vis);
 
             } catch (IOException ex) {
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
new file mode 100644
index 0000000000..cf6523fb06
--- /dev/null
+++ 
b/ide/markdown/src/org/netbeans/modules/markdown/ui/preview/MarkdownEditorKit.java
@@ -0,0 +1,42 @@
+/*
+ * 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.ui.preview;
+
+import org.netbeans.modules.markdown.ui.preview.views.MarkdownViewFactory;
+import javax.swing.text.ViewFactory;
+import javax.swing.text.html.HTMLEditorKit;
+
+/**
+ *
+ * @author moacirrf
+ */
+public class MarkdownEditorKit extends HTMLEditorKit {
+
+    private final transient ViewFactory viewFactory;
+
+    public MarkdownEditorKit() {
+        super();
+        this.viewFactory = new MarkdownViewFactory();
+    }
+
+    @Override
+    public ViewFactory getViewFactory() {
+        return viewFactory;
+    }
+}
diff --git 
a/ide/markdown/src/org/netbeans/modules/markdown/ui/preview/views/CheckboxView.java
 
b/ide/markdown/src/org/netbeans/modules/markdown/ui/preview/views/CheckboxView.java
new file mode 100644
index 0000000000..4151576cad
--- /dev/null
+++ 
b/ide/markdown/src/org/netbeans/modules/markdown/ui/preview/views/CheckboxView.java
@@ -0,0 +1,48 @@
+/*
+ * 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.ui.preview.views;
+
+import java.awt.Component;
+import java.awt.event.ActionEvent;
+import javax.swing.BorderFactory;
+import javax.swing.JCheckBox;
+import javax.swing.text.Element;
+import javax.swing.text.html.FormView;
+
+/**
+ *
+ * @author moacirrf
+ */
+public class CheckboxView extends FormView {
+
+    public CheckboxView(Element elem) {
+        super(elem);
+    }
+
+    @Override
+    protected Component createComponent() {
+        Component component = super.createComponent();
+        if (component instanceof JCheckBox) {
+            JCheckBox c = (JCheckBox) component;
+            c.setBorder(BorderFactory.createEmptyBorder(0, 0, -4, 0));
+            c.addActionListener((ActionEvent e) -> 
c.setSelected(!c.isSelected()));
+        }
+        return component;
+    }
+}
diff --git 
a/ide/markdown/src/org/netbeans/modules/markdown/ui/preview/views/MarkdownViewFactory.java
 
b/ide/markdown/src/org/netbeans/modules/markdown/ui/preview/views/MarkdownViewFactory.java
new file mode 100644
index 0000000000..a1c426e88b
--- /dev/null
+++ 
b/ide/markdown/src/org/netbeans/modules/markdown/ui/preview/views/MarkdownViewFactory.java
@@ -0,0 +1,61 @@
+/*
+ * 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.ui.preview.views;
+
+import javax.swing.text.AbstractDocument;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.Element;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.View;
+import javax.swing.text.html.HTML;
+import javax.swing.text.html.HTMLEditorKit;
+
+/**
+ * This class creates Views for a JEditorPane, it receives and HTML element and
+ * you must create the most similar swing component to this html element. For
+ * example a HTML input type checkbox, its a JCheckBox, and image can be a
+ * JLabel and so on.
+ *
+ * @author moacirrf
+ */
+public class MarkdownViewFactory extends HTMLEditorKit.HTMLFactory {
+
+    @Override
+    public View create(Element elem) {
+
+        if (isElementOfTag(elem, HTML.Tag.INPUT)) {
+            return new CheckboxView(elem);
+        }
+
+        return super.create(elem);
+    }
+
+    public boolean isElementOfTag(Element elem, HTML.Tag tag) {
+
+        AttributeSet attrs = elem.getAttributes();
+        Object elementName
+                = attrs.getAttribute(AbstractDocument.ElementNameAttribute);
+        Object o = (elementName != null)
+                ? null : attrs.getAttribute(StyleConstants.NameAttribute);
+        HTML.Tag kind = (HTML.Tag) o;
+
+        return (o instanceof HTML.Tag) && (kind == tag);
+
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to