You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "lkishalmi (via GitHub)" <gi...@apache.org> on 2023/04/27 01:44:09 UTC

[GitHub] [netbeans] lkishalmi opened a new pull request, #5891: A very minimal, but functional viewer for Markdown files.

lkishalmi opened a new pull request, #5891:
URL: https://github.com/apache/netbeans/pull/5891

   Well, I was missing the Preview functionality for Markdown files. I used some plugins a few years ago. I think the plugin portal is down at the moment, so I could not find that. I came up with something very basic. It uses the existing flexmark library we ship with the IDE. I do not think it's bulletproof, but better than nothing. Regarding that the implementation so simple, its a shame I have not done it earlier, so it could be in NB18. 
   
   
   ![image](https://user-images.githubusercontent.com/1381701/234736753-c854cbf4-413e-4cda-91d9-660854e0e96e.png)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


[GitHub] [netbeans] neilcsmith-net commented on pull request #5891: A very minimal, but functional viewer for Markdown files.

Posted by "neilcsmith-net (via GitHub)" <gi...@apache.org>.
neilcsmith-net commented on PR #5891:
URL: https://github.com/apache/netbeans/pull/5891#issuecomment-1525814283

   Looks great!  It's simple, but something to build on if need be.
   
   > BTW aren't the split actions are mixed up? Split vertically would do a horizontal split and split horizontally does a vertical split. Or that is just mixed up in my head?
   
   I think that's just your head! :wink: At least, it's the way I would expect them to be - split horizontally, put side by side, split vertically, put one on top of the other.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


[GitHub] [netbeans] lkishalmi commented on a diff in pull request #5891: A very minimal, but functional viewer for Markdown files.

Posted by "lkishalmi (via GitHub)" <gi...@apache.org>.
lkishalmi commented on code in PR #5891:
URL: https://github.com/apache/netbeans/pull/5891#discussion_r1178680896


##########
ide/markdown/src/org/netbeans/modules/markdown/MarkdownViewerElement.java:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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 com.vladsch.flexmark.html.HtmlRenderer;
+import com.vladsch.flexmark.parser.Parser;
+import com.vladsch.flexmark.util.data.MutableDataSet;
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.swing.Action;
+import javax.swing.JComponent;
+import javax.swing.JEditorPane;
+import javax.swing.JScrollPane;
+import javax.swing.JToolBar;
+import org.netbeans.core.spi.multiview.CloseOperationState;
+import org.netbeans.core.spi.multiview.MultiViewElement;
+import org.netbeans.core.spi.multiview.MultiViewElementCallback;
+import org.openide.awt.UndoRedo;
+import org.openide.filesystems.FileChangeAdapter;
+import org.openide.filesystems.FileChangeListener;
+import org.openide.filesystems.FileEvent;
+import org.openide.filesystems.FileObject;
+import org.openide.util.Lookup;
+import org.openide.util.NbBundle.Messages;
+import org.openide.windows.TopComponent;
+
+/**
+ *
+ * @author lkishalmi
+ */
+@MultiViewElement.Registration(
+        displayName = "#LBL_MarkdownViewer",
+        iconBase = "org/netbeans/modules/markdown/markdown.png",
+        mimeType = "text/x-markdown",
+        persistenceType = TopComponent.PERSISTENCE_NEVER,
+        preferredID = "MarkdownViewer",
+        position = 1100
+)
+@Messages("LBL_MarkdownViewer=Preview")
+public class MarkdownViewerElement implements MultiViewElement {
+
+    private static final Logger LOG = Logger.getLogger(MarkdownViewerElement.class.getName());
+
+    private final MarkdownDataObject dataObject;
+    private transient JToolBar toolbar;
+
+    private transient JComponent component;
+    private transient JEditorPane viewer;
+
+    private final FileChangeListener fcl = new FileChangeAdapter() {
+        @Override
+        public void fileChanged(FileEvent fe) {
+            updateView();
+        }
+    
+    };
+
+    public MarkdownViewerElement(Lookup lookup) {
+        dataObject = lookup.lookup(MarkdownDataObject.class);
+    }
+
+    @Override
+    public JComponent getVisualRepresentation() {
+        if (component == null) {
+            viewer = new JEditorPane();
+            viewer.setContentType("text/html");
+            viewer.setEditable(false);
+            component = new JScrollPane(viewer);
+        }
+        return component;
+    }
+
+    @Override
+    public JComponent getToolbarRepresentation() {
+        if (toolbar == null) {
+            toolbar = new JToolBar();
+        }
+        return toolbar;
+    }
+
+    @Override
+    public Action[] getActions() {
+        return new Action[0];
+    }
+
+    @Override
+    public Lookup getLookup() {
+        return dataObject.getLookup();
+    }
+
+    @Override
+    public void componentOpened() {
+        dataObject.getPrimaryFile().addFileChangeListener(fcl);
+        updateView();
+    }
+
+    @Override
+    public void componentClosed() {
+        dataObject.getPrimaryFile().removeFileChangeListener(fcl);
+    }
+
+    @Override
+    public void componentShowing() {
+    }
+
+    @Override
+    public void componentHidden() {
+    }
+
+    @Override
+    public void componentActivated() {
+    }
+
+    @Override
+    public void componentDeactivated() {
+    }
+
+    @Override
+    public UndoRedo getUndoRedo() {
+        return UndoRedo.NONE;
+    }
+
+    @Override
+    public void setMultiViewCallback(MultiViewElementCallback callback) {
+    }
+
+    @Override
+    public CloseOperationState canCloseElement() {
+        return CloseOperationState.STATE_OK;
+    }
+
+    @Messages("TXT_MarkdownViewerElement_Error=<html>Something happened during markdown parsing.")

Review Comment:
   Good catch. Not anymore.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


[GitHub] [netbeans] mbien commented on a diff in pull request #5891: A very minimal, but functional viewer for Markdown files.

Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #5891:
URL: https://github.com/apache/netbeans/pull/5891#discussion_r1178559265


##########
ide/markdown/src/org/netbeans/modules/markdown/MarkdownViewerElement.java:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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 com.vladsch.flexmark.html.HtmlRenderer;
+import com.vladsch.flexmark.parser.Parser;
+import com.vladsch.flexmark.util.data.MutableDataSet;
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.swing.Action;
+import javax.swing.JComponent;
+import javax.swing.JEditorPane;
+import javax.swing.JScrollPane;
+import javax.swing.JToolBar;
+import org.netbeans.core.spi.multiview.CloseOperationState;
+import org.netbeans.core.spi.multiview.MultiViewElement;
+import org.netbeans.core.spi.multiview.MultiViewElementCallback;
+import org.openide.awt.UndoRedo;
+import org.openide.filesystems.FileChangeAdapter;
+import org.openide.filesystems.FileChangeListener;
+import org.openide.filesystems.FileEvent;
+import org.openide.filesystems.FileObject;
+import org.openide.util.Lookup;
+import org.openide.util.NbBundle.Messages;
+import org.openide.windows.TopComponent;
+
+/**
+ *
+ * @author lkishalmi
+ */
+@MultiViewElement.Registration(
+        displayName = "#LBL_MarkdownViewer",
+        iconBase = "org/netbeans/modules/markdown/markdown.png",
+        mimeType = "text/x-markdown",
+        persistenceType = TopComponent.PERSISTENCE_NEVER,
+        preferredID = "MarkdownViewer",
+        position = 1100
+)
+@Messages("LBL_MarkdownViewer=Preview")
+public class MarkdownViewerElement implements MultiViewElement {
+
+    private static final Logger LOG = Logger.getLogger(MarkdownViewerElement.class.getName());
+
+    private final MarkdownDataObject dataObject;
+    private transient JToolBar toolbar;
+
+    private transient JComponent component;
+    private transient JEditorPane viewer;
+
+    private final FileChangeListener fcl = new FileChangeAdapter() {
+        @Override
+        public void fileChanged(FileEvent fe) {
+            updateView();
+        }
+    
+    };
+
+    public MarkdownViewerElement(Lookup lookup) {
+        dataObject = lookup.lookup(MarkdownDataObject.class);
+    }
+
+    @Override
+    public JComponent getVisualRepresentation() {
+        if (component == null) {
+            viewer = new JEditorPane();
+            viewer.setContentType("text/html");
+            viewer.setEditable(false);
+            component = new JScrollPane(viewer);
+        }
+        return component;
+    }
+
+    @Override
+    public JComponent getToolbarRepresentation() {
+        if (toolbar == null) {
+            toolbar = new JToolBar();
+        }
+        return toolbar;
+    }
+
+    @Override
+    public Action[] getActions() {
+        return new Action[0];
+    }
+
+    @Override
+    public Lookup getLookup() {
+        return dataObject.getLookup();
+    }
+
+    @Override
+    public void componentOpened() {
+        dataObject.getPrimaryFile().addFileChangeListener(fcl);
+        updateView();
+    }
+
+    @Override
+    public void componentClosed() {
+        dataObject.getPrimaryFile().removeFileChangeListener(fcl);
+    }
+
+    @Override
+    public void componentShowing() {
+    }
+
+    @Override
+    public void componentHidden() {
+    }
+
+    @Override
+    public void componentActivated() {
+    }
+
+    @Override
+    public void componentDeactivated() {
+    }
+
+    @Override
+    public UndoRedo getUndoRedo() {
+        return UndoRedo.NONE;
+    }
+
+    @Override
+    public void setMultiViewCallback(MultiViewElementCallback callback) {
+    }
+
+    @Override
+    public CloseOperationState canCloseElement() {
+        return CloseOperationState.STATE_OK;
+    }
+
+    @Messages("TXT_MarkdownViewerElement_Error=<html>Something happened during markdown parsing.")

Review Comment:
   unused?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


[GitHub] [netbeans] johnmanko commented on pull request #5891: A very minimal, but functional viewer for Markdown files.

Posted by "johnmanko (via GitHub)" <gi...@apache.org>.
johnmanko commented on PR #5891:
URL: https://github.com/apache/netbeans/pull/5891#issuecomment-1698372597

   Will this support color themes?   The code blocks should stand out more.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


[GitHub] [netbeans] BradWalker commented on pull request #5891: A very minimal, but functional viewer for Markdown files.

Posted by "BradWalker (via GitHub)" <gi...@apache.org>.
BradWalker commented on PR #5891:
URL: https://github.com/apache/netbeans/pull/5891#issuecomment-1524435194

   I really like it! It's also going to be helpful to me.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


[GitHub] [netbeans] johnmanko commented on pull request #5891: A very minimal, but functional viewer for Markdown files.

Posted by "johnmanko (via GitHub)" <gi...@apache.org>.
johnmanko commented on PR #5891:
URL: https://github.com/apache/netbeans/pull/5891#issuecomment-1701902034

   Thanks @lkishalmi and @Chris2011 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


[GitHub] [netbeans] lkishalmi commented on pull request #5891: A very minimal, but functional viewer for Markdown files.

Posted by "lkishalmi (via GitHub)" <gi...@apache.org>.
lkishalmi commented on PR #5891:
URL: https://github.com/apache/netbeans/pull/5891#issuecomment-1698378640

   > Will this support color themes? The code blocks should stand out more.
   
   Theoretically we can do some basic color/style support adding some CSS. Tough that's really far from my expertise.
   
   I can start a PR though, if anyone would show up doing the real CSS work, I can make sure that those styles are applied in the "Viewer"


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


[GitHub] [netbeans] lkishalmi commented on pull request #5891: A very minimal, but functional viewer for Markdown files.

Posted by "lkishalmi (via GitHub)" <gi...@apache.org>.
lkishalmi commented on PR #5891:
URL: https://github.com/apache/netbeans/pull/5891#issuecomment-1524846738

   BTW aren't the split actions are mixed up? Split vertically would do a horizontal split and split horizontally does a vertical split. Or that is just mixed up in my head?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


[GitHub] [netbeans] Chris2011 commented on pull request #5891: A very minimal, but functional viewer for Markdown files.

Posted by "Chris2011 (via GitHub)" <gi...@apache.org>.
Chris2011 commented on PR #5891:
URL: https://github.com/apache/netbeans/pull/5891#issuecomment-1524941831

   Grest news, thx. You haven't heard of this plugin, right? https://github.com/moacirrf/netbeans-markdown It is great and powerful, but has also some problems while syncing the scroll position etc. I like the idea to have it inside the core.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


[GitHub] [netbeans] lkishalmi merged pull request #5891: A very minimal, but functional viewer for Markdown files.

Posted by "lkishalmi (via GitHub)" <gi...@apache.org>.
lkishalmi merged PR #5891:
URL: https://github.com/apache/netbeans/pull/5891


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


[GitHub] [netbeans] Chris2011 commented on pull request #5891: A very minimal, but functional viewer for Markdown files.

Posted by "Chris2011 (via GitHub)" <gi...@apache.org>.
Chris2011 commented on PR #5891:
URL: https://github.com/apache/netbeans/pull/5891#issuecomment-1698659874

   I can do the css :)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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