Previous Thread
Next Thread
Print Thread
Rate Thread
#222601 08/19/2002 6:04 PM
Joined: Apr 2002
Posts: 1,768
Addict
Addict
Offline
Joined: Apr 2002
Posts: 1,768
The color markup tag translates its closing tag to </font color>. Is this standards-compliant?

Sponsored Links
joeuser #222602 08/19/2002 6:13 PM
Joined: Mar 2000
Posts: 21,079
Likes: 3
I type Like navaho
I type Like navaho
Joined: Mar 2000
Posts: 21,079
Likes: 3
I don't think so... would need to do a test page and check

uno momento por favor


- Allen wavey
- What Drives You?
Joined: Mar 2000
Posts: 21,079
Likes: 3
I type Like navaho
I type Like navaho
Joined: Mar 2000
Posts: 21,079
Likes: 3


- Allen wavey
- What Drives You?
Joined: Apr 2002
Posts: 1,768
Addict
Addict
Offline
Joined: Apr 2002
Posts: 1,768
So should that be considered a bug?

joeuser #222605 08/19/2002 6:21 PM
Joined: Mar 2000
Posts: 21,079
Likes: 3
I type Like navaho
I type Like navaho
Joined: Mar 2000
Posts: 21,079
Likes: 3
technically yes, as the current closing tag really isn't compliant to any html standard


- Allen wavey
- What Drives You?
Sponsored Links
Joined: Apr 2002
Posts: 1,768
Addict
Addict
Offline
Joined: Apr 2002
Posts: 1,768
Thanks

joeuser #222607 08/19/2002 6:38 PM
Joined: Jun 2001
Posts: 3,273
That 70's Guy
That 70's Guy
Offline
Joined: Jun 2001
Posts: 3,273
posted by Dave_L:
So should that be considered a bug?



Actually that's a "designed flaw"... lol This was the way Rick was able to deal with the new color markup code.

Perhaps one can still simply replace the </font color> tags with </font> tags before displaying so that they are compliant?

sjsaunders #222608 08/19/2002 6:44 PM
Joined: Apr 2002
Posts: 1,768
Addict
Addict
Offline
Joined: Apr 2002
Posts: 1,768
That sounds like it would work, except that the translation would have to be done every time a post is displayed, which seems inefficient.

A couple of other choices:

Use the method employed by UBB.classic, where the opening and closing tags are translated with a single regex.

Use <!--color--></font> in place of </font color>. I haven't thought this through, so I'm not sure if it would work.

sjsaunders #222609 08/19/2002 6:46 PM
Joined: May 1999
Posts: 1,715
Addict
Addict
Joined: May 1999
Posts: 1,715
[]
Actually that's a "designed flaw"... lol This was the way Rick was able to deal with the new color markup code.

Perhaps one can still simply replace the </font color> tags with </font> tags before displaying so that they are compliant?


Yes, it should be possible. I've been thinking of adding this to the markuphack since there are even more tags that aren't really xhtml compliant in the same way.

c0bra #222610 08/19/2002 6:50 PM
Joined: Mar 2000
Posts: 21,079
Likes: 3
I type Like navaho
I type Like navaho
Joined: Mar 2000
Posts: 21,079
Likes: 3
why wouldn't a plain </font> work? You are only closing the opening <font color= tag


- Allen wavey
- What Drives You?
Sponsored Links
joeuser #222611 08/19/2002 6:56 PM
Joined: May 1999
Posts: 1,715
Addict
Addict
Joined: May 1999
Posts: 1,715
That sounds like a better idea to have the html comment in front of the closing font tag, and I don't see why it shouldn't work.

Joined: Apr 2002
Posts: 1,768
Addict
Addict
Offline
Joined: Apr 2002
Posts: 1,768
I don't think that would work, because there may be other </font> tags that don't correspond to the color markups. (Unless the UBB.classic method were used.)

Joined: May 1999
Posts: 1,715
Addict
Addict
Joined: May 1999
Posts: 1,715
Other markup tags also have the </font> tag so the undo_markup function won't be able to distinguish which one is used for the color tag.

c0bra #222614 08/21/2002 3:53 AM
Joined: Aug 2002
Posts: 15
Newbie
Newbie
Offline
Joined: Aug 2002
Posts: 15
posted by Gardener:
Other markup tags also have the </font> tag so the undo_markup function won't be able to distinguish which one is used for the color tag.


undo_markup could easily tell which closing font tags are used for color tags because they are the ones that follow a font tag with a
color attribute. I haven't seen the latest markup code but this is the way to do it (with perl):

code:

