Questions tagged [pretty-print]

Prettyprint (or pretty-print) is the application of any of various stylistic formatting conventions to text, source code, markup, and other similar kinds of content. These formatting conventions usually consist of changes in positioning, spacing, color, contrast, size and similar modifications intended to make the content easier for people to view, read and understand.

1047 questions
277
votes
20 answers

Formatting floats without trailing zeros

How can I format a float so that it doesn't contain trailing zeros? In other words, I want the resulting string to be as short as possible. For example: 3 -> "3" 3. -> "3" 3.0 -> "3" 3.1 -> "3.1" 3.14 -> "3.14" 3.140 -> "3.14"
TarGz
  • 3,319
  • 4
  • 19
  • 11
274
votes
13 answers

JSON.stringify output to div in pretty print way

I JSON.stringify a json object by result = JSON.stringify(message, my_json, 2) The 2 in the argument above is supposed to pretty print the result. It does this if I do something like alert(result). However, I want to output this to the user by…
Alexis
  • 23,545
  • 19
  • 104
  • 143
261
votes
5 answers

How do I get python's pprint to return a string instead of printing?

In other words, what's the sprintf equivalent to pprint?
drue
  • 4,863
  • 6
  • 22
  • 14
234
votes
20 answers

Printing Java Collections Nicely (toString Doesn't Return Pretty Output)

I wish to print a Stack 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…
Elazar Leibovich
  • 32,750
  • 33
  • 122
  • 169
210
votes
11 answers

Convert JSON String to Pretty Print JSON output using Jackson

This is the JSON string I…
arsenal
  • 23,366
  • 85
  • 225
  • 331
197
votes
8 answers

Pretty-Print JSON Data to a File using Python

A project for class involves parsing Twitter JSON data. I'm getting the data and setting it to the file without much trouble, but it's all in one line. This is fine for the data manipulation I'm trying to do, but the file is ridiculously hard to…
Zelbinian
  • 3,221
  • 5
  • 20
  • 23
169
votes
9 answers

How can I get Express to output nicely formatted HTML?

When using Express for Node.js, I noticed that it outputs the HTML code without any newline characters or tabs. Though it may be more efficient to download, it's not very readable during development. How can I get Express to output nicely formatted…
Stephen
  • 7,994
  • 9
  • 44
  • 73
169
votes
22 answers

Pretty printing XML with javascript

I have a string that represents a non indented XML that I would like to pretty-print. For example: should become: Syntax highlighting is not a requirement. To tackle the problem I first transform the…
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
159
votes
16 answers

Pretty-print a Map in Java

I am looking for a nice way to pretty-print a Map. map.toString() gives me: {key1=value1, key2=value2, key3=value3} I want more freedom in my map entry values and am looking for something more like this: key1="value1", key2="value2", key3="value3" I…
space_monkey
  • 1,712
  • 2
  • 11
  • 12
148
votes
5 answers

A command-line HTML pretty-printer: Making messy HTML readable

I'm looking for recommendations for HTML pretty printers which fulfill the following requirements: Takes HTML as input, and then output a nicely formatted/correctly indented but "graphically equivalent" version of the given input HTML. Must support…
knorv
  • 49,059
  • 74
  • 210
  • 294
134
votes
10 answers

How can I beautify JavaScript code using Command Line?

I am writing a batch script in order to beautify JavaScript code. It needs to work on both Windows and Linux. How can I beautify JavaScript code using the command line tools?
grom
  • 15,842
  • 19
  • 64
  • 67
125
votes
20 answers

How to print from GitHub

If I want to print a markdown file from GitHub as it appears on screen, for example: https://github.com/RestKit/RestKit/blob/master/Docs/Object%20Mapping.md Then how can I accomplish that? What code do I need to change in the resulting github html…
pulkitsinghal
  • 3,855
  • 13
  • 45
  • 84
120
votes
6 answers

How to format strings using printf() to get equal length in the output

I have two functions, one which produces messages like Starting initialization... and another which checks return codes and outputs "Ok", "Warning" or "Error". However, the output that is produced is of the different length: Starting…
psihodelia
  • 29,566
  • 35
  • 108
  • 157
118
votes
15 answers

Any way to properly pretty-print OrderedDict?

I like the pprint module in Python. I use it a lot for testing and debugging. I frequently use the width option to make sure the output fits nicely within my terminal window. It has worked fine until they added the new ordered dictionary type in…
Elias Zamaria
  • 96,623
  • 33
  • 114
  • 148
110
votes
30 answers

The simplest way to comma-delimit a list?

What is the clearest way to comma-delimit a list in Java? I know several ways of doing it, but I'm wondering what the best way is (where "best" means clearest and/or shortest, not the most efficient. I have a list and I want to loop over it,…
13ren
  • 11,887
  • 9
  • 47
  • 64
1
2
3
69 70