<p class="imgcaption">Figure 3: The Grep Dialog</p>
<p>When this script is run you'll see a dialog like the one shown in figure 3.</p>
<h3>Extending Applications with Javascript Plugins</h3>
<p>As its name implies KJSEmbed is not just a tool for writing standalone Javascript
tools, it also provides facilities for extending existing applications, these
facilities being with a KParts plugin for running scripts. The next example
uses the plugin to add a simple HTML-to-text action to Kate, the standard KDE
editor. </p>
<pre>
function html2text( html )
{
var text = html.replace( /&lt;[^&gt;]*&gt;/g, '' );
text = text.replace( /&amp;quot;/g, '&quot;' );
text = text.replace( /&amp;lt;/g, '&lt;' );
text = text.replace( /&amp;amp;/g, '&amp;' );
return text;
}
function text2html( text )
{
var html = text.replace( /&amp;/g,&quot;&amp;amp;&quot;);
html = html.replace( /&quot;/g,&quot;&amp;quot;&quot;);
html = html.replace( /&lt;/g,&quot;&amp;lt;&quot;);
return html;
}
</pre>
<p>The details...</p>
<pre>&lt;!DOCTYPE actionset&gt;<br>&lt;actionset&gt;<br>&lt;header&gt;<br> &lt;name&gt;html2text_actions&lt;/name&gt;<br> &lt;label&gt;HTML To Text Actions&lt;/label&gt;<br> &lt;script type=&quot;js&quot; src=&quot;html2text_plugin.js&quot;&gt;&lt;/script&gt;<br>&lt;/header&gt;<br>&lt;action&gt;<br> &lt;name&gt;html_to_text&lt;/name&gt;<br> &lt;type&gt;KAction&lt;/type&gt;<br> &lt;icons&gt;text&lt;/icons&gt;<br> &lt;label&gt;&lt;text&gt;Convert HTML To Text&lt;/text&gt;&lt;/label&gt;<br> &lt;statustext&gt;Converts the selected text from HTML to text.&lt;/statustext&gt;<br> &lt;script type=&quot;js&quot;&gt;kpart.selectedText = html2text( kpart.selectedText )&lt;/script&gt;<br>&lt;/action&gt;<br>&lt;action&gt;<br> &lt;name&gt;text_to_html&lt;/name&gt;<br> &lt;type&gt;KAction&lt;/type&gt;<br> &lt;icons&gt;html&lt;/icons&gt;<br> &lt;label&gt;&lt;text&gt;Quote For HTML&lt;/text&gt;&lt;/label&gt;<br> &lt;statustext&gt;Quotes the selected text for inclusion in an HTML document.&lt;/statustext&gt;<br> &lt;script type=&quot;js&quot;&gt;kpart.selectedText = text2html( kpart.selectedText )&lt;/script&gt;<br>&lt;/action&gt;<br>&lt;/actionset&gt;<br></pre>