Re: Consider adding content(html) to display html source

On Sun, Feb 19, 2012 at 9:03 PM, Charles Pritchard <chuck@jumis.com> wrote:
> A CSS generated and replaced content semantic, something like content(html)
> could be helpful with the <code> tag as well as @contentEditable.
> The idea is for innerHTML to be made visible to the user.
>
> Examples:
> <code><p>I am abusing the code tag</p></code>
> <div contentEditable><em>I know basic html</em></div>
>
> Something in CSS would it easier to flip on and off HTML source code
> examples.
>
> Something more heavy could display syntax highlighting, if it's not being
> set to a string.
> code { content: html(); }

I'm with Daniel.  This is a semantic abuse.  Your document contains
HTML code, but you're trying to display it as text.

This is fundamentally limited in the case of HTML, since you're
triggering HTML parsing and there are limitations on what you can
nest.  It's also very easily confusing, as it has to rely on
serializing the DOM, not displaying the original bytes sent down the
wire (to do so would be a layering violation), so you'd frequently
display something *different* than what is actually displayed in your
source.

Using it in concert with contenteditable would be extra-confusing,
even if it worked exactly as you intended, for the reasons listed
above - you'd get code changing underneath you constantly as it gets
parsed into a DOM and then reserialized.  (I don't think it can
possibly work like you want, though.)

If you want to manipulate some code as text, you should either encode
it as text by escaping the five important characters, or lobby for the
reintroduction of <xmp>.  (I asked for this before; search the HTMLWG
bugzilla for it.)

~TJ

Received on Tuesday, 28 February 2012 00:25:43 UTC