Showing posts with label html notation. Show all posts
Showing posts with label html notation. Show all posts

Thursday, 27 May 2010

HTML Notation Converter

Right, two text boxes on stage, one input:

htmlinput.text = '';
htmlinput.addEventListener(Event.CHANGE,outputhtml);
var htmlCode:Array = ['<','>',"\r",'&','"'];
var htmlNotation:Array = ['&lt;','&gt;',"\n",'&amp;','&quot;'];
function outputhtml(evnt:Event):void {
htmloutput.text = "<pre>";
var str:String = htmlinput.text;
for(var i:uint = 0; i<str.length; i++) {
var char:String = str.charAt(i);
trace(char+' '+str.charCodeAt(i));
var ind:int = htmlCode.indexOf(char);
if(ind == -1) {
htmloutput.appendText(char);
}else{
htmloutput.appendText(htmlNotation[ind]);
}
}
htmloutput.appendText("</pre>");
}


This code was also output using it, and I put the ampersand and quote marks in, because it was great at converting html into html notation, but my actual html notation was getting converted back to html by the blog editor!

It doesn't recognise all linebreaks, but it will pick up on the proper ones, web text is a bit funny like that...

HTML notation conversion

OK... I have checked it and it works.

Apparently you have to surround the whole thing with
<pre>...</pre>
tags to let the editor or whatever know that it is fake html, and you still have to use the notation.

Can you imagine how long it would take me to do that by hand?!? And I'd probably make some mistakes.

So my next task is to make a simple swf to convert my html into html notation, because it really is so handy to have code on this blog, it is so easy for me to find when I need it.
Update:
Here it is...

HTML code in posts

I have a link that puts together all the notation I will probably need to put html on the posts without the editor getting confused.

http://www.blogspottutorial.com/2008/12/html-code-appears-in-posting.html