Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow <div> inside <pre> #479

Closed
blat opened this issue Jan 8, 2017 · 8 comments
Closed

Allow <div> inside <pre> #479

blat opened this issue Jan 8, 2017 · 8 comments

Comments

@blat
Copy link

blat commented Jan 8, 2017

Hi!

I have an issue with some HTML containing syntax highlighted code. My <pre> tags contains <span> and <div>, but... Tidy doesn't allow <div> inside a <pre> :(

For example, input HTML:

<pre>one<div>two</div>three</pre>

Tidy output:

<pre>one</pre>
<div>two</div>
<pre>three</pre>

The result is totally different!

FYI, in error buffer:

line 1 column 1 - Warning: missing </pre> before <div>
line 1 column 17 - Warning: inserting implicit <pre>
@geoffmcl
Copy link
Contributor

geoffmcl commented Jan 8, 2017

@blat thanks for the issue...

Have not had time to fully research why, but the W3C validator will also issue an error on

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="generator" content=
"HTML Tidy for HTML5 for Windows version 5.3.12">
<title>Issue #479-2</title>
</head>
<body>
<pre>one<div>two</div>three</pre>
</body>
</html>

Saying: Error: Element div not allowed as child of element pre in this context., so this agrees with tidy...

The question is, is your sample valid html?

Look forward to further comments...

Regards, geoff.

@geoffmcl geoffmcl added this to the 5.3 milestone Jan 8, 2017
@blat
Copy link
Author

blat commented Jan 8, 2017

Yes, it's not valid according W3C but it's supported by all browsers, and lot of tools generate <pre> tags which contain <div> and <span> to render colorized code...

I have found an old report about this: https://sourceforge.net/p/tidy/bugs/805/

@geoffmcl
Copy link
Contributor

geoffmcl commented Jan 8, 2017

@blat, thanks for the old link... as I re-read and remembered, this debate was not solved then...

Yes, solely in the interests of generating a html that renders like the original, I think tidy could have an option for this... What to call it?

tidy --allow-invalid-html yes, hmmm, maybe not ;=))
tidy --rendering-priority yes, I can maybe see this...

Of course tidy should still warn about the invalid html, and whine about have been told to break html rules, in preference for maintaining rendering equivalence... but this seems hard to do... do not know if I am for or against this...

Or, alternatively, is there a way re-do the html, such that it conformed, and retains the rendering by browsers?

Certainly look forward to ideas, code, patches, PR to do this, either as an option, or changed output... thanks...

@geoffmcl
Copy link
Contributor

Since we are about to release a 5.4, and presently no conclusion on what should, could be done here moving it out to next 5.5... thanks...

@geoffmcl geoffmcl modified the milestones: 5.5, 5.3 Feb 27, 2017
HarrisonXi added a commit to HarrisonXi/HarrisonXi.github.io that referenced this issue Mar 30, 2017
@geoffmcl
Copy link
Contributor

Since no further comments in quite some time, closing this...

Free free to re-open, or file a new issue... thanks...

@HarrisonXi
Copy link

Tidy 5.6.0 still cannot work for this on Mac.

Test:

<pre class="a"><div>b</div></pre>

Result:

<pre class="a"></pre>
<div>
  b
</div>

@geoffmcl
Copy link
Contributor

@HarrisonXi thanks for your comment...

Yes, am aware current Tidy will still fix this invalid html... and read no arguments here that tidy should accept this...

Of course, we understand most browsers will not care, and maybe render it as the user wants to see, but that in itself is not an argument for tidy to break W3C recomendations... And it is agreed that tidy's fix may be rendered differently...

Was going to try to find more W3C references on this, but seems https://www.w3.org/ is temporarily down, returning 503... but will try to remember this, and do some more research later...

What I am seeking are specific W3C references on allowing a <div> inside a <pre>... please add pointers if you find any... and look forward to more feedback... thanks...

Until then still feel this should remain closed... sorry...

@balthisar
Copy link
Member

I regard Mozilla MDN as a reliable source in addition to WHATWG and W3C, and they say only phrasing content is allowed inside a pre element, and this does not include div.

Tidy isn't just a linter; it's meant to prevent bad HTML, including that generated by non-conforming tools.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants