News for hackers. Stuff that matters.
Re:Hacker News doesn't validate by aston on Tuesday January 06, 2009 @09:33PM (#422850)
pg's stated before he treats HTML as nothing more than object code. If it runs acceptably on all platforms, who cares what it looks like?
Re:Hacker News doesn't validate by ashu on Tuesday January 06, 2009 @11:36PM (#423008)
That (= treating as object code) does not preclude producing validating HTML. In fact, on the contrary, that is the only way (IMHO) one can produce validating HTML - if your HTML all goes through a common piece of code for rendering tags. See AppJet's HTML producing JS functions, for example.
Re:Hacker News doesn't validate by daleharvey on Tuesday January 06, 2009 @10:21PM (#422920)
it would be nice to be able to use an xml parser to screenscrape, i mean, missing alt tags dont really matter, but not having to write silly regexs to strip out the data you need over simple xml queries is a plus
Re:Hacker News doesn't validate by jrockway on Wednesday January 07, 2009 @03:17PM (#423886)
Try cloure-html. It turns invalid HTML into valid XHTML SAX events (which can be made into a DOM with cxml-dom or cxml-stp).

The architecture of closure-html and cxml are really nice, even if you don't use Lisp. You should take a look.

Re:Hacker News doesn't validate by staunch on Tuesday January 06, 2009 @10:34PM (#422933)
Use any decent HTML parser.
Re:Hacker News doesn't validate by daleharvey on Tuesday January 06, 2009 @10:36PM (#422934)
they arent anywhere near as ubiquitous as xml parsers
Re:Hacker News doesn't validate by snprbob86 on Tuesday January 06, 2009 @11:09PM (#422980)
For Python, use BeautifulSoup: http://www.crummy.com/software/BeautifulSoup/

Otherwise, try HTML Tidy: http://tidy.sourceforge.net/

Re:Hacker News doesn't validate by weavejester on Wednesday January 07, 2009 @05:47AM (#423282)
Ian Bicking seems to consider lxml superior to BeautifulSoup: http://blog.ianbicking.org/2008/12/10/lxml-an-underappreciat...
Re:Hacker News doesn't validate by snprbob86 on Wednesday January 07, 2009 @09:35AM (#423440)
Cool! Thanks for this.
Re:Hacker News doesn't validate by eli on Wednesday January 07, 2009 @12:07AM (#423031)
Hpricot for Ruby: https://code.whytheluckystiff.net/hpricot/

But, yeah, Tidy does a darn job of turning just about any HTML into XHTML.

Re:Hacker News doesn't validate by icefox on Wednesday January 07, 2009 @12:07PM (#423635)
Funny story on that. For the Arora browser for a while I was pondering the best way to make a tool to import html bookmarks. I went a handful of different routes, but none of them were that good (I could import all my test data, but I wasn't sure I could input all users data) because of all the different html bookmark files that people generate, but I had an epiphany. I had at my fingertips webkit. So rather then trying to reinvent a bad html parser I just would just let webkit parse it and walk it with javascript.

The code ended up being something like

QWebView view; view.load("file://local/file/foo.html"); print view.mainFrame()->evaluateJavaScript(javascriptCode);

Full source here: http://github.com/Arora/arora/tree/master/tools/htmlToXBel

With QtWebKit working on all platforms and having a really nice api making things like this is a snap and easy to do.

Re:Hacker News doesn't validate by fizx on Tuesday January 06, 2009 @10:59PM (#422969)
libxml2 has an html parser. Everything(ish) has a libxml2 binding. The real PITA about scraping HN is that there's hardly any id/class attributes and you end up with td:nth-child(3).
Re:Hacker News doesn't validate by pxlpshr on Wednesday January 07, 2009 @12:19PM (#423660)
PG is brilliant and everyone has their own methodology, but there are a lot of reasons to not use tables aside from standards. Just because someone gave insight into their method, does not mean it's universal. Horses for courses...

For one, tables are excess bloat... as your site scales, those small kb turn into big bandwidth savings. Two, code uniformity is important when you have multiple people working on an intensive design and efficiency is critical. XHTML/CSS is practically the new table for new developers entering the market.

And three, as we age we get stuck in our ways. Doesn't surprise me PG may prefer tables. It took me 3 years to wean off of them... but the decision was for the better and I would never go back to tables, except for data display. :)

Re:Hacker News doesn't validate by kwamenum86 on Tuesday January 06, 2009 @09:59PM (#422887)
code that does not validate is more lielly to break with browsers updates.
Re:Hacker News doesn't validate by andrewtj on Tuesday January 06, 2009 @10:16PM (#422912)
In my experience preemptive fixes are akin to procrastination when there's no empirical evidence to necessitate the change.
Re:Hacker News doesn't validate by kwamenum86 on Wednesday January 07, 2009 @01:22PM (#423732)
We have web standards to prevent browser bugs. Ironically sticking to standards 100 percent of the time often causes buggy visual display in some browsers. Standards are supposed to make things easier but the browsers have been pretty slow in complying. That does not mean that standards are not a good idea.

The lack of empirical evidence is due to that non-compliance. The same browser sometimes allows non-compliant code and chokes on valid code. This is a coordination game (just like driving on the right side of the road). If everyone complies (developers, browsers, etc.) things work. If enough don't, everything breaks.

Re:Hacker News doesn't validate by michaelneale on Wednesday January 07, 2009 @12:55AM (#423079)
that's an awesome quote - can I borrow it ??
Re:Hacker News doesn't validate by andrewtj on Wednesday January 07, 2009 @06:34AM (#423311)
sure
Re:Hacker News doesn't validate by run4yourlives on Wednesday January 07, 2009 @01:57AM (#423115)
That assumes that there's extra work in coding to standard. In fact, it's quicker to do so.
Re:Hacker News doesn't validate by tomjen on Wednesday January 07, 2009 @02:46AM (#423156)
Really - adding a doctag is faster than not adding it? That seems incorrect to me.
Re:Hacker News doesn't validate by andreyf on Wednesday January 07, 2009 @11:37AM (#423586)
I think gp is talking about the long-run. That is, getting things to render right on all browsers, on all devices, printed, etc.

Have you ever tried printing a thread? It's bearable, not certainly but pretty.

Re:Hacker News doesn't validate by run4yourlives on Wednesday January 07, 2009 @12:20PM (#423664)
That's like saying you don't indent your code blocks because hitting tab is slower than not hitting tab.

The point being that there is a lot more to development than keystrokes.

But let's user your argument anyway: what's faster:

<div id="content">content</div>

or

<table id="content"><tr><td>content</td></tr></table>

Now, lets say I want to move the table text from left to right alignment. While you're mucking around in your code, I pull up the css file and add a line.

Re:Hacker News doesn't validate by eli on Wednesday January 07, 2009 @12:05AM (#423030)
and code that validates is likely to break with certain current browsers :/
Re:Hacker News doesn't validate by kwamenum86 on Wednesday January 07, 2009 @12:28AM (#423048)
good point- but you can always figure out a way to write valid cross-browser code. it's difficult to tell whether or not the effort is worth it because some "broken" code works well in all browsers and there is no reason not to expect this to continue.
Re:Hacker News doesn't validate by Jem on Wednesday January 07, 2009 @05:37AM (#423272)
Really? My valid code doesn't have any problems in current browsers.
Re:Hacker News doesn't validate by eli on Wednesday January 07, 2009 @10:32AM (#423500)
And the hilariously invalid intranet app I built in 1997 doesn't have any problems in current browsers either. What's your point?

I'm not saying it's impossible to write valid code that works (duh). But having code that validates doesn't exempt you from browser bugs and quirks. And sometimes it makes life quite a bit harder.

Re:Hacker News doesn't validate by Jem on Monday January 12, 2009 @04:40AM (#430332)
> What's your point?

That the problem is with your coding. Invalid or not, if you can't make it work properly that's down to you and bugger all to do with validity.

Re:Hacker News doesn't validate by run4yourlives on Wednesday January 07, 2009 @12:41PM (#423689)
That would be a good argument if it were true, but most of those invalid 1997 apps don't work at all in any browser but IE.

An now, they're a nightmare to upgrade.

Re:Hacker News doesn't validate by bradgessler on Wednesday January 07, 2009 @04:01PM (#423950)
HAML templates are object code-ish and those render properly. It is certainly possible to write a chunk of code that maps objects into valid XHTML. Through a style sheet on it and you're done; its not like HN has a complicated page layout.
Re:Hacker News doesn't validate by kleevr on Tuesday January 06, 2009 @10:39PM (#422942)
though I'm sure pg's concept of object code is outpacing-ly more resolute than my own,... I really do think I agree.