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

Nokogiri adds id attribute with XHTML doctype #562

Closed
TeamIguana opened this issue Nov 4, 2011 · 2 comments
Closed

Nokogiri adds id attribute with XHTML doctype #562

TeamIguana opened this issue Nov 4, 2011 · 2 comments

Comments

@TeamIguana
Copy link

Hi,
we have found a strange issue in Nokogiri (latest version).

Using this code:

html = Nokogiri::XML::Builder.new do |html|
      html.doc.create_internal_subset(
          'html',
          '-//W3C//DTD XHTML 1.0 Transitional//EN',
          'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'
      )
      html.html {
        html.body {
          html.a(:href=>'url', :name=>'name')
        }
      }
    end
    p html.doc.to_s

the resulting HTML will be:

<?xml version=\"1.0\"?>
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<body>
<a href=\"url\" name=\"name\" id=\"name\"></a>
</body>
</html>

as you can see, the anchor has an additional id attribute that was not given.

However, if we remove the doctype definition it doesn't get added.

How come?

Thanks,
Team Iguana

@flavorjones
Copy link
Member

Because, apparently, libxml2 is that good.

http://www.w3.org/TR/xhtml1/#h-4.10

@morenocarullo
Copy link

Oh, well, awesome :) Thanks!

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

No branches or pull requests

3 participants