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

PRE tag not considered as a special tag #39

Closed
slandelle opened this issue Oct 7, 2013 · 2 comments
Closed

PRE tag not considered as a special tag #39

slandelle opened this issue Oct 7, 2013 · 2 comments
Assignees
Labels

Comments

@slandelle
Copy link
Contributor

Hi,

I have some html code that contains code blocks within <pre> tags, such as:

<pre>
  new Foo<Bar>() {}
</pre>

Lagarto complains that the <bar> tag is not properly closed, even when setting parseSpecialTagsAsCdata to true.

IMHO, parseSpecialTagsAsCdata should handle this tag.

Moreover, shouldn't parseSpecialTagsAsCdata default to true?

Thanks a lot for this great library, it rocks!
Regards,

Stéphane

@ghost ghost assigned igr Oct 7, 2013
@igr
Copy link
Member

igr commented Oct 7, 2013

Hey Stephane!

Glad you asked this question, as it might be a tricky one 😄

It happens that pre tag is not a special tag after all. Its just a regular tag (except for the new lines; afair). Which means, inner HTML has to be encoded, too! Thats why you see the error/warning.

Try yourself;) Go to the HMTL validator and type:

<!DOCTYPE HTML>
<html><head><title>x</title></head><body>
<pre>new Foo<Bar>(){}</pre>
</body></html>

There will be errors regarding the Bar word - that is interpreted as a tag. Once when you encode the < and >, the validation goes fine.

parseSpecialTagsAsCdata field only affects: style, script and xmp tags (see documentation). And it is set to true by default in HTML5 mode (which is also default); in other modes (XHTML/XML) it is not set as user needs to encode the content of these tags, too.

@slandelle
Copy link
Contributor Author

Oh sorry, you're absolutely right!
The sample I was testing was the home page of a famous framework and I realize that the <Bar> doesn't show up in a browser either.

Sorry for the noise.

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

No branches or pull requests

2 participants