]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 package winterwell.markdown.editors;
2
3 import java.io.File;
4
5 import org.eclipse.core.runtime.IPath;
6 import org.eclipse.jface.action.Action;
7 import org.eclipse.ui.IEditorInput;
8 import org.eclipse.ui.IEditorPart;
9 import org.eclipse.ui.IPathEditorInput;
10
11 import winterwell.utils.io.FileUtils;
12
13
14 public class ExportHTMLAction extends Action {
15         public ExportHTMLAction() {
16                 super("Export to HTML");
17         }
18         @Override
19         public void run() {
20                 IEditorPart ed = ActionBarContributor.getActiveEditor();
21                 if (!(ed instanceof MarkdownEditor)) {
22                         return;
23                 }
24                 MarkdownEditor editor = (MarkdownEditor) ed;
25                 IEditorInput i = editor.getEditorInput();
26                 if (i instanceof IPathEditorInput) {
27                         IPathEditorInput input = (IPathEditorInput) i;
28                         IPath path = input.getPath();
29                         path = path.removeFileExtension();
30                         path = path.addFileExtension("html");
31                         File file = path.toFile();
32                         String html = editor.getMarkdownPage().html();
33                         FileUtils.write(file, html);
34                 }
35         }
36
37 }