Author Topic: Paste as HTML without meta data  (Read 1176 times)

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1712
  • Karma: +29/-2
    • View Profile
    • HippoEDIT
HTML Tools: example of script plugin for editing HTML
« on: February 24, 2012, 08:34:39 pm »
This example shows how to extend HippoEDIT with syntax specific functionality. Explicitly create small helpers for HTML editing, and call/access with shortcut, with toolbar button and menu.
More detailed description about api and scripting syntax can be found here and here. In this topic just an example.


Code: Javascript
  1. var nIconLink = Application.RegisterIconString(
  2. 'R0lGODlhEAAQALMAAFVVVcLCwpmZmX5+fu/v79fX12lpaWZmZoyMjOTk5KKiovT09MzMzN3d3f// \
  3. /wAAACH5BAEHAA4ALAAAAAAQABAAAARM0MlJq704680nU6DCSF84BsKiLkKArmyAEAgihKFQ00Mz \
  4. OIgFYUhYIBy9gYFhaB6e0ObSoDgUEonCAWTFahUOAWAMEEjEZHNnzW5bIgA7'
  5. );
  6.  
  7. Application.AddScriptInfo("HTML Tools", "1.0.0.0", "HTML Tools for HippoEDIT", "HippoEDIT", "supportbox@hippoedit.com", "http://www.hippoedit.com");
  8.  
  9. function onInsertLink()
  10. {
  11.         var dialog_template =
  12.         '@<dialog title="Insert Link" resizing="horizontal" modal="false" id="insert_link"> \
  13.            <image> \
  14.                 R0lGODlhMAAwALMAALm5ub29veXl5czMzO7u7tjY2MbGxvb29tzc3P///wAAAAAAAAAAAAAAAAAA \
  15.                 AAAAACH5BAEHAAkALAAAAAAwADAAAAT/MMlJq7046827/1phAEFxgOhFBEDbBkQqJ6trwzNYt0Zx \
  16.                 xznODlCQCH5BzbA4ObpwScvS4nydopPppQoYYCVaDPcbzvha2LLZhR21mJuqN1mFa7jA4OBFEYht \
  17.                 flF7JBM+BlSAX4OHCWcAgUaJX0eMjgF9kl8JCBKWeVyQmp1Pn5k5BHmFpE2mKQcFLCSQngkCBm4t \
  18.                 oSkCsS6Vq1y5QcEAvy8xBDbCOVwDCHO0RgMBAybDNnbRorXYFNqiXHYIwLp03RTAxZrhiDhVV+Yu \
  19.                 dhR5jqkz7ByDAFEHvfMYHM0J4gjgBUcA7slww2gDwnIyfHF4+AUXRFUuLsqgeLBVEn8eJ0Fto9Hr \
  20.                 EaaMI8GUDCQypUps+0y6zFLSo8shKGdK2TdAoc6fQFNEAAA7 \
  21.            </image> \
  22.            <columnbreak/> \
  23.            <group> \
  24.                    <paragraph text="Path:" minwidth="6" style="required" align="left"/> \
  25.                    <edit id="url" cuebanner="Enter here url (required)" autocomplete="url" minwidth="25" required="true"/> \
  26.                    <file_browser filter="All files (*.*)|*.*|HTML Files (*.html)|*.html||" align="right"/> \
  27.            </group> \
  28.            <group> \
  29.                    <paragraph text="Title:" minwidth="6" align="left"/> \
  30.                    <edit id="title" cuebanner="Enter here title" minwidth="25"/> \
  31.            </group> \
  32.            <group uniform="true" align="right|bottom"> \
  33.                    <button title="&amp;OK" returnval="ok" default="true"/> \
  34.                    <button title="&amp;Cancel" returnval="cancel"/> \
  35.            </group> \
  36.         </dialog>@';
  37.        
  38.         var varStorage = CreateStorage();
  39.  
  40.         var sel     = ActiveView.Selection;
  41.         var selText = ActiveDocument.GetText(sel);
  42.         varStorage.write("title", selText);
  43.  
  44.         if ( dialog(dialog_template, varStorage) != 0  )
  45.         {
  46.                 var linkPattern = "<a href=\"" + varStorage.read("url") + "\">" + varStorage.read("title") + "</a>";  
  47.                 ActiveDocument.ReplaceText(sel, linkPattern, HE_ACTION_UNKNOWN);       
  48.         }      
  49. }
  50.  
  51. var vInsertLinkCMD = Application.CreateCommand("HTML.InsertLink", "Insert Link...", "Interactively insert link element into HTML code", nIconLink, onInsertLink);
  52. Application.RegisterCommand(vInsertLinkCMD);
  53.  
  54. ////////////////////////////////////////////////////////////////////////
  55. // Initialize HTML Toolbar
  56. Application.onInitToolbars = function (){
  57.         var MyToolbar = this.GetToolBar("HTML", true);
  58.         MyToolbar.Name = "HTML Tools";
  59.         MyToolbar.AddButton(vInsertLinkCMD);
  60. }
  61.  
  62. ////////////////////////////////////////////////////////////////////////
  63. // Create new main Menu for HTML
  64. Application.onInitMainMenu = function (bUpdate){
  65.         if ( bUpdate == false )
  66.         {
  67.                 var menuHTML = this.InsertSubMenu(this.ItemCount - 4, "HTM&L");
  68.                 if ( menuHTML != null )
  69.                 {
  70.                         menuHTML.AddItem("", vInsertLinkCMD);
  71.                 }
  72.         }
  73. }

For you convenience I have also attached plug-in file.  Just drop it somewhere and than Tools->Execute... After successful execution you should see new menu, toolbar button and command.
Something like this:


And this will be a result:
* html_tools.hejs (3.02 kB - downloaded 7 times.)

Plugin is always reloaded on start-up after execution (using file you point). To disable it, go to Tools->Options->Plugins and uncheck.
To reinitialize, just once more Execute.

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1712
  • Karma: +29/-2
    • View Profile
    • HippoEDIT
Re: HTML Tools: example of script plugin for editing HTML
« Reply #1 on: March 14, 2012, 09:20:08 pm »
I have extended HTML Tools script adding new commands and some optimizations.
Not all stuff is ready, but here I hope for some feedback and help of community :) Especially HTML developers.

New screenshots:

 

Related Topics

  Subject / Started by Replies Last post
0 Replies
401 Views
Last post September 27, 2009, 07:42:57 pm
by Stefan
10 Replies
1395 Views
Last post October 17, 2009, 02:25:36 pm
by alex
10 Replies
1179 Views
Last post August 11, 2010, 07:35:40 pm
by knn
3 Replies
818 Views
Last post February 12, 2011, 04:03:56 pm
by alex
1 Replies
93 Views
Last post March 14, 2012, 09:20:08 pm
by alex