
Frustrated at the inability to instantly post up code snippets without Blogger corrupting a great deal of it,
I've created this Flash application to help convert code snippets of any kind into valid presentable XHTML, preserving tab indentations.
Originally planning it to be a simple code-and-run application, I attempted customizing it more and more as i debugged and discovered more neccessities. After a whole day's work, this is the end result.
Downloadable at http://parallax-engine.110mb.com/CodeConverter.zip.
It works for all kinds of code, be it PHP, XHTML itself, XML, MySQL, C++, Perl, etc.
That is because it removes all opening and closing <> angle brackets, as well as turn all whitespace, and tabs into , and newlines into <br />
You can customise how many Spaces = A single Tab. Alternatively, you can just specify it to use the <pre> tag to preserve whitespace instead.
Comes with a HTML preview for checking the Tab to Space conversion, as well as specify border color, text color and background color of the code snippet. Comes with automatic CSS scroll-bar for small page widths.
Generates XHTML Transitional 1.1, using CSS 2.0, with clear comment markers. The only reason it fails to be XHTML Strict 1.1 is because of all the original code snippet that the w3c code verifier mistakens as invalid XHTML. Heck sometimes the verifier even deems it NOT XHTML but HTML 4.0!!
Here's an example code snippet, of the Actionscript code used to run the application, created using the application itself.
/*
* This work is licensed under the Creative Commons
* Attribution-Share Alike 3.0 License. To view a copy
* of this license, visit
* http://creativecommons.org/licenses/by-sa/3.0/
* or send a letter to Creative Commons, 171 Second
* Street, Suite 300, San Francisco, California, 94105,
* USA.
* Copyright 2007, Cardin Lee
*/
_root.buttony.onRelease = function()
{
var body:String = "";
var front:String = "";
var back:String = "";
if(input.text == null || borderColor == null ||
bgColor == null)
return;
body = input.text;
body = Replace(body, "<", "<");
body = Replace(body, ">", ">");
front = "<div style='border: 1px " + borderColor.text
+ " solid; background-color: " + bgColor.text
+ "; text-align:left; color: " + textColor.text
+ "; overflow-y: auto; overflow-x: auto;"
+ "border-style: solid double; border-width: 1px 4px;" +
"margin: 15px 10px; padding: 5px 20px;'>" + newline;
back = newline + "</div>";
if(convertWhitespace.selected == true)
{
var noOfSpaces:String = "";
for(i=1;i<=parseInt(tabSpace.text);i++)
noOfSpaces += " ";
body = Replace(body, "\t", noOfSpaces);
body = Replace(body, " ", " ");
}else
{
front = "<pre>" + newline + front;
back += newline + "</pre>";
}
final = front + body + back;
final = "<!---------------Code Starts here--------------->" +
newline + final + newline +
"<!---------------Code Ends here--------------->";
final = Replace(final, "\n", "<br />\n");
_global.final = final;
output.text = final;
};
/*
* Credit, and probably copyright too, goes to
* mrand01 of Actionscript.org forums for
* coming up with such an ingenious function!!
*/
function Replace(block:String, find:String, replace:String):String {
return block.split(find).join(replace);
}

This
work is licensed under a
Creative Commons Attribution-Share Alike 3.0 License.
I hope this has turned out useful. It certainly would prove to be a useful obfuscator, lolz, the HTML version is very cryptic.
![]()
Konjiki no Gash Bell rocks!! Don't say it ain't.
1. Konjiki no Gash Bell OP3 [Mienai Tsubasa] - Tanimoto Takayashi
2. Bad Day - David Powter
3. Bleach OP6 [Alones] - Aqua Timerz

No comments:
Post a Comment