$Body =~ s/\[$lang{'COLOR_RED'}\](.*?)\[\/$lang{'COLOR_RED'}\]/<font color=red>$1<\/font>/ig; # do
$Body =~ s/<font color=red>(.*?)<\/font>/\[$lang{'COLOR_RED'}\]$1\[\/$lang{'COLOR_RED'}\]/ig; # undo



jjski #222615 08/21/2002 9:22 AM
Joined: May 1999
Posts: 1,715
Addict
Addict
Joined: May 1999
Posts: 1,715
Won't work.

Well, it will, but start nesting tags and it will break. That's the reason the start and end font tag is replaced separately and the reason that the </font> has the extra info so that it differs from other </font> tags.

c0bra #222616 08/21/2002 10:21 AM
Joined: Apr 2002
Posts: 1,768
Addict
Addict
Offline
Joined: Apr 2002
Posts: 1,768
Actually, mod_perl's post describes the method used by UBB.classic that I referred to earlier. Nested tags are handled properly if you loop over the regex replacement operations. Each loop iteration handles one layer of nesting.

joeuser #222617 08/21/2002 10:52 AM
Joined: May 1999
Posts: 1,715
Addict
Addict
Joined: May 1999
Posts: 1,715
Granted, with added code, the code would work. =] Sort of, at least. There would still be problems with extra tags inside the color tag that would also use the </font> right? Because that would match first.

c0bra #222618 08/21/2002 11:01 AM
Joined: Apr 2002
Posts: 1,768
Addict
Addict
Offline
Joined: Apr 2002
Posts: 1,768
I'm not sure what you mean. Could you provide an example?

joeuser #222619 08/21/2002 11:41 AM
Joined: May 1999
Posts: 1,715
Addict
Addict
Joined: May 1999
Posts: 1,715
More tags than the color-tag could generate the </font> end tag, and when parsing the color tag those tags would match as well.

If these tags were used:
[font:courier] Red courier, size 5 [/font]

And it would create the following html:
<font style="courier"><font color="red"><font size="5"> Red courier, size 5 </font></font></font>

Then the regexp would parse the code like this:
[font:courier] Red courier, size 5 [/font]

Because the regex would match the first occurance of </font>. In the above example, the tags are just nested wrong, but it could match other code which would break things even worse. Like </font> which is inside the quote-tag if I'm not mistaken.

c0bra #222620 08/21/2002 12:24 PM
Joined: Apr 2002
Posts: 1,768
Addict
Addict
Offline
Joined: Apr 2002
Posts: 1,768
That wouldn't happen.

The code I use in my font hack for UBB.classic looks like this:

my $match = 1;
while($match != 0) {
$match = 0;
$match++ if $text =~ s~(<font (.+?)>)(.+?)(</font>)~\[font $2\]$3\[/font\]~is;
}

Here's how it works:

Initially: <font style="courier"><font color="red"><font size="5"> Red courier, size 5 </font></font></font>

After iteration 1: <font style="courier"><font color="red">[font size="5"] Red courier, size 5 [/font]</font></font>

After iteration 2: <font style="courier">[font color="red"][font size="5"] Red courier, size 5 [/font][/font]</font>

After iteration 3: [font style="courier"][font color="red"][font size="5"] Red courier, size 5 [/font][/font][/font]

joeuser #222621 08/21/2002 2:38 PM
Joined: May 1999
Posts: 1,715
Addict
Addict
Joined: May 1999
Posts: 1,715
I still can't see how the regex can now which font closing tag it should parse?

Maybe my example was a bad one, since you could merge them into one markup tag like you have. But that wasn't the point. The point being that if different markups both have the </font> the regex will have no way of knowing which one is the one that it should match to. Some amazing things can be done with regexes, but magic isn't one of them. =]

Testing your code shows that the following happens:
Initially:
<font style="courier"><font color="red"><font size="5"> Red courier, size 5 </font></font></font>

After iteration 1:
[font style="courier"]<font color="red"><font size="5"> Red courier, size 5 [/font]</font></font>

After iteration 2:
[font style="courier"][font color="red"]<font size="5"> Red courier, size 5 [/font][/font]</font>

After iteration 3:
[font style="courier"][font color="red"][font size="5"] Red courier, size 5 [/font][/font][/font]

In this case it doesn't matter that much of course, but it shows that the replace is done with the first possible match. If the </font> tag is part of something else, it will break, and it could potentially screw up the nesting as well.

c0bra #222622 08/21/2002 2:57 PM
Joined: Apr 2002
Posts: 1,768
Addict
Addict
Offline
Joined: Apr 2002
Posts: 1,768
Hmmmmmm, you're right, that code does behave as you describe.

I did some fairly complex tests for that hack, and couldn't break it, but maybe I didn't find the right test case.

joeuser #222623 08/21/2002 3:15 PM
Joined: Jun 2001
Posts: 3,273
That 70's Guy
That 70's Guy
Offline
Joined: Jun 2001
Posts: 3,273
Pages that display posts, such as showflat.php could have the </font color> tag converted to </font> to remain standards compliant.

Just prior to this:

$postrow[$i]['Body'] = $Body;

You could use this:

$Body = str_replace("</font color>","</font>",$Body);

Then the browser would recieve compliant code for viewing and custom tags could remain for editing and other such purposes.


Am I missing something with all of this? I think I'm understanding that the main goal is to have the html that is displayed be standards compliant. How the html is handled on the backend prior to display shouldn't make a difference. (IMHO)

sjsaunders #222624 08/21/2002 3:32 PM
Joined: Apr 2002
Posts: 1,768
Addict
Addict
Offline
Joined: Apr 2002
Posts: 1,768
I'd prefer to use <!--color--></font> instead of </font color>. I think it's simpler to make the posts that are stored in the database correct HTML. Then you don't have to worry about special conversions whenever you want to display them.

sjsaunders #222625 08/21/2002 3:33 PM
Joined: May 1999
Posts: 1,715
Addict
Addict
Joined: May 1999
Posts: 1,715
That's what we've all said as well, but then we went on about discussing if we could have the non-compliant html removed completely.

It would be nice to not have to do that extra replace for the color tag (and the others that I have in the markuphack), but it works.

joeuser #222626 08/21/2002 3:55 PM
Joined: May 1999
Posts: 1,715
Addict
Addict
Joined: May 1999
Posts: 1,715
True, it would be nice if the correct html was in the database as well. And the html comment should work perfectly OK.

Here's the code for this if anyone wants it, do the following in ubbt.inc.php:
Find this line:
code:

$matches[0][$i] = preg_replace("/\[\/{$ubbt_lang['COLOR']}\]/","</font color>",$matches[0][$i]);


Change it to this:
code:

$matches[0][$i] = preg_replace("/\[\/{$ubbt_lang['COLOR']}\]/","<!-- color --></font>",$matches[0][$i]);


Find this line:
code:

$Body = preg_replace("/\[\/{$ubbt_lang['COLOR']}\]/","</font color>",$Body);


Change it to this:
code:

$Body = preg_replace("/\[\/{$ubbt_lang['COLOR']}\]/","<!-- color --></font>",$Body);


Find this line:
code:

$Body = preg_replace("/<\/font color>/i","[/{$ubbt_lang['COLOR']}]",$Body);


And change it to this:
code:

$Body = preg_replace("/<!-- color --><\/font>/i","[/{$ubbt_lang['COLOR']}]",$Body);



But after this is done, the color markup won't be parsed correctly when changing posts done with the old way. But I guess it should work by adding the given lines instead of replacing the old line, that way even old posts should be parsed correctly during editing. Haven't tested it though.

c0bra #222627 08/21/2002 4:13 PM
Joined: Apr 2002
Posts: 1,768
Addict
Addict
Offline
Joined: Apr 2002
Posts: 1,768
Not meaning to be too picky, but before this gets "standardized", do you think <!--color--> (no spaces) would be better than <!-- color -->?

joeuser #222628 08/21/2002 5:01 PM
Joined: May 1999
Posts: 1,715
Addict
Addict
Joined: May 1999
Posts: 1,715
Don't know, I always have a space before/after the --, I think some ancient browser broke if this wasn't the case. Not sure though, but I just do it by habit, removing the spaces should probably be OK and might be better for the parsing.

Also, only the code in the undo_markup should be added instead of replaced. Thus making sure that old posts are editable (is that a word? =]), but all new posts use the new markup.

c0bra #222629 08/22/2002 3:20 PM
Joined: Aug 2002
Posts: 15
Newbie
Newbie
Offline
Joined: Aug 2002
Posts: 15
I don't mind being wrong when it sparks such a useful discussion.

I solved this problem by disabling color markup since it clashes with stylesheets, and discourages those who like to distinguish themselves by posting in all violet text. Crude but effective.

jjski #222630 08/22/2002 4:59 PM
Joined: May 1999
Posts: 1,715
Addict
Addict
Joined: May 1999
Posts: 1,715
That's one way of fixing the problem of course. =] If my users would start setting the color of all the text in their posts and change font styles etc I would definetely remove the function. But at the moment it's only used in signatures, or to highlight some small bits of text. But before I'd remove it completely I'd try to convince users that are overusing those markups to stop.


Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
hatter
hatter
USA
Posts: 69
Joined: January 2001
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20221218)