mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-14 21:43:11 +00:00

to do that conversion, and the resulting html and pdf documents. All of the work is done in subdirectories. This is for review, comment, and adjustment. Still to be done: - Integrate the docbook to html and pdf into the Maven build. - Merge changes from the Foundation version of docs into HTML. - Remove the legacy HTML source. - Remove the generated html and pdf once the build does it. - Various small formatting cleanups. git-svn-id: http://scm.dspace.org/svn/repo/branches/dspace-1_5_x@3042 9c30dcfa-912a-0410-8fc2-9e0234be79fd
77 lines
1.9 KiB
Python
Executable File
77 lines
1.9 KiB
Python
Executable File
#! /usr/bin/env python
|
|
|
|
""" Utility program to try to gently line wrap preformatted text inside an XML tag
|
|
|
|
"""
|
|
|
|
import sys, string
|
|
import codecs
|
|
|
|
def wrapElementLines(wrap=72,src=sys.stdin, dst=sys.stdout, srcenc='iso8859', dstenc='utf-8', elem='screen'):
|
|
|
|
# Tell python how to encode the output (generally utf-8)
|
|
(e,d,sr,sw) = codecs.lookup(dstenc)
|
|
out = sw(dst)
|
|
|
|
# Tell python how to interpret the input (generally iso8859)
|
|
(e,d,sr,sw) = codecs.lookup(srcenc)
|
|
inp = sr(src)
|
|
|
|
inElem = False
|
|
openElem = "<"+elem+">"
|
|
closeElem = "</"+elem+">"
|
|
|
|
for line in inp:
|
|
try:
|
|
index = line.index(openElem)
|
|
inElem = True
|
|
except:
|
|
pass
|
|
if inElem:
|
|
try:
|
|
line.index(closeElem)
|
|
inElem = False
|
|
except:
|
|
while len(line) > wrap:
|
|
lim = indexlimit(line,wrap)
|
|
try:
|
|
space = line[0:lim].rindex(' ')
|
|
out.write(line[0:space]+"\n\t") # " \\\n\t"
|
|
line = line[space+1:]
|
|
except:
|
|
out.write(line[0:lim]+"\n") # "\\\n"
|
|
line = line[wrap:]
|
|
out.write(line)
|
|
|
|
def indexlimit(string,limit=72):
|
|
tag=False
|
|
ent=False
|
|
ptr=0
|
|
cnt=0
|
|
for ch in string:
|
|
ptr = ptr + 1
|
|
if ch == '<' and not tag:
|
|
tag=True
|
|
elif ch == '>' and tag:
|
|
tag=False
|
|
elif ch == '&' and not ent:
|
|
ent=True
|
|
elif ch == ';' and ent:
|
|
cnt = cnt + 1
|
|
ent=False
|
|
elif not (tag or ent):
|
|
cnt = cnt + 1
|
|
if cnt >= limit:
|
|
return ptr
|
|
return ptr
|
|
|
|
src = sys.stdin
|
|
dst = sys.stdout
|
|
|
|
if len(sys.argv) > 1:
|
|
src = open(sys.argv[1])
|
|
if len(sys.argv) > 2:
|
|
dst = open(sys.argv[2],"w")
|
|
|
|
wrapElementLines(src=src,dst=dst,wrap=70,srcenc="utf-8")
|