Eclipse | htmlSave Eclipse | Contact | Blog
JSEditor | htmlSave | GDSearch | Eclipse Automation

   
htmlSave
  • Main
  • Download
  •    
    Eclipse Links:
  • Eclipse.org
  • Eclipse plug-in Central
  •    

    htmlSave - Save Any Eclipse Editor as HTML

    Often I have wanted to save Java or other languages as html. There are several tools online that does this, but many are commercial and they are cumbersome to use (you often have to cut and paste the java into a webpage).

    So I figured, Eclipse has the style information needed, why not just extract it and generate HTML directly from Eclipse editors. This plug-in adds a simple action on the file menu to save the active text editor as HTML:

    The HTML is stored in a file and also in the clipboard. You can cancel the save file action and the HTML will still be stored in the clipboard. It will use your exact settings including font settings, formatting and colors. Here are some examples of HTML save:

    JavaScript:

    for (var i = 0 ; i < 10 ; i++) {
      
    var x = "";

      
    if (i > 5) {
         
    "sadsda".toString();
         x.toString();
      }
    }

    Java:

    package com.my.htmlsave.internal.editors;
    /*
     *   --------------------------------
     *             H t m l S a v e
     *                         ------------------------------------------
     *   ( c ) 2 0 0 5    -   M o r t e n   H .   M o e l l e r 
     *   A l l    R i g h t s    R e s e r v e d
     *
     *  Permission to copy, use and distribute this code and plug-in, free of charge, for
     *  non-commercial and commercial purposes. This plug-in is distributed under the MPL
     *  license (Mozilla Public License)
     *
     *  Get updates, news and other exiting plugins at http://eclipse.moelleryoung.com/
     * 
     */


    import org.eclipse.jface.text.source.SourceViewer;
    import org.eclipse.swt.custom.StyledText;
    import org.eclipse.ui.IEditorPart;

    import com.my.htmlsave.IStructuredTextFinder;

    /**
     
    * @author Morten Moeller 
     
    */
    public class JSEditor implements IStructuredTextFinder {

        
    /**
         
    * Called when JSEditor is active. It takes the current editor and
         
    * finds the StyledText widget in it and returns it to the html
         
    * generation part.
         
    * 
         
    * @param part The active editor part.
         
    * @return the styled text editor for 
         
    */
        
    public StyledText findStyledText(IEditorPart part) {
            
    com.my.jseditor.editor.JSEditor ed = (com.my.jseditor.editor.JSEditor) part; 
            
    SourceViewer viewer = ed.getJSSourceViewer();
            
    return viewer.getTextWidget();
        
    }
    }

    How to make your editor work with htmlSave:

    The plug-in can work with any text editor in Eclipse, but it needs to know how to get a hold of the StyledText widget in it. This is done by using an extension point HtmlSave.sourceViewerFinder. An example of one of one of these extensions is the java class exampled above.

    Version 1.1 of htmlSave has gotten a little "smarter" and works with more editors than before, but it still might not be able to find the style information needed. Also, if you extend IAdaptable and return the StyledText widget when asked for it, that works as well.

    Known Problems:

    Some StyledText widgets doesn't set text attributes into the editor but uses a listening system instead (for example, all StructuredEditors from WTP uses this method). Due to access restrictions to these methods, this plug-in cannot get the coloring information out of these editors.

    © 2004-2006 Morten Moeller