pretty-print

How to format code in html / css / js/ php

久未见 提交于 2019-11-26 15:38:27
问题 I'm looking for a way to automatically format and color code I write in an HTML document. I know wikipedia does it, for example on the page: http://en.wikipedia.org/wiki/Nested_function I'm sure there are libraries out there to do this, but I can't for the life of me, find one. Does anyone have any suggestions? 回答1: Have a look at the Prettify JavaScript library. It's the one generally used by people (it's the one being used here on SO, for example.) You would use it like this: In your <head>

Printing Java Collections Nicely (toString Doesn&#39;t Return Pretty Output)

对着背影说爱祢 提交于 2019-11-26 15:06:14
I wish to print a Stack<Integer> object as nicely as the Eclipse debugger does (i.e. [1,2,3...] ) but printing it with out = "output:" + stack doesn't return this nice result. Just to clarify, I'm talking about Java's built-in collection so I can't override its toString() . How can I get a nice printable version of the stack? You could convert it to an array and then print that out with Arrays.toString(Object[]) : System.out.println(Arrays.toString(stack.toArray())); String.join(",", yourIterable); (Java 8) tlavarea The MapUtils class offered by the Apache Commons project offers a MapUtils

How do I pretty-print HTML with Nokogiri?

懵懂的女人 提交于 2019-11-26 13:58:14
问题 I wrote a web crawler in Ruby and I'm using Nokogiri::HTML to parse the page. I need to print the page out and while messing around in IRB I noticed a pretty_print method. However it takes a parameter and I can't figure out what it wants. My crawler is caching the HTML of the webpages and writing it to files on my local machine. I would like to "pretty print" the HTML so that it looks nice and properly formatted when I do so. 回答1: By "pretty printing" of HTML page I presume you meant that you

How can I “pretty” format my JSON output in Ruby on Rails?

徘徊边缘 提交于 2019-11-26 13:53:04
I would like my JSON output in Ruby on Rails to be "pretty" or nicely formatted. Right now, I call to_json and my JSON is all on one line. At times this can be difficult to see if there is a problem in the JSON output stream. Is there way to configure or a method to make my JSON "pretty" or nicely formatted in Rails? jpatokal Use the pretty_generate() function, built into later versions of JSON. For example: require 'json' my_object = { :array => [1, 2, 3, { :sample => "hash"} ], :foo => "bar" } puts JSON.pretty_generate(my_object) Which gets you: { "array": [ 1, 2, 3, { "sample": "hash" } ],

Python pretty XML printer with lxml

流过昼夜 提交于 2019-11-26 13:17:50
问题 After reading from an existing file with 'ugly' XML and doing some modifications, pretty printing doesn't work. I've tried etree.write(FILE_NAME, pretty_print=True) . I have the following XML: <testsuites tests="14" failures="0" disabled="0" errors="0" time="0.306" name="AllTests"> <testsuite name="AIR" tests="14" failures="0" disabled="0" errors="0" time="0.306"> .... And I use it like this: tree = etree.parse('original.xml') root = tree.getroot() ... # modifications ... with open(FILE_NAME,

Pretty-printing output from javax.xml.transform.Transformer with only standard java api (Indentation and Doctype positioning)

不羁岁月 提交于 2019-11-26 12:15:59
问题 Using the following simple code: package test; import java.io.*; import javax.xml.transform.*; import javax.xml.transform.stream.*; public class TestOutputKeys { public static void main(String[] args) throws TransformerException { // Instantiate transformer input Source xmlInput = new StreamSource(new StringReader( \"<!-- Document comment --><aaa><bbb/><ccc/></aaa>\")); StreamResult xmlOutput = new StreamResult(new StringWriter()); // Configure transformer Transformer transformer =

Pretty printing XML with javascript

我的未来我决定 提交于 2019-11-26 12:02:55
I have a string that represents a non indented XML that I would like to pretty-print. For example: <root><node/></root> should become: <root> <node/> </root> Syntax highlighting is not a requirement. To tackle the problem I first transform the XML to add carriage returns and white spaces and then use a pre tag to output the XML. To add new lines and white spaces I wrote the following function: function formatXml(xml) { var formatted = ''; var reg = /(>)(<)(\/*)/g; xml = xml.replace(reg, '$1\r\n$2$3'); var pad = 0; jQuery.each(xml.split('\r\n'), function(index, node) { var indent = 0; if (node

NumPy: Pretty print tabular data

青春壹個敷衍的年華 提交于 2019-11-26 11:17:40
问题 I would like to print NumPy tabular array data, so that it looks nice. R and database consoles seem to demonstrate good abilities to do this. However, NumPy\'s built-in printing of tabular arrays looks like garbage: import numpy as np dat_dtype = { \'names\' : (\'column_one\', \'col_two\', \'column_3\'), \'formats\' : (\'i\', \'d\', \'|S12\')} dat = np.zeros(4, dat_dtype) dat[\'column_one\'] = range(4) dat[\'col_two\'] = 10**(-np.arange(4, dtype=\'d\') - 4) dat[\'column_3\'] = \'ABCD\' dat[\

How do I print out a tree structure?

久未见 提交于 2019-11-26 10:26:54
问题 I\'m trying to improve performance in our app. I\'ve got performance information in the form of a tree of calls, with the following node class: public class Node { public string Name; // method name public decimal Time; // time spent in method public List<Node> Children; } I want to print out the tree such that I can see lines between the nodes - something like in this question. What\'s an algorithm I can use in C# for doing that? Edit: Obviously I need to use recursion - but my attempts keep

How do I get Python&#39;s ElementTree to pretty print to an XML file?

一曲冷凌霜 提交于 2019-11-26 09:44:28
问题 Background I am using SQLite to access a database and retrieve the desired information. I\'m using ElementTree in Python version 2.6 to create an XML file with that information. Code import sqlite3 import xml.etree.ElementTree as ET # NOTE: Omitted code where I acccess the database, # pull data, and add elements to the tree tree = ET.ElementTree(root) # Pretty printing to Python shell for testing purposes from xml.dom import minidom print minidom.parseString(ET.tostring(root)).toprettyxml