rst2pdf/rst2pdf-0.16-docutils_0.8.patch

788 lines
33 KiB
Diff
Raw Permalink Normal View History

--- rst2pdf-0.16/rst2pdf/createpdf.py.orig 2010-10-06 23:21:41.000000000 +0200
+++ rst2pdf-0.16/rst2pdf/createpdf.py 2011-10-07 18:41:42.000000000 +0200
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
-#$HeadURL: https://rst2pdf.googlecode.com/svn/tags/0.16/rst2pdf/createpdf.py $
-#$LastChangedDate: 2010-10-06 18:21:41 -0300 (Wed, 06 Oct 2010) $
-#$LastChangedRevision: 2396 $
+#$HeadURL$
+#$LastChangedDate$
+#$LastChangedRevision$
# See LICENSE.txt for licensing terms
@@ -65,7 +65,7 @@ from docutils.readers import standalone
from docutils.transforms import Transform
import pygments_code_block_directive # code-block directive
-import oddeven_directive
+import oddeven_directive
from reportlab.platypus import *
from reportlab.platypus.doctemplate import IndexingFlowable
@@ -125,13 +125,13 @@ from nodehandlers import nodehandlers
'lowerroman': 'ROMAN_LOWER',
'alpha': 'LETTERS_UPPER',
'loweralpha': 'LETTERS_LOWER' }
-
+
class RstToPdf(object):
def __init__(self, stylesheets=[],
- language='en',
+ language='en_US',
header=None,
footer=None,
inlinelinks=False,
@@ -157,6 +157,7 @@ from nodehandlers import nodehandlers
custom_cover='cover.tmpl',
floating_images=False,
numbered_links=False,
+ section_header_depth=2
):
self.debugLinesPdf=False
self.depth=0
@@ -165,17 +166,19 @@ from nodehandlers import nodehandlers
self.splittables=splittables
self.basedir=basedir
self.language = language
+ self.docutils_language = language
try:
- get_language (self.language)
+ self.get_language(self.language)
except ImportError:
try:
language = self.language.split('_', 1)[0]
- get_language (language)
- self.language = language
+ self.get_language(language)
+ self.docutils_language = language
except ImportError:
- log.warning("Can't load Docutils module "\
- "for language %s or %s", self.language, language)
- self.language = 'en'
+ log.warning("Can't load Docutils module"
+ " for language %s or %s", self.language, language)
+ self.language = 'en_US'
+ self.docutils_language = 'en'
self.doc_title = ""
self.doc_title_clean = ""
self.doc_subtitle = ""
@@ -193,13 +196,13 @@ from nodehandlers import nodehandlers
self.PATH = abspath(dirname(sys.executable))
else:
self.PATH = abspath(dirname(__file__))
-
-
+
+
self.font_path=font_path
self.style_path=style_path
self.def_dpi=def_dpi
self.loadStyles(stylesheets)
-
+
self.docutils_languages = {}
self.inlinelinks = inlinelinks
self.breaklevel = breaklevel
@@ -218,6 +221,7 @@ from nodehandlers import nodehandlers
self.def_dpi = def_dpi
self.show_frame = show_frame
self.numbered_links = numbered_links
+ self.section_header_depth = section_header_depth
self.img_dir = os.path.join(self.PATH, 'images')
# Sorry about this, but importing sphinx.roles makes some
@@ -242,18 +246,20 @@ from nodehandlers import nodehandlers
if self.language:
self.styles.languages.append(self.language)
self.styles['bodytext'].language = self.language
-
+ else:
+ self.styles.languages.append('en_US')
+ self.styles['bodytext'].language = 'en_US'
# Load the docutils language modules for all required languages
for lang in self.styles.languages:
try:
- self.docutils_languages[lang] = get_language(lang)
+ self.docutils_languages[lang] = self.get_language(lang)
except ImportError:
try:
self.docutils_languages[lang] = \
- get_language(lang.split('_', 1)[0])
+ self.get_language(lang.split('_', 1)[0])
except ImportError:
- log.warning("Can't load Docutils module \
- for language %s", lang)
+ log.warning("Can't load Docutils module"
+ " for language %s", lang)
# Load the hyphenators for all required languages
if wordaxe is not None:
@@ -265,8 +271,8 @@ from nodehandlers import nodehandlers
except Exception:
# hyphenators may not always be available or crash,
# e.g. wordaxe issue 2809074 (http://is.gd/16lqs)
- log.warning("Can't load wordaxe DCW hyphenator "
- "for German language, trying Py hyphenator instead")
+ log.warning("Can't load wordaxe DCW hyphenator"
+ " for German language, trying Py hyphenator instead")
else:
continue
try:
@@ -286,17 +292,25 @@ from nodehandlers import nodehandlers
self.pending_targets=[]
self.targets=[]
-
+
def loadStyles(self, styleSheets=None ):
-
+
if styleSheets is None:
styleSheets=[]
-
+
self.styles = sty.StyleSheet(styleSheets,
self.font_path,
self.style_path,
def_dpi=self.def_dpi)
+ def get_language(self, lang):
+ try:
+ return get_language(lang, reporter=log)
+ except TypeError, err: # Docutils < 0.8
+ if 'get_language' in str(err) and 'reporter' in str(err):
+ return get_language(lang)
+ raise # re-raise any other TypeError
+
def style_language(self, style):
"""Return language corresponding to this style."""
try:
@@ -318,8 +332,8 @@ from nodehandlers import nodehandlers
def text_for_label(self, label, style):
"""Translate text for label."""
try:
- text = self.docutils_languages[self.style_language(style)]\
- .labels[label]
+ text = self.docutils_languages[
+ self.style_language(style)].labels[label]
except KeyError:
text = label.capitalize()
return text
@@ -327,8 +341,8 @@ from nodehandlers import nodehandlers
def text_for_bib_field(self, field, style):
"""Translate text for bibliographic fields."""
try:
- text = self.docutils_languages[self.style_language(style)]\
- .bibliographic_fields[field]
+ text = self.docutils_languages[
+ self.style_language(style)].bibliographic_fields[field]
except KeyError:
text = field
return text + ":"
@@ -336,8 +350,8 @@ from nodehandlers import nodehandlers
def author_separator(self, style):
"""Return separator string for authors."""
try:
- sep = self.docutils_languages[self.style_language(style)]\
- .author_separators[0]
+ sep = self.docutils_languages[
+ self.style_language(style)].author_separators[0]
except KeyError:
sep = ';'
return sep + " "
@@ -366,13 +380,12 @@ from nodehandlers import nodehandlers
if s.underline:
r1.append('<u>')
r2.insert(0,'</u>')
-
+
return [''.join(r1), ''.join(r2)]
except KeyError:
log.warning('Unknown class %s', style)
return None
-
def styleToFont(self, style):
'''Takes a style name, returns a font tag for it, like
@@ -387,7 +400,7 @@ from nodehandlers import nodehandlers
if bc:
r.append('backColor="#%s"' % bc.hexval()[2:])
if s.trueFontSize:
- r.append('size="%d"'%s.fontSize)
+ r.append('size="%d"'%s.fontSize)
r.append('>')
return ''.join(r)
except KeyError:
@@ -420,14 +433,14 @@ from nodehandlers import nodehandlers
else:
start = 1
- if node.parent.get('bullet') or \
- isinstance(node.parent, docutils.nodes.bullet_list):
- b = node.parent.get('bullet','*')
+ if node.parent.get('bullet') or isinstance(
+ node.parent, docutils.nodes.bullet_list):
+ b = node.parent.get('bullet', '*')
if b == "None":
b = ""
t = 'bullet'
- elif node.parent.get('enumtype')=='arabic':
+ elif node.parent.get('enumtype') == 'arabic':
b = str(node.parent.children.index(node) + start) + '.'
elif node.parent.get('enumtype') == 'lowerroman':
@@ -521,9 +534,9 @@ from nodehandlers import nodehandlers
content=[XXPreformatted(text, style)],
mode=self.fit_mode, style=style)
- def createPdf(self, text=None,
- source_path=None,
- output=None,
+ def createPdf(self, text=None,
+ source_path=None,
+ output=None,
doctree=None,
compressed=False,
# This adds entries to the PDF TOC
@@ -541,7 +554,7 @@ from nodehandlers import nodehandlers
'footer': self.footer,
'endnotes': [],
'extraflowables': []}
-
+
self.pending_targets=[]
self.targets=[]
@@ -550,7 +563,7 @@ from nodehandlers import nodehandlers
if doctree is None:
if text is not None:
if self.language:
- settings_overrides={'language_code': self.language}
+ settings_overrides={'language_code': self.docutils_language}
else:
settings_overrides={}
self.doctree = docutils.core.publish_doctree(text,
@@ -570,7 +583,7 @@ from nodehandlers import nodehandlers
self.doctree.walk(snf)
srf = SectRefExpander(self.doctree, snf.sectnums)
self.doctree.walk(srf)
-
+
elements = self.gen_elements(self.doctree)
# Find cover template, save it in cover_file
@@ -621,8 +634,8 @@ from nodehandlers import nodehandlers
# Handle images with alignment more like in HTML
new_elem=[]
for i,e in enumerate(elements[::-1]):
- if isinstance (e, MyImage) and e.image.hAlign != 'CENTER'\
- and new_elem:
+ if (isinstance (e, MyImage) and e.image.hAlign != 'CENTER'
+ and new_elem):
# This is an image where flowables should wrap
# around it
popped=new_elem.pop()
@@ -670,7 +683,7 @@ from nodehandlers import nodehandlers
# first pass in the case of ###Total###, then we
# make a new forced two-pass build. This is broken.
# conceptually.
-
+
if getattr(self, 'mustMultiBuild', False):
# Force a multibuild pass
if not isinstance(elements[-1],UnhappyOnce):
@@ -686,8 +699,8 @@ from nodehandlers import nodehandlers
# Add it to the pile
#if not isinstance (e, MySpacer):
fnPile.append(e)
- elif getattr(e, '_atTop', False) or \
- isinstance (e, (UnhappyOnce, MyPageBreak)):
+ elif getattr(e, '_atTop', False) or isinstance(
+ e, (UnhappyOnce, MyPageBreak)):
if fnPile:
newStory.append(Sinker(fnPile))
newStory.append(e)
@@ -702,7 +715,7 @@ from nodehandlers import nodehandlers
continue
-
+
break
except ValueError, v:
# FIXME: cross-document links come through here, which means
@@ -737,7 +750,7 @@ from reportlab.platypus import doctempla
# Notify TOC entry for headings/abstracts/dedications.
level, text = flowable.level, flowable.text
parent_id = flowable.parent_id
- node = flowable.node
+ node = flowable.node
pagenum = setPageCounter()
self.notify('TOCEntry', (level, text, pagenum, parent_id, node))
@@ -790,7 +803,8 @@ from reportlab.platypus import doctempla
self.afterFlowable(S[0])
doctemplate._addGeneratedContent(flowables,frame)
else:
- ident = "Splitting error(n==%d) on page %d in\n%s" % (n,self.page,self._fIdent(f,60,frame))
+ ident = "Splitting error(n==%d) on page %d in\n%s" % (
+ n, self.page, self._fIdent(f, 60, frame))
#leave to keep apart from the raise
raise LayoutError(ident)
del S[0]
@@ -798,17 +812,17 @@ from reportlab.platypus import doctempla
flowables.insert(i,f) # put split flowables back on the list
else:
if hasattr(f,'_postponed') and f._postponed > 4:
- ident = "Flowable %s%s too large on page %d in frame %r%s of template %r" % \
- (self._fIdent(f,60,frame),doctemplate._fSizeString(f),self.page, self.frame.id,
- self.frame._aSpaceString(), self.pageTemplate.id)
+ ident = "Flowable %s%s too large on page %d in frame %r%s of template %r" % (
+ self._fIdent(f, 60, frame), doctemplate._fSizeString(f),self.page,
+ self.frame.id, self.frame._aSpaceString(), self.pageTemplate.id)
#leave to keep apart from the raise
raise LayoutError(ident)
# this ought to be cleared when they are finally drawn!
f._postponed = 1
- mbe = getattr(self,'_multiBuildEdits',None)
+ mbe = getattr(self, '_multiBuildEdits', None)
if mbe:
- mbe((delattr,f,'_postponed'))
- flowables.insert(0,f) # put the flowable back
+ mbe((delattr, f, '_postponed'))
+ flowables.insert(0, f) # put the flowable back
self.handle_frameEnd()
@@ -830,7 +844,7 @@ from reportlab.platypus import doctempla
def drawOn(self, canvas, x, y, _sW):
pass
-
+
flowables.PageCounter = PageCounter
def setPageCounter(counter=None, style=None):
@@ -853,13 +867,13 @@ flowables.PageCounter = PageCounter
else:
ptext=unicode(_counter)
return ptext
-
+
class MyContainer(_Container, Flowable):
pass
class UnhappyOnce(IndexingFlowable):
'''An indexing flowable that is only unsatisfied once.
- If added to a story, it will make multiBuild run
+ If added to a story, it will make multiBuild run
at least two passes. Useful for ###Total###'''
_unhappy=True
def isSatisfied(self):
@@ -867,7 +881,7 @@ flowables.PageCounter = PageCounter
self._unhappy= False
return False
return True
-
+
def draw(self):
pass
@@ -935,7 +949,7 @@ flowables.PageCounter = PageCounter
getattr(canv, 'sectNum', ''))
text = smartyPants(text, smarty)
return text
-
+
for i,e in enumerate(elems):
if isinstance(e, Paragraph):
text = replace(e.text)
@@ -955,7 +969,7 @@ flowables.PageCounter = PageCounter
even=self.replaceTokens([e.even,], canv, doc, smarty)[0]
elems[i]=OddEven(odd, even)
return elems
-
+
def draw(self, pageobj, canv, doc, x, y, width, height):
self.totalpages = max(self.totalpages, doc.page)
items = self.prepared
@@ -1007,11 +1021,11 @@ flowables.PageCounter = PageCounter
return
try:
w, h, kind = MyImage.size_for_node(dict(uri=uri, ), self.client)
- except ValueError:
+ except ValueError:
# Broken image, return arbitrary stuff
uri=missing
w, h, kind = 100, 100, 'direct'
-
+
pw, ph = self.styles.pw, self.styles.ph
if self.client.background_fit_mode == 'center':
scale = min(1.0, 1.0 * pw / w, 1.0 * ph / h)
@@ -1025,7 +1039,7 @@ flowables.PageCounter = PageCounter
# Do scale anyway
x, y = 0, 0
sw, sh = pw, ph
-
+
bg = MyImage(uri, sw, sh, client=self.client)
self.image_cache[uri] = info = bg, x, y
bg, x, y = info
@@ -1041,8 +1055,8 @@ flowables.PageCounter = PageCounter
global _counter, _counterStyle
- self.tw = self.styles.pw - self.styles.lm -\
- self.styles.rm - self.styles.gm
+ styles = self.styles
+ self.tw = styles.pw - styles.lm - styles.rm - styles.gm
# What page template to use?
tname = canv.__dict__.get('templateName',
self.styles.firstTemplate)
@@ -1052,34 +1066,33 @@ flowables.PageCounter = PageCounter
doct = getattr(canv, '_doctemplate', None)
canv._doctemplate = None # to make _listWrapOn work
- if doc.page==1:
- _counter=0
- _counterStyle='arabic'
- _counter+=1
+ if doc.page == 1:
+ _counter = 0
+ _counterStyle = 'arabic'
+ _counter += 1
# Adjust text space accounting for header/footer
-
+
self.hh = self._head.prepare(self, canv, doc)
self.fh = self._foot.prepare(self, canv, doc)
-
+
canv._doctemplate = doct
- self.hx = self.styles.lm
- self.hy = self.styles.ph - self.styles.tm -self.hh
+ self.hx = styles.lm
+ self.hy = styles.ph - styles.tm - self.hh
+
+ self.fx = styles.lm
+ self.fy = styles.bm
+ self.th = styles.ph - styles.tm - styles.bm - self.hh \
+ - self.fh - styles.ts - styles.bs
- self.fx = self.styles.lm
- self.fy = self.styles.bm
- self.th = self.styles.ph - self.styles.tm - \
- self.styles.bm - self.hh - self.fh - \
- self.styles.ts - self.styles.bs
-
# Adjust gutter margins
if doc.page % 2: # Left page
- x1 = self.styles.lm
+ x1 = styles.lm
else: # Right page
- x1 = self.styles.lm + self.styles.gm
- y1 = self.styles.bm + self.fh + self.styles.bs
-
+ x1 = styles.lm + styles.gm
+ y1 = styles.bm + self.fh + styles.bs
+
# If there is a background parameter for this page Template, draw it
if 'background' in self.template:
self.draw_background('background', canv)
@@ -1087,13 +1100,13 @@ flowables.PageCounter = PageCounter
self.frames = []
for frame in self.template['frames']:
self.frames.append(SmartFrame(self,
- self.styles.adjustUnits(frame[0], self.tw) + x1,
- self.styles.adjustUnits(frame[1], self.th) + y1,
- self.styles.adjustUnits(frame[2], self.tw),
- self.styles.adjustUnits(frame[3], self.th),
+ styles.adjustUnits(frame[0], self.tw) + x1,
+ styles.adjustUnits(frame[1], self.th) + y1,
+ styles.adjustUnits(frame[2], self.tw),
+ styles.adjustUnits(frame[3], self.th),
showBoundary=self.show_frame))
- canv.firstSect=True
- canv._pagenum=doc.page
+ canv.firstSect = True
+ canv._pagenum = doc.page
for frame in self.frames:
frame._pagenum=doc.page
@@ -1101,15 +1114,15 @@ flowables.PageCounter = PageCounter
"""Draw header/footer."""
# Adjust for gutter margin
canv.addPageLabel(canv._pageNumber-1,numberingstyles[_counterStyle],_counter)
-
- log.info('Page %s [%s]'%(_counter,doc.page))
+
+ log.error('Page %s [%s]'%(_counter,doc.page))
if doc.page % 2: # Left page
hx = self.hx
fx = self.fx
else: # Right Page
hx = self.hx + self.styles.gm
fx = self.fx + self.styles.gm
-
+
self._head.draw(self, canv, doc, hx, self.hy, self.tw, self.hh)
self._foot.draw(self, canv, doc, fx, self.fy, self.tw, self.fh)
@@ -1119,12 +1132,12 @@ flowables.PageCounter = PageCounter
def parse_commandline():
-
+
parser = OptionParser()
-
+
parser.add_option('--config', dest='configfile', metavar='FILE',
help='Config file to use. Default=~/.rst2pdf/config')
-
+
parser.add_option('-o', '--output', dest='output', metavar='FILE',
help='Write the PDF to FILE')
@@ -1133,16 +1146,16 @@ flowables.PageCounter = PageCounter
parser.add_option('-s', '--stylesheets', dest='style',
type='string', action='append',
metavar='STYLESHEETS', default=[def_ssheets],
- help='A comma-separated list of custom stylesheets.'\
- ' Default="%s"' % def_ssheets)
+ help='A comma-separated list of custom stylesheets. Default="%s"'
+ % def_ssheets)
def_sheetpath = os.pathsep.join([expanduser(p) for p in
config.getValue("general", "stylesheet_path", "").split(os.pathsep)])
parser.add_option('--stylesheet-path', dest='stylepath',
metavar='FOLDER%sFOLDER%s...%sFOLDER'%((os.pathsep, )*3),
default=def_sheetpath,
- help='A list of folders to search for stylesheets,"\
- " separated using "%s". Default="%s"' %(os.pathsep, def_sheetpath))
+ help='A list of folders to search for stylesheets,'
+ ' separated using "%s". Default="%s"' %(os.pathsep, def_sheetpath))
def_compressed = config.getValue("general", "compressed", False)
parser.add_option('-c', '--compressed', dest='compressed',
@@ -1161,59 +1174,64 @@ flowables.PageCounter = PageCounter
parser.add_option('--font-path', dest='fpath',
metavar='FOLDER%sFOLDER%s...%sFOLDER'%((os.pathsep, )*3),
default=def_fontpath,
- help='A list of folders to search for fonts,'\
- ' separated using "%s". Default="%s"'%(os.pathsep, def_fontpath))
+ help='A list of folders to search for fonts, separated using "%s".'
+ ' Default="%s"' % (os.pathsep, def_fontpath))
def_baseurl = urlunparse(['file',os.getcwd()+os.sep,'','','',''])
parser.add_option('--baseurl', dest='baseurl', metavar='URL',
default=def_baseurl,
help='The base URL for relative URLs. Default="%s"'%def_baseurl)
- def_lang = config.getValue("general", "language", 'en')
+ def_lang = config.getValue("general", "language", 'en_US')
parser.add_option('-l', '--language', metavar='LANG',
default=def_lang, dest='language',
- help='Language to be used for hyphenation and '\
- 'docutils localizations. Default="%s"' % def_lang)
+ help='Language to be used for hyphenation'
+ ' and docutils localizations. Default="%s"' % def_lang)
def_header = config.getValue("general", "header")
parser.add_option('--header', metavar='HEADER',
default=def_header, dest='header',
- help='Page header if not specified in the document.'\
- ' Default="%s"' % def_header)
+ help='Page header if not specified in the document.'
+ ' Default="%s"' % def_header)
def_footer = config.getValue("general", "footer")
parser.add_option('--footer', metavar='FOOTER',
default=def_footer, dest='footer',
- help='Page footer if not specified in the document.'\
- ' Default="%s"' % def_footer)
+ help='Page footer if not specified in the document.'
+ ' Default="%s"' % def_footer)
+
+ def_section_header_depth = config.getValue("general","section_header_depth",2)
+ parser.add_option('--section-header-depth', metavar='N',
+ default=def_section_header_depth, dest='section_header_depth',
+ help = '''Sections up to this depth will be used in the header and footer's replacement of ###Section###. Default=%s''' % def_section_header_depth)
def_smartquotes = config.getValue("general", "smartquotes", "0")
parser.add_option("--smart-quotes", metavar="VALUE",
default=def_smartquotes, dest="smarty",
- help='Try to convert ASCII quotes, ellipsis and dashes '\
- 'to the typographically correct equivalent. For details,'\
- ' read the man page or the manual. Default="%s"'%def_smartquotes)
+ help='Try to convert ASCII quotes, ellipses and dashes'
+ ' to the typographically correct equivalent. For details,'
+ ' read the man page or the manual. Default="%s"' % def_smartquotes)
def_fit = config.getValue("general", "fit_mode", "shrink")
parser.add_option('--fit-literal-mode', metavar='MODE',
default=def_fit, dest='fit_mode',
- help='What todo when a literal is too wide. One of error,'\
- ' overflow,shrink,truncate. Default="%s"'%def_fit)
+ help='What to do when a literal is too wide. One of error,'
+ ' overflow,shrink,truncate. Default="%s"' % def_fit)
def_fit_background = config.getValue("general", "background_fit_mode",
- "center")
+ "center")
parser.add_option('--fit-background-mode', metavar='MODE',
default=def_fit_background, dest='background_fit_mode',
- help='How to fit the background image to the page.'\
- ' One of scale or center. Default="%s"'%def_fit_background)
+ help='How to fit the background image to the page.'
+ ' One of scale or center. Default="%s"' % def_fit_background)
parser.add_option('--inline-links', action="store_true",
dest='inlinelinks', default=False,
- help='shows target between parenthesis instead of active link')
+ help='Shows target between parentheses instead of active link.')
parser.add_option('--repeat-table-rows', action="store_true",
dest='repeattablerows', default=False,
- help='Repeats header row for each splitted table')
+ help='Repeats header row for each split table.')
parser.add_option('-q', '--quiet', action="store_true",
dest='quiet', default=False,
@@ -1235,22 +1253,22 @@ flowables.PageCounter = PageCounter
"footnote_backlinks", True)
parser.add_option('--no-footnote-backlinks', action='store_false',
dest='footnote_backlinks', default=def_footnote_backlinks,
- help='Disable footnote backlinks.'\
- ' Default=%s' % str(not def_footnote_backlinks))
+ help='Disable footnote backlinks.'
+ ' Default=%s' % str(not def_footnote_backlinks))
def_inline_footnotes = config.getValue("general",
"inline_footnotes", False)
parser.add_option('--inline-footnotes', action='store_true',
dest='inline_footnotes', default=def_inline_footnotes,
- help='Show footnotes inline.'\
- ' Default=%s' % str(not def_inline_footnotes))
+ help='Show footnotes inline.'
+ ' Default=%s' % str(not def_inline_footnotes))
def_real_footnotes = config.getValue("general",
"real_footnotes", False)
parser.add_option('--real-footnotes', action='store_true',
dest='real_footnotes', default=def_real_footnotes,
- help='Show footnotes at the bottom of the page where they are defined.'\
- ' Default=%s' % str(def_real_footnotes))
+ help='Show footnotes at the bottom of the page where they are defined.'
+ ' Default=%s' % str(def_real_footnotes))
def_dpi = config.getValue("general", "default_dpi", 300)
parser.add_option('--default-dpi', dest='def_dpi', metavar='NUMBER',
@@ -1263,20 +1281,20 @@ flowables.PageCounter = PageCounter
parser.add_option('--disable-splittables', dest='splittables',
action='store_false', default=True,
- help='Don\'t use splittable flowables in some elements. '
- 'Only try this if you can\'t process a document any other way.')
+ help="Don't use splittable flowables in some elements."
+ " Only try this if you can't process a document any other way.")
def_break = config.getValue("general", "break_level", 0)
parser.add_option('-b', '--break-level', dest='breaklevel',
metavar='LEVEL', default=def_break,
- help='Maximum section level that starts in a new page.'\
- ' Default: %d' % def_break)
+ help='Maximum section level that starts in a new page.'
+ ' Default: %d' % def_break)
def_fpeven = config.getValue("general", "first_page_even", False)
parser.add_option('--first-page-even', dest='first_page_even',
action='store_true', default=def_fpeven,
- help='Whether first page is odd (as in the screen on "facing pages"), '\
- 'or even (as in a book)')
+ help='Whether first page is odd (as in the screen on "facing pages"),'
+ ' or even (as in a book).')
def_blankfirst = config.getValue("general", "blank_first_page", False)
parser.add_option('--blank-first-page', dest='blank_first_page',
@@ -1286,14 +1304,16 @@ flowables.PageCounter = PageCounter
def_breakside = config.getValue("general", "break_side", 'any')
parser.add_option('--break-side', dest='breakside', metavar='VALUE',
default=def_breakside,
- help='How section breaks work. Can be "even", and sections start in an even page,'\
- '"odd", and sections start in odd pages, or "any" and sections start in the next page,'\
- 'be it even or odd. See also the -b option.')
+ help='How section breaks work. Can be "even", and sections start'
+ ' in an even page, "odd", and sections start in odd pages,'
+ ' or "any" and sections start in the next page, be it even or odd.'
+ ' See also the -b option.')
- parser.add_option('--date-invariant', dest='invariant',
+ parser.add_option('--date-invariant', dest='invariant',
action='store_true', default=False,
- help="Don't store the current date in the PDF. Useful mainly for the test suite, "\
- "where we don't want the PDFs to change.")
+ help="Don't store the current date in the PDF."
+ " Useful mainly for the test suite,"
+ " where we don't want the PDFs to change.")
parser.add_option('-e', '--extension-module', dest='extensions', action="append", type="string",
default = ['vectorpdf'],
@@ -1307,7 +1327,7 @@ flowables.PageCounter = PageCounter
def_floating_images = config.getValue("general", "floating_images", False)
parser.add_option('--use-floating-images', action='store_true', default=def_floating_images,
- help='Makes images with :aling: attribute work more like in rst2html. Default: %s'%def_floating_images,
+ help='Makes images with :align: attribute work more like in rst2html. Default: %s'%def_floating_images,
dest='floating_images')
def_numbered_links = config.getValue("general", "numbered_links", False)
@@ -1324,7 +1344,7 @@ flowables.PageCounter = PageCounter
options, args = parser.parse_args(copy(args))
if options.configfile:
- options.cfname=options.configfile
+ config.parseConfig(options.configfile)
parser = parse_commandline()
options, args = parser.parse_args(copy(args))
@@ -1415,9 +1435,8 @@ flowables.PageCounter = PageCounter
options.inline_footnotes = True
if reportlab.Version < '2.3':
- log.warning('You are using Reportlab version %s.'\
- ' The suggested version '\
- 'is 2.3 or higher'%reportlab.Version)
+ log.warning('You are using Reportlab version %s.'
+ ' The suggested version is 2.3 or higher' % reportlab.Version)
if options.invariant:
patch_PDFDate()
@@ -1450,6 +1469,7 @@ flowables.PageCounter = PageCounter
custom_cover=options.custom_cover,
floating_images=options.floating_images,
numbered_links=options.numbered_links,
+ section_header_depth=int(options.section_header_depth),
).createPdf(text=options.infile.read(),
source_path=options.infile.name,
output=options.outfile,
@@ -1489,7 +1509,7 @@ filenames change'''
lambda yyyy,mm,dd,hh,m,s:
"D:%04d%02d%02d%02d%02d%02d%+03d'%02d'" % (yyyy,mm,dd,hh,m,s,0,0))
return pdfdoc.format(pdfdoc.PDFString(dfmt(*self.date)), doc)
-
+
pdfdoc.PDFDate = PDFDate
reportlab.rl_config.invariant = 1