Преглед изворни кода

add command and context menu item for opening markdown editor

markellekelly пре 5 година
родитељ
комит
de74911a07

+ 1 - 0
packages/markdownviewer-extension/package.json

@@ -38,6 +38,7 @@
   "dependencies": {
     "@jupyterlab/application": "^2.0.2",
     "@jupyterlab/apputils": "^2.0.2",
+    "@jupyterlab/coreutils": "^4.0.2",
     "@jupyterlab/markdownviewer": "^2.0.2",
     "@jupyterlab/rendermime": "^2.0.2",
     "@jupyterlab/settingregistry": "^2.0.1"

+ 32 - 0
packages/markdownviewer-extension/src/index.ts

@@ -23,11 +23,14 @@ import {
 
 import { ISettingRegistry } from '@jupyterlab/settingregistry';
 
+import { PathExt } from '@jupyterlab/coreutils';
+
 /**
  * The command IDs used by the markdownviewer plugin.
  */
 namespace CommandIDs {
   export const markdownPreview = 'markdownviewer:open';
+  export const markdownEditor = 'markdownviewer:edit';
 }
 
 /**
@@ -142,6 +145,35 @@ function activate(
     }
   });
 
+  commands.addCommand(CommandIDs.markdownEditor, {
+    execute: () => {
+      let widget = tracker.currentWidget;
+      if (!widget) {
+        return;
+      }
+      let path = widget.context.path;
+      return commands.execute('docmanager:open', {
+        path,
+        factory: 'Editor',
+        options: {
+          mode: 'split-right'
+        }
+      });
+    },
+    isVisible: () => {
+      let widget = tracker.currentWidget;
+      return (
+        (widget && PathExt.extname(widget.context.path) === '.md') || false
+      );
+    },
+    label: 'Show Markdown Editor'
+  });
+
+  app.contextMenu.addItem({
+    command: CommandIDs.markdownEditor,
+    selector: '.jp-RenderedMarkdown'
+  });
+
   return tracker;
 }
 

+ 3 - 0
packages/markdownviewer-extension/tsconfig.json

@@ -12,6 +12,9 @@
     {
       "path": "../apputils"
     },
+    {
+      "path": "../coreutils"
+    },
     {
       "path": "../markdownviewer"
     },