Htmlify
HTML
Try this: (<a href='http://yoursite.com'>http://yoursite.com</a>.) if not, then <br/>ask Jimmy B <[email protected]?subject=MyProblem> <br/>the FTP link is <a href='ftp://mysite.com/dofuss/'>ftp://mysite.com/dofuss/</a>. Did you<br/>see this <a href='http://technews.org/news/wires.html?ref=wett&skin=rat%20fur'>technews.org/news/wires.html?ref=wett&skin=rat%20fur</a>?<br/> <br/>
<input type=button value=htmlify id=htmlify />
///////////// Show and tell //////////////<br/>
Test Text
<br/>
<textarea id='test' rows='5' cols='60'>
Try this: (http://yoursite.com.) if not, then
ask Jimmy B <[email protected]?subject=MyProblem>
the FTP link is ftp://mysite.com/dofuss/. Did you
see this technews.org/news/wires.html?ref=wett&skin=rat%20fur?
</textarea>
<br/><br/>
Raw HTML
<br/>
<textarea id='raw' rows='5' cols='90'>
</textarea>
<br/><br/>
<b>Browser View</b>
<br/>
<div id='Browser_View'>
</div>
<br/>
<h2 style= 'margin-left: 2%; width: 50%; font-family: Verdana; font-size: 1.2em'>Notes:</h2>
<p style= 'margin-left: 4%; width: 50%; font-family: Verdana; font-size: 0.9em';>
Use your browser's View Source function, copy all and paste into a text editor.
Save it as <b>htmlify_reference.html</b> and then as htmlify-1.html for your working copy.
JavaScript can be maddening - a slight mistake anywhere can result in nothing working.
Make sure you have a working version to use as a return point.
<br/><br/>
By all means improve on this project but please post your improvements in this thread.
<br/><br/>
There is no restriction on any legitimate use of this material. Feel free to spread it
around.
<br/><br/>
John<br/>
</p>
JavaScript
var test = document.getElementById("test");
document.getElementById("htmlify").onclick = function (){
htmlview(test.value);
};
function htmlview($text)
{
///////////// Show and tell //////////////
htmlversion = htmlify($text); // Convert the Test Text to HTML
raw.value = ""; // Clear the Raw HTML box
raw.value = htmlversion; // Show the raw HTML from this pass
Browser_View.innerHTML = raw.value; // Show as a browser would see it.
}
function htmlify($text)
{
var tlnk = new Array; //Create an array to hold the potential links
var hlnk = new Array; //Create an array to hold the HTML translation
// First, translate special characters to HTML
$text = spchrs2html($text);
// Loop through the clear text
var i = 0;
for (i=0;i<4;i++) // Set ;i<20; to a reasonable limit here
{
// Get a potential link and mark where it came from
$text = $text.replace(/(\S+\.\S+)/,"<"+i+">"); // look for dots that are surrounded by non-whitespace characters
tlnk[i] = RegExp.$1;
} // EOLoop
ac = i;
//?** too many loops - need a break **
// Loop through the array of potential links and make replacements
for (i=0;i<ac;i++)
{
// If this is a number, (e.g. 6.4sec; $5.00 etc.) OR too short; restore original and skip it
if (tlnk[i].search(/\d\.\d/)>-1 || tlnk[i].length <5) // Search for digit.digit OR len < 5 in this potential link
{
$text = $text.replace("<"+i+">", tlnk[i]);
}
else
{
// Make this URL into a real link - move brackets and punctuation outside of the anchor tag
htm = makelink(tlnk[i]);
$text = $text.replace("<"+i+">", htm);
}
}
// Now put the breaks on
$text = $text.replace(/\n/g,"<br/>");
// And deal with multiple spaces
$text = $text.replace(/\ \ /g," ");
// And any other specials
$text = $text.replace(/"/g,""");
$text = $text.replace(/\$/g,"$");
return $text;
}
function makelink(txt) // Make a real link from this potential link
{
txt = html2spchrs(txt); // Undo...