Hi,
I’m building a custom RichTextEditor so the user can set a title, subtitle and paragraph in the text. But because the htmlText of the textArea returns depracated html, I wanted to replace it with valid xhtml.
So I have something like this:
<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="20" COLOR="#232323" LETTERSPACING="0" KERNING="1">This should be a h1 title</FONT></P></TEXTFORMAT>
That should be replaced to:
<h1>This should be a h1 title</h1>
But the problem is that I can’t find a way to close the h1 with </h1> without doing it for both </h1> and </h2>
This is the code to replace the start-tags <h1>,<h2> and <p>:
[AS]pattern = /<P.*><FONT.SIZE=“20”.?>/g;
str = str.replace(pattern, “<h1>”);
pattern = /<P.*><FONT.SIZE=“14”.?>/g;
str = str.replace(pattern, “<h2>”);
pattern = /<P ALIGN=“LEFT”>/g;
str = str.replace(pattern, “<p>”);[/AS]
This code closes the tags:
[AS]pattern = /</FONT></P>/g;
str = str.replace(pattern, “</h1>”);
pattern = /</P>/g;
str = str.replace(pattern, “</p>”);[/AS]
But in case I have a title and a subtitle it closes it twice with </h1>. Anyone an idea? I’m looking into the String.search() function but I’m not getting any results…
Thx!