def addParas(words): words = [asUnicode(w) for w in words] txt = u' '.join([(len(w) > 5 and u'<index item=%s/>%s' % (quoteattr(commajoin([w[:2], w[:3], w])), w) or w) for w in words]) para = Paragraph(txt, makeBodyStyle()) story.append(para)
def test0(self): """ Test case for Indexes. This will draw an index %sat the end of the document with dots seperating the indexing terms from the page numbers. Index terms are grouped by their first 2, and first 3 characters. The page numbers should be clickable and link to the indexed word. """ # Build story. for headers in False, True: path = outputfile("test_platypus_index%s.pdf" % (headers and "_headers" or "")) doc = MyDocTemplate(path) story = [] styleSheet = getSampleStyleSheet() bt = styleSheet["BodyText"] description = "<font color=red>%s</font>" % ( self.test0.__doc__ % (headers and "with alphabetic headers " or "") ) story.append(Paragraph(description, bt)) index = SimpleIndex(dot=" . ", headers=headers) for i in range(20): words = randomtext.randomText(randomtext.PYTHON, 5).split(" ") txt = " ".join( [ (len(w) > 5 and "<index item=%s/>%s" % (quoteattr(commajoin([w[:2], w[:3], w])), w) or w) for w in words ] ) para = Paragraph(txt, makeBodyStyle()) story.append(para) # test ampersand in index term txt = '\nMarks & Spencer - purveyors of fine groceries, underwear and ampersands - should have their initials displayed however they were input.\n<index item="M&S,groceries"/><index item="M&S,underwear"/><index item="M&S,ampersands"/>' para = Paragraph(txt, makeBodyStyle()) story.append(para) story.append(index) doc.build(story, canvasmaker=index.getCanvasMaker())
def test0(self): ''' Test case for Indexes. This will draw an index %sat the end of the document with dots seperating the indexing terms from the page numbers. Index terms are grouped by their first 2, and first 3 characters. The page numbers should be clickable and link to the indexed word. ''' # Build story. for headers in False, True: path = outputfile('test_platypus_index%s.pdf' % (headers and '_headers' or '')) doc = MyDocTemplate(path) story = [] styleSheet = getSampleStyleSheet() bt = styleSheet['BodyText'] description = '<font color=red>%s</font>' % ( self.test0.__doc__ % (headers and 'with alphabetic headers ' or '')) story.append(Paragraph(description, bt)) index = SimpleIndex(dot=' . ', headers=headers) for i in range(20): words = randomtext.randomText(randomtext.PYTHON, 5).split(' ') txt = ' '.join([(len(w) > 5 and '<index item=%s/>%s' % (quoteattr(commajoin([w[:2], w[:3], w])), w) or w) for w in words]) para = Paragraph(txt, makeBodyStyle()) story.append(para) #test ampersand in index term txt = '\nMarks & Spencer - purveyors of fine groceries, underwear and ampersands - should have their initials displayed however they were input.\n<index item="M&S,groceries"/><index item="M&S,underwear"/><index item="M&S,ampersands"/>' para = Paragraph(txt, makeBodyStyle()) story.append(para) story.append(index) doc.build(story, canvasmaker=index.getCanvasMaker())