]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/winterwell.markdown/src/winterwell/markdown/editors/ExportHTMLAction.java
migrated to svn revision 33108
[simantics/platform.git] / bundles / winterwell.markdown / src / winterwell / markdown / editors / ExportHTMLAction.java
diff --git a/bundles/winterwell.markdown/src/winterwell/markdown/editors/ExportHTMLAction.java b/bundles/winterwell.markdown/src/winterwell/markdown/editors/ExportHTMLAction.java
new file mode 100644 (file)
index 0000000..3c9d26e
--- /dev/null
@@ -0,0 +1,37 @@
+package winterwell.markdown.editors;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jface.action.Action;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IPathEditorInput;
+
+import winterwell.utils.io.FileUtils;
+
+
+public class ExportHTMLAction extends Action {
+       public ExportHTMLAction() {
+               super("Export to HTML");
+       }
+       @Override
+       public void run() {
+               IEditorPart ed = ActionBarContributor.getActiveEditor();
+               if (!(ed instanceof MarkdownEditor)) {
+                       return;
+               }
+               MarkdownEditor editor = (MarkdownEditor) ed;
+               IEditorInput i = editor.getEditorInput();
+               if (i instanceof IPathEditorInput) {
+                       IPathEditorInput input = (IPathEditorInput) i;
+                       IPath path = input.getPath();
+                       path = path.removeFileExtension();
+                       path = path.addFileExtension("html");
+                       File file = path.toFile();
+                       String html = editor.getMarkdownPage().html();
+                       FileUtils.write(file, html);
+               }
+       }
+
+}