http://qs321.pair.com?node_id=328127

I've made several minor improvements to the HTML nesting enforcement code based on the testing done so far. Thanks go to the few who I saw "complain," especially ysth. (:

First, note that P is no longer a block tag as far as PerlMonks html nesting is concerned (because people often don't close a P tag and that shouldn't prevent earlier tags from being closed).

The other improvements mostly have to do with how corrections are displayed. Below is my attempt at documenting the htmlerror reporting levels. With luck, the SiteDocClan will improve these into a PM doc node (along with the previous announcement).

So there are two new settings in User Settings. And pretty soon the htmlnest option will go away (it will become the default behavior that can only be disabled by adding ;htmlnest=0 to a URL).

I also took the opportunity to move all of the Nodelet Settings out of the over-full User Settings and clean it up slightly.

HTML error reporting levels

Reporting levels summary

  • Level 0 shows invalid/unapproved HTML tags as plain text.
  • Level 1 also shows non-trivial closing HTML tags that had to be inserted (as grey text).
  • Level 2 also shows invalid/unapproved attributes of approved HTML tags (enclosed in the approved tag; all as grey text).
  • Level 3 also shows non-</p> closing HTML tags that were ignored (as grey text with a line drawn through it).
  • Level 4 also shows trivial closing HTML tags that were ignored or inserted (as grey text; ignored tags have a line drawn through them). Trivial tags are </p> and non-nesting tags inserted other than at the endof the HTML being filtered.

Reporting levels details

No matter what htmlerror reporting is set to, any unrecognized, invalid, or unapproved tags simply have their opening < changed to &lt; so that the tag becomes visible as text (see the More HTML escaping announcement).

When you have htmlerror reporting set to 4 (the maximum), nearly all other corrections made to the HTML will also be made visible, but in a grey font:

  • Any approved closing tags that get ignored in order to enforce proper nesting of tags will be made visible inside of <font color="#808080" class="htmlignored"> tags.

    The default PerlMonks CSS includes font.htmlignored { text-decoration: line-through; } which means the grey text will have a line drawn through it as if <strike> tags had been used (unless your browser does not support CSS). The strike-out allows you to distinguish them from inserted closing tags (and you can use CSS to customize their appearance).

  • Any closing tags that have to be inserted in order to enforce proper nesting of tags will also be displayed, but inside of <font color="#808080" class="htmlinserted"> tags.
  • Any unrecognized, invalid, or unapproved attributes in an approved tag will be displayed inside angle brackets with the tag name. All of this will be inside of <font color="#808080" class="htmlattrib"> tags.

    For example, if IMG is an approved tag with approved attributes of ALT, HEIGHT, and WIDTH, then HTML of <Img ALT=purdy align="top" oops> will be changed to <img alt='purdy' /><font color="#808080" class="htmlattrib">&lt;img align="top" oops></font> so you'll see "<img align="top" oops>" displayed after the image. These are the only non-closing tags that will be displayed in grey.

This level (4) of htmlerror reporting is rather obnoxious and is reserved for when you are composing your own nodes or temporarily request it by adding ;htmlerror=4 to a PerlMonks URL.

If you lower the htmlerror reporting level to 3, then inserted and ignored </p> tags are not displayed. Neither are closing tags that were inserted to close a non-nesting tag other than at the end of the HTML being filtered.

For example, if you have an HTML table that is missing all of its </tr>, </th>, and </td> tags, then these will be inserted but not be displayed (as long as the </table> is not missing).

Level 3 omits showing these most common lapses (that are harmless unless you consider strict compliance to newer HTML standards as a goal in itself) but shows nearly all other mistakes.

Level 2 omits showing ignored closing tags. So it shows non-trivial inserted closing tags (descibed in the next paragraph) and ignored attributes.

Level 1 omits showing ignored attributes. This means that it only shows when tags had to be inserted to close an unclosed or misnested tag (but never shows non-nesting tags unless they were inserted at the end of the filtered HTML, and never shows </p>).

Level 0 (the default) just fixes nesting errors but doesn't display any of them.

User settings

In user settings, you can select between htmlerror reporting levels of 0, 1, 2, or 3 to be used when you view nodes at PerlMonks. You can temporarily select any reporting level (including 4) by appending ;htmlerror=4 (for example) to any PerlMonks URL.1

Note that using an error reporting level of 3 will show you harmless "errors" so you shouldn't select this unless you can deal with seeing a lot of "mistakes" without becoming obnoxious in pointing them out to others.

When you start composing a new node, for thefirst preview you can select between htmlerror reporting levels 3 and 4 (the default choice is also controlled in user settings and defaults to 3). For previews after the first, you can pick any reporting level via a form element on the preview page.

[ The patches to Preview are a bit complicated and haven't been finished. At the time of this writing, the first preview uses your 'preview' level of error reporting and there is no form element for adjusting the level while previewing. ]

1 You can't select 4 as your default error reporting level (except for when previewing your own nodes) because it reports harmless "errors" that we expect to be made often by many members and we don't want to hear complaints about such.

- tye