first commit
This commit is contained in:
commit
417e54da96
5696 changed files with 900003 additions and 0 deletions
File diff suppressed because it is too large
Load diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,78 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# $Id: prepstyles.py 9386 2023-05-16 14:49:31Z milde $
|
||||
# Author: Dave Kuhlman <dkuhlman@rexx.com>
|
||||
# Copyright: This module has been placed in the public domain.
|
||||
|
||||
"""
|
||||
Adapt a word-processor-generated styles.odt for odtwriter use:
|
||||
|
||||
Drop page size specifications from styles.xml in STYLE_FILE.odt.
|
||||
See https://docutils.sourceforge.io/docs/user/odt.html#page-size
|
||||
"""
|
||||
|
||||
# Author: Michael Schutte <michi@uiae.at>
|
||||
|
||||
from xml.etree import ElementTree as etree
|
||||
|
||||
import sys
|
||||
import zipfile
|
||||
from tempfile import mkstemp
|
||||
import shutil
|
||||
import os
|
||||
|
||||
NAMESPACES = {
|
||||
"style": "urn:oasis:names:tc:opendocument:xmlns:style:1.0",
|
||||
"fo": "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
|
||||
}
|
||||
|
||||
|
||||
def prepstyle(filename):
|
||||
|
||||
zin = zipfile.ZipFile(filename)
|
||||
styles = zin.open("styles.xml")
|
||||
|
||||
root = None
|
||||
# some extra effort to preserve namespace prefixes
|
||||
for event, elem in etree.iterparse(styles, events=("start", "start-ns")):
|
||||
if event == "start-ns":
|
||||
etree.register_namespace(elem[0], elem[1])
|
||||
elif event == "start":
|
||||
if root is None:
|
||||
root = elem
|
||||
|
||||
styles.close()
|
||||
|
||||
for el in root.findall(".//style:page-layout-properties",
|
||||
namespaces=NAMESPACES):
|
||||
for attr in list(el.attrib):
|
||||
if attr.startswith("{%s}" % NAMESPACES["fo"]):
|
||||
del el.attrib[attr]
|
||||
|
||||
tempname = mkstemp()
|
||||
zout = zipfile.ZipFile(os.fdopen(tempname[0], "wb"), "w",
|
||||
zipfile.ZIP_DEFLATED)
|
||||
|
||||
for item in zin.infolist():
|
||||
if item.filename == "styles.xml":
|
||||
zout.writestr(item, etree.tostring(root, encoding="UTF-8"))
|
||||
else:
|
||||
zout.writestr(item, zin.read(item.filename))
|
||||
|
||||
zout.close()
|
||||
zin.close()
|
||||
shutil.move(tempname[1], filename)
|
||||
|
||||
|
||||
def main():
|
||||
args = sys.argv[1:]
|
||||
if len(args) != 1 or args[0] in ('-h', '--help'):
|
||||
print(__doc__, file=sys.stderr)
|
||||
print("Usage: %s STYLE_FILE.odt\n" % sys.argv[0], file=sys.stderr)
|
||||
sys.exit(1)
|
||||
filename = args[0]
|
||||
prepstyle(filename)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,109 @@
|
|||
# $Id: pygmentsformatter.py 9015 2022-03-03 22:15:00Z milde $
|
||||
# Author: Dave Kuhlman <dkuhlman@rexx.com>
|
||||
# Copyright: This module has been placed in the public domain.
|
||||
|
||||
"""
|
||||
|
||||
Additional support for Pygments formatter.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
import pygments
|
||||
import pygments.formatter
|
||||
|
||||
|
||||
class OdtPygmentsFormatter(pygments.formatter.Formatter):
|
||||
def __init__(self, rststyle_function, escape_function):
|
||||
pygments.formatter.Formatter.__init__(self)
|
||||
self.rststyle_function = rststyle_function
|
||||
self.escape_function = escape_function
|
||||
|
||||
def rststyle(self, name, parameters=()):
|
||||
return self.rststyle_function(name, parameters)
|
||||
|
||||
|
||||
class OdtPygmentsProgFormatter(OdtPygmentsFormatter):
|
||||
def format(self, tokensource, outfile):
|
||||
tokenclass = pygments.token.Token
|
||||
for ttype, value in tokensource:
|
||||
value = self.escape_function(value)
|
||||
if ttype == tokenclass.Keyword:
|
||||
s2 = self.rststyle('codeblock-keyword')
|
||||
s1 = '<text:span text:style-name="%s">%s</text:span>' % \
|
||||
(s2, value, )
|
||||
elif ttype == tokenclass.Literal.String:
|
||||
s2 = self.rststyle('codeblock-string')
|
||||
s1 = '<text:span text:style-name="%s">%s</text:span>' % \
|
||||
(s2, value, )
|
||||
elif ttype in (
|
||||
tokenclass.Literal.Number.Integer,
|
||||
tokenclass.Literal.Number.Integer.Long,
|
||||
tokenclass.Literal.Number.Float,
|
||||
tokenclass.Literal.Number.Hex,
|
||||
tokenclass.Literal.Number.Oct,
|
||||
tokenclass.Literal.Number,
|
||||
):
|
||||
s2 = self.rststyle('codeblock-number')
|
||||
s1 = '<text:span text:style-name="%s">%s</text:span>' % \
|
||||
(s2, value, )
|
||||
elif ttype == tokenclass.Operator:
|
||||
s2 = self.rststyle('codeblock-operator')
|
||||
s1 = '<text:span text:style-name="%s">%s</text:span>' % \
|
||||
(s2, value, )
|
||||
elif ttype == tokenclass.Comment:
|
||||
s2 = self.rststyle('codeblock-comment')
|
||||
s1 = '<text:span text:style-name="%s">%s</text:span>' % \
|
||||
(s2, value, )
|
||||
elif ttype == tokenclass.Name.Class:
|
||||
s2 = self.rststyle('codeblock-classname')
|
||||
s1 = '<text:span text:style-name="%s">%s</text:span>' % \
|
||||
(s2, value, )
|
||||
elif ttype == tokenclass.Name.Function:
|
||||
s2 = self.rststyle('codeblock-functionname')
|
||||
s1 = '<text:span text:style-name="%s">%s</text:span>' % \
|
||||
(s2, value, )
|
||||
elif ttype == tokenclass.Name:
|
||||
s2 = self.rststyle('codeblock-name')
|
||||
s1 = '<text:span text:style-name="%s">%s</text:span>' % \
|
||||
(s2, value, )
|
||||
else:
|
||||
s1 = value
|
||||
outfile.write(s1)
|
||||
|
||||
|
||||
class OdtPygmentsLaTeXFormatter(OdtPygmentsFormatter):
|
||||
def format(self, tokensource, outfile):
|
||||
tokenclass = pygments.token.Token
|
||||
for ttype, value in tokensource:
|
||||
value = self.escape_function(value)
|
||||
if ttype == tokenclass.Keyword:
|
||||
s2 = self.rststyle('codeblock-keyword')
|
||||
s1 = '<text:span text:style-name="%s">%s</text:span>' % \
|
||||
(s2, value, )
|
||||
elif ttype in (tokenclass.Literal.String,
|
||||
tokenclass.Literal.String.Backtick,
|
||||
):
|
||||
s2 = self.rststyle('codeblock-string')
|
||||
s1 = '<text:span text:style-name="%s">%s</text:span>' % \
|
||||
(s2, value, )
|
||||
elif ttype == tokenclass.Name.Attribute:
|
||||
s2 = self.rststyle('codeblock-operator')
|
||||
s1 = '<text:span text:style-name="%s">%s</text:span>' % \
|
||||
(s2, value, )
|
||||
elif ttype == tokenclass.Comment:
|
||||
if value[-1] == '\n':
|
||||
s2 = self.rststyle('codeblock-comment')
|
||||
s1 = '<text:span text:style-name="%s">%s</text:span>\n' % \
|
||||
(s2, value[:-1], )
|
||||
else:
|
||||
s2 = self.rststyle('codeblock-comment')
|
||||
s1 = '<text:span text:style-name="%s">%s</text:span>' % \
|
||||
(s2, value, )
|
||||
elif ttype == tokenclass.Name.Builtin:
|
||||
s2 = self.rststyle('codeblock-name')
|
||||
s1 = '<text:span text:style-name="%s">%s</text:span>' % \
|
||||
(s2, value, )
|
||||
else:
|
||||
s1 = value
|
||||
outfile.write(s1)
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue