Are there JavaScript or Ruby versions of HTML tidy?
In Ruby you can parse the HTML in Nokogiri, which will let you check for errors, then have it output the HTML, which will clean up missing closing tags and such. Notice in the following HTML that the title and p tags are not closed correctly, but Nokogiri adds the ending tags.
require 'nokogiri'
html = '<html><head><title>the title</head><body><p>a paragraph</body></html>'
doc = Nokogiri::HTML(html)
puts "Errors found" if (doc.errors.any?)
puts doc.to_html
# >> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
# >> <html>
# >> <head>
# >> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
# >> <title>the title</title>
# >> </head>
# >> <body><p>a paragraph</p></body>
# >> </html>
Alternately you can open a connection to /usr/bin/tidy
and tell it to do the dirty work:
require 'open3'
html = '<html><head><title>the title</head><body><p>a paragraph</body></html>'
stdin, stdout, stderr = Open3.popen3('/usr/bin/tidy -qi')
stdin.puts html
stdin.close
puts stdout.read
# >> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
# >>
# >> <html>
# >> <head>
# >> <meta name="generator" content=
# >> "HTML Tidy for Mac OS X (vers 31 October 2006 - Apple Inc. build 15.3.6), see www.w3.org">
# >>
# >> <title>the title</title>
# >> </head>
# >>
# >> <body>
# >> <p>a paragraph</p>
# >> </body>
# >> </html>
Prevent PHP Tidy from converting style tag data to CDATA
Turn off the output-xhtml
option. The CDATA wrapping is required for XHTML, as CSS can contain unescaped >
characters.
Eclipse - plugin for feeding html syntax?
Take a look at Aptana Studio
There are few versions (2nd, 3rd, 2nd for Ruby support); the 3rd one is still beta. It can be used as it is, or can be installed as plugin for your Eclipse.
IMHO this is the best plugin if you need to use HTML/CSS/JavaScript and do it in Eclipse IDE (the reason does not matter :)
UPDATE: just forgot to mention that it has built-in support for popular JS frameworks (like YUI, jQuery, etc.).
Formatting of dynamically generated HTML - does no one care?
The HAML templating engine was specifically created with the goal of generating properly indented, nested and formatted HTML. There's no reason why other templating engines couldn't do the same.
So, yes, it is just laziness.
Related Topics
How to Get All Arguments of a Function as Single Object Inside That Function
How to Detect When a Youtube Video Finishes Playing
How to Include Newlines in Labels in D3 Charts
How to Reduce JavaScript Object to Only Contain Properties from Interface
Angular 4 Interceptor Retry Requests After Token Refresh
Why Does JavaScript's Eval Need Parentheses to Eval JSON Data
Why Does JavaScript's Eval Need Parentheses to Eval JSON Data
How to Extract Text from a PDF in JavaScript
Converting JSON Format to CSV to Upload Data Table in R to Produce D3 Bubble Chart
Programmatically Select Text in a Contenteditable HTML Element
Sorting a JSON Object in JavaScript
Compare JavaScript Array of Objects to Get Min/Max
Youtube Iframe Player API - Onstatechange Not Firing