1 package winterwell.markdown.editors;
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;
11 import winterwell.utils.io.FileUtils;
14 public class ExportHTMLAction extends Action {
15 public ExportHTMLAction() {
16 super("Export to HTML");
20 IEditorPart ed = ActionBarContributor.getActiveEditor();
21 if (!(ed instanceof MarkdownEditor)) {
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);