"Tidy and GeSHi webservices"


Sometime ago I spent a good amount of time playing with Wez Furlong PHPScript to merge PHP functionalities directly into ASP pages. Although it really can be done, I couldn't feel comfortable enough with the stability of the final application. In fact, the merge between PHP and other ASP languages (VBScript, Javascript, Ruby, Perl and Python) in the same script caused the application to work only in odd requests and not in even ones. Plus it was triggering processing errors in the server. This is incredibly strange and clearly shows that the Active Script port of PHP is flawed. It works fine for .wsc and other command lines things but not plays well with ASP.

Since PHP has a huge community which create really good things, it's interesting to get the benefits of their work in other environments that doesn't run the language. Two notable examples of the good things available in PHP are GeSHi, an incredible code highlighting extension that currently work with over than 130 languages, and Tidy, a nice extension to wrap and indent your XML and HTML. As we can't live without them, I've built the webservices for them both.


Although PHP Tidy isn't the only implementation of HTML Tidy it's a very updated one and is the one I've always used, so I trust in it. Tidy webservice is available at http://zend.lojcomm.com.br/tidy/ and here's a ASP/Javascript example of using it:

<%@ language="Javascript" %>

var code = "<html><head><title>Does this Tidy Webservice works?</title></head><body><h1><i>It works!</u></h2></body></html>";

var Tidy = new ActiveXObject("MSSOAP.SoapClient30");
Tidy.clientProperty("ServerHTTPRequest") = true;

Response.write("<h1>Tidy WebService is running Tidy release " + Tidy.version() + "</h1>");
Response.write("<h2>Tidy.go return</h2>");
Response.write("<pre><code>" + printer_friendly(Tidy.go(code, '{"output-xhtml":true, "indent":true, "indent-spaces":4}')) + "</code></pre>");
Response.write("<h2>Tidy.getHtml return</h2>");
Response.write("<pre><code>" + printer_friendly(Tidy.getHtml(code, '{"output-xhtml":true, "indent":true, "indent-spaces":4}')) + "</code></pre>");
Response.write("<h2>Tidy.getHead return</h2>");
Response.write("<pre><code>" + printer_friendly(Tidy.getHead(code, '{"output-xhtml":true, "indent":true, "indent-spaces":4}')) + "</code></pre>");
Response.write("<h2>Tidy.getBody return</h2>");
Response.write("<pre><code>" + printer_friendly(Tidy.getBody(code, '{"output-xhtml":true, "indent":true, "indent-spaces":4}')) + "</code></pre>");

Tidy = null;

function printer_friendly(code) {
    return code.replace(/</g, "&lt;");



GeSHi is the real one guilt for me to start this quest. I love it deeply and use it everywhere (yes, this blog is using it!). GeSHi webservice is available at http://zend.lojcomm.com.br/geshi/ and here's a ASP/Javascript example of using it:

<%@ language="Javascript" %>

var code = [
"    <head>",
"        <title>Does this GeSHi Webservice works?</title>",
"    </head>",
"    <body>",
"        <h1>It works!</h1>",
"    </body>",

var lang = "html4strict";

var GeSHi = new ActiveXObject("MSSOAP.SoapClient30");
GeSHi.clientProperty("ServerHTTPRequest") = true;

Response.write("<h1>GeSHi WebService is running GeSHi v" + GeSHi.version() + "</h1>");
Response.write("<h2>Available languages</h2>");
Response.write("<p>" + GeSHi.languages() + "</p>");
Response.write("<h2>Testing highlight method</h2>");
Response.write(GeSHi.highlight(code, lang, true));

GeSHi = null;



Well, thats it! I really hope those webservices become useful for others than myself. They are very useful and powerful tools that any programmer should, and now have, access to.