Why any thing after <plaintext> is shown as encoded?

56 views Asked by At

Why in this code after <plaintext> every thing is encoded? even </plaintext> or </body>:

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <p>The markup for this is 01</p>
    <plaintext>
        <h1>Main heading goes here</h1>
        <p>First paragraph goes here</p>
        <h2>Sub-heading goes here</h2>
    </plaintext>
    <p>The markup for this is 02</p>
    <h2>test 01</h2>
    <h2>test 02</h2>
</body>
</html>

jsfiddle

1

There are 1 answers

0
Jongware On BEST ANSWER

Because that is what <plaintext> does:

The HTML Plaintext Element () renders everything following the start tag as raw text, without interpreting any HTML. There is no closing tag, since everything after it is considered raw text.

Note: Do not use this element.  This element has been deprecated since HTML 2 and was never implemented by all browsers; even those that did implement it didn't do so consistently. In addition, it is obsoleted in HTML 5; browsers that still accept it may simply treat it as a <pre> element, which still interprets HTML within, even though that's not what you probably want.

(my emphasis)

<plaintext> drinks your HTML milkshake, and everything after it is No Longer HTML.

<plaintext> is a kick in the head for any HTML document; even more, it makes no sense at all in an XHTML document (which mandates that every tag is correctly nested and closed).

There is only one possible use of <plaintext>: to paste a HTML header above any plain text document, without having to check and adjust the contents of said document.

Fun fact

<plaintext> appeared in the very first list of HTML codes as distributed by Tim Berners-Lee in 1992. Note the last paragraph.

Plaintext

This tag indicates that all following text is to be taken litterally, up to the end of the file. Plain text is designed to be represented in the same way as example XMP text, with fixed width character and significant line breaks. Format:

<PLAINTEXT>

This tag allows the rest of a file to be read efficiently without parsing. Its presence is an optimisation. There is no closing tag.

(source: http://www.w3.org/History/19921103-hypertext/hypertext/WWW/MarkUp/Tags.html)