annotate textshaper/onelineit.py @ 41:56199789d2a0

mv
author Jeff Hammel <k0scist@gmail.com>
date Mon, 25 Aug 2014 19:22:37 -0700
parents onelineit.py@e1832eeae084
children 1a80204bd562
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3 def onelineit(string):
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 string = string.split('\n')
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 string = [ i.strip() or '\n' for i in string ]
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6 string = ' '.join(string)
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7 string = string.split('\n')
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 string = [ i.strip() for i in string if i.strip() ]
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10 return '\n\n'.join(string)
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12 if __name__ == '__main__':
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13 import sys
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14 print onelineit(sys.stdin.read())