Package winterwell.markdown.editors

Source Code of winterwell.markdown.editors.ExportHTMLAction

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);
    }
  }

}
TOP

Related Classes of winterwell.markdown.editors.ExportHTMLAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.