Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Nokogiri messing with my a tag
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Daniel Jabbour  
View profile   Translate to Translated (View Original)
 More options May 29 2012, 6:38 am
From: Daniel Jabbour <d...@inigral.com>
Date: Tue, 29 May 2012 03:38:39 -0700 (PDT)
Local: Tues, May 29 2012 6:38 am
Subject: Nokogiri messing with my a tag
Hi all-

So I'm running an HTML fragment through nokogiri, and I'm getting some
odd behavior. My fragment is a little non-standard, HTML wise, but I'm
confused by what's going on, and wondering if you can help explain
(and surpress) the behavior I'm seeing.

Basically, I've got a fragment, which I'm running through
Nokogiri::HTML.fragment(<fragment>). The fragment contains an a tag,
around a table (ex <a ...><table>...</table></a>). However, when I run
the fragment through nokogiri and to_s it, it rewrite the a tag so it
no longer surrounds the table (ex <a...></a><table>...</table>).

So basically:

1) Why is it doing this?
2) How can I stop this behavior?

Any insight would be appreciated!

Thanks kindly,
Daniel


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Dalessio  
View profile   Translate to Translated (View Original)
 More options May 29 2012, 7:27 am
From: Mike Dalessio <mike.dales...@gmail.com>
Date: Tue, 29 May 2012 07:27:30 -0400
Local: Tues, May 29 2012 7:27 am
Subject: Re: [nokogiri-talk] Nokogiri messing with my a tag

Greetings!

Nokogiri attempts to "fix" broken HTML. This is a feature. It uses libxml2
(or, if you're on JRuby, xerces instead) to do this; in order to support
many of the HTML-specific features, Nokogiri needs the parsed document to
be compliant HTML.

Tables within an anchor are, as far as I know, illegal HTML. Here's a
sample script:

#! /usr/bin/env ruby

require 'rubygems'
require 'nokogiri'

puts Nokogiri::HTML::Document.parse("<html><body><a href='http://foo.com/bar
'></a></body></html>").to_html
# <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "
http://www.w3.org/TR/REC-html40/loose.dtd">
# <html><body><a href="http://foo.com/bar"></a></body></html>

puts Nokogiri::HTML::Document.parse("<html><body><a href='http://foo.com/bar
'><table><tr><td>foo</td></tr></table></a></body></html>").to_html
# <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "
http://www.w3.org/TR/REC-html40/loose.dtd">
# <html><body>
# <a href="http://foo.com/bar"></a><table><tr><td>foo</td></tr></table>
# </body></html>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »