author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Tue, 18 Dec 2018 13:06:21 +0200 | |
changeset 2305 | 2d52dea2eee3 |
parent 2285 | 41b2a3652b35 |
permissions | -rw-r--r-- |
1334
9bf0d5a1f0cf
Include common header with quick links.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1326
diff
changeset
|
1 |
.. -*- coding: utf-8; -*- |
1209 | 2 |
|
3 |
=========================== |
|
4 |
Pretty print source code. |
|
5 |
=========================== |
|
6 |
.. contents:: |
|
1905
fba288d59662
Include only local subsections into TOC. This prevent duplication of
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
7 |
:local: |
1209 | 8 |
|
1326
8aac6cb8518d
About pretty printing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1323
diff
changeset
|
9 |
About pretty printing. |
8aac6cb8518d
About pretty printing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1323
diff
changeset
|
10 |
====================== |
8aac6cb8518d
About pretty printing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1323
diff
changeset
|
11 |
|
1209 | 12 |
Code formatter, beautifier, pretty printer. |
13 |
||
2096 | 14 |
http://en.wikipedia.org/wiki/Pretty-printer |
15 |
Wiki article on pretty printing. |
|
1326
8aac6cb8518d
About pretty printing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1323
diff
changeset
|
16 |
|
2096 | 17 |
json |
1209 | 18 |
==== |
19 |
||
2097
614569553a08
Pretty print json with jq.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2096
diff
changeset
|
20 |
With ``jq`` (available in Debian/Cygwin):: |
614569553a08
Pretty print json with jq.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2096
diff
changeset
|
21 |
|
614569553a08
Pretty print json with jq.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2096
diff
changeset
|
22 |
$ jq $FILE |
614569553a08
Pretty print json with jq.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2096
diff
changeset
|
23 |
$ curl -s http://.../... | jq |
614569553a08
Pretty print json with jq.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2096
diff
changeset
|
24 |
|
614569553a08
Pretty print json with jq.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2096
diff
changeset
|
25 |
By default ``jq`` produce colorized output in terminal! |
614569553a08
Pretty print json with jq.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2096
diff
changeset
|
26 |
|
2096 | 27 |
With Python 2.6+:: |
28 |
||
29 |
$ python -m simplejson.tool $FILE |
|
2098
1a896c3e47c2
Alternative Python module to pretty-print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2097
diff
changeset
|
30 |
$ python -m json.tool $FILE |
2096 | 31 |
|
32 |
In terminal you can add color support with ``pygmentize``:: |
|
33 |
||
34 |
$ curl -s http://.../... | python -m simplejson.tool | pygmentize -l json |
|
35 |
||
36 |
xml |
|
37 |
=== |
|
38 |
||
39 |
With tidy:: |
|
1209 | 40 |
|
41 |
$ tidy -xml -i -utf8 -o out.xml in.xml |
|
42 |
||
43 |
or in Emacs:: |
|
44 |
||
45 |
C-x h C-x <RET> c utf-8 <RET> C-u M-| tidy -q -xml -i -utf8 - |
|
46 |
||
2096 | 47 |
With xmllint:: |
1209 | 48 |
|
49 |
$ xmllint --format file.xml |
|
50 |
||
2285
41b2a3652b35
Pretty print XMLs in place.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2228
diff
changeset
|
51 |
Pretty print XMLs in place:: |
41b2a3652b35
Pretty print XMLs in place.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2228
diff
changeset
|
52 |
|
41b2a3652b35
Pretty print XMLs in place.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2228
diff
changeset
|
53 |
for f in *.xml; do xmllint -o $f --format $f; done |
41b2a3652b35
Pretty print XMLs in place.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2228
diff
changeset
|
54 |
|
41b2a3652b35
Pretty print XMLs in place.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2228
diff
changeset
|
55 |
In Emacs:: |
1209 | 56 |
|
57 |
: C-x h C-u M-| xmllint --format - <RET> |
|
58 |
||
2096 | 59 |
With Emacs and nxml you need introduce line-breaks and then:: |
1209 | 60 |
|
61 |
C-x h C-M-\ |
|
62 |
||
2096 | 63 |
http://tidy.sourceforge.net |
64 |
Home page. |
|
65 |
http://www.emacswiki.org/cgi-bin/wiki/tidy.el |
|
66 |
Emacs bindings. |
|
67 |
http://xmlindent.sourceforge.net/ |
|
68 |
xmlindent home page. |
|
1209 | 69 |
|
70 |
c/c++/java/c#. |
|
1323
1d94538d70c9
http://perltidy.sourceforge.net/
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1209
diff
changeset
|
71 |
============== |
1209 | 72 |
|
73 |
Artistic Style, astyle. |
|
74 |
----------------------- |
|
75 |
||
76 |
A Free, Fast and Small Automatic Formatter for C, C++, C#, and Java Source Code. |
|
77 |
||
78 |
There are exist package for Cygwin, Debian. |
|
79 |
||
2228
837f1337c59b
Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2098
diff
changeset
|
80 |
http://astyle.sourceforge.net/ |
837f1337c59b
Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2098
diff
changeset
|
81 |
home page |
1209 | 82 |
|
83 |
Uncrustify. |
|
84 |
----------- |
|
85 |
||
86 |
Source Code Beautifier for C, C++, C#, ObjectiveC, D, Java, Pawn and VALA. |
|
87 |
||
88 |
Exist package for Windows (binary from home page), Debian. |
|
89 |
||
2228
837f1337c59b
Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2098
diff
changeset
|
90 |
http://uncrustify.sourceforge.net/ |
837f1337c59b
Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2098
diff
changeset
|
91 |
home page |
1209 | 92 |
|
93 |
jpplib. |
|
94 |
------- |
|
95 |
||
96 |
Pretty Printer Library. |
|
97 |
||
2228
837f1337c59b
Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2098
diff
changeset
|
98 |
http://jpplib.sourceforge.net/ |
837f1337c59b
Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2098
diff
changeset
|
99 |
Home page. |
1209 | 100 |
|
1323
1d94538d70c9
http://perltidy.sourceforge.net/
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1209
diff
changeset
|
101 |
Perl. |
1d94538d70c9
http://perltidy.sourceforge.net/
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1209
diff
changeset
|
102 |
===== |
1d94538d70c9
http://perltidy.sourceforge.net/
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1209
diff
changeset
|
103 |
|
2096 | 104 |
http://perltidy.sourceforge.net/ |
105 |
Home page. |
|
1323
1d94538d70c9
http://perltidy.sourceforge.net/
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1209
diff
changeset
|
106 |