How to Pretty Print HTML to a file, with indentation

I ended up using BeautifulSoup directly. That is something lxml.html.soupparser uses for parsing HTML. BeautifulSoup has a prettify method that does exactly what it says it does. It prettifies the HTML with proper indents and everything. BeautifulSoup will NOT fix the HTML, so broken code, remains broken. But in this case, since the code is … Read more

The simplest way to comma-delimit a list?

Java 8 and later Using StringJoiner class, and forEach method : StringJoiner joiner = new StringJoiner(“,”); list.forEach(item -> joiner.add(item.toString()); return joiner.toString(); Using Stream, and Collectors: return list.stream(). map(Object::toString). collect(Collectors.joining(“,”)).toString(); Java 7 and earlier See also #285523 String delim = “”; for (Item i : list) { sb.append(delim).append(i); delim = “,”; }

Any way to properly pretty-print OrderedDict?

Ever since Python 3.7, Python guarantees that keys in a dictionary will retain their insertion order. (They still don’t behave exactly the same as OrderedDict objects, though, as two dicts a and b can be considered equal a == b even if the order of the keys is different, whereas OrderedDict does check this upon … Read more

How can I beautify JavaScript code using Command Line?

First, pick your favorite Javascript based Pretty Print/Beautifier. I prefer the one at http://jsbeautifier.org/, because it’s what I found first. Downloads its file https://github.com/beautify-web/js-beautify/blob/master/js/lib/beautify.js Second, download and install The Mozilla group’s Java based Javascript engine, Rhino. “Install” is a little bit misleading; Download the zip file, extract everything, place js.jar in your Java classpath (or … Read more

A command-line HTML pretty-printer: Making messy HTML readable [closed]

Have a look at the HTML Tidy Project: http://www.html-tidy.org/ The granddaddy of HTML tools, with support for modern standards. There used to be a fork called tidy-html5 which since became the official thing. Here is its GitHub repository. Tidy is a console application for Mac OS X, Linux, Windows, UNIX, and more. It corrects and … Read more

Pretty printing XML with javascript

From the text of the question I get the impression that a string result is expected, as opposed to an HTML-formatted result. If this is so, the simplest way to achieve this is to process the XML document with the identity transformation and with an <xsl:output indent=”yes”/> instruction: <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”> <xsl:output omit-xml-declaration=”yes” indent=”yes”/> <xsl:template … Read more