diff --git a/ide/libs.flexmark/external/binaries-list b/ide/libs.flexmark/external/binaries-list index 39492b77ad4b..326e9e2b77d4 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 e433355c5403..84c2f207e1fe 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-ext-gfm-tasklist-0.62.2.jar 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 df15ddf381ba..f975b17bb0c1 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 835019d60a32..ea9ccab5d577 100644 --- a/ide/libs.flexmark/nbproject/project.xml +++ b/ide/libs.flexmark/nbproject/project.xml @@ -93,6 +93,10 @@ ext/flexmark-0.62.2.jar external/flexmark-0.62.2.jar + + ext/flexmark-ext-gfm-tasklist-0.62.2.jar + external/flexmark-ext-gfm-tasklist-0.62.2.jar + diff --git a/ide/markdown/nbproject/project.xml b/ide/markdown/nbproject/project.xml index 4837c76e6c30..2634c03dc1fd 100644 --- a/ide/markdown/nbproject/project.xml +++ b/ide/markdown/nbproject/project.xml @@ -47,7 +47,7 @@ - 1.14 + 1.15 diff --git a/ide/markdown/src/org/netbeans/modules/markdown/MarkdownViewerElement.java b/ide/markdown/src/org/netbeans/modules/markdown/MarkdownViewerElement.java index 49124b50571b..b822a2f7356e 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 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 MarkdownViewerElement(Lookup lookup) { 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 CloseOperationState canCloseElement() { return CloseOperationState.STATE_OK; } - @Messages("TXT_MarkdownViewerElement_Error=Something happened during markdown parsing.") public void updateView() { if ((source != null) && (viewer != null)) { @@ -241,14 +240,14 @@ public void updateView() { 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 000000000000..cf6523fb06f5 --- /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 000000000000..4151576cad0a --- /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 000000000000..a1c426e88b99 --- /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); + + } +}