def munge(document, template, linkrel, d, fullpath, ext, url, config): # FIXME: This has *way* to much duplicated crap in common with tree.munge #fixRelativeLinks(template, linkrel) removeH1(document) fixAPI(document, url) fontifyPython(document) addPyListings(document, d) addHTMLListings(document, d) #fixLinks(document, ext) #putInToC(template, generateToC(document)) template = template.cloneNode(1) # Insert the slides into the template slides = [] pos = 0 for title, slide in splitIntoSlides(document): t = template.cloneNode(1) text = dom.Text() text.data = title setTitle(t, [text]) tmplbody = domhelpers.findElementsWithAttribute(t, "class", "body")[0] tmplbody.childNodes = slide tmplbody.setAttribute("class", "content") # FIXME: Next/Prev links # FIXME: Perhaps there should be a "Template" class? (setTitle/setBody # could be methods...) slides.append(HTMLSlide(t, title, pos)) pos += 1 insertPrevNextLinks(slides, os.path.splitext(os.path.basename(fullpath)), ext) return slides
def test_setTitleWithChapter(self): """ L{tree.setTitle} includes a chapter number if it is passed one. """ document = dom.Document() parent = dom.Element('div') parent.ownerDocument = document title = dom.Element('title') parent.appendChild(title) titleNodes = [dom.Text()] titleNodes[0].ownerDocument = document titleNodes[0].data = 'foo bar' # Oh yea. The numberer has to agree to put the chapter number in, too. numberer.setNumberSections(True) tree.setTitle(parent, titleNodes, '13') self.assertEqual(title.toxml(), '<title>13. foo bar</title>')
def test_setTitle(self): """ L{tree.setTitle} inserts the given title into the first I{title} element and the first element with the I{title} class in the given template. """ parent = dom.Element("div") firstTitle = dom.Element("title") parent.appendChild(firstTitle) secondTitle = dom.Element("span") secondTitle.setAttribute("class", "title") parent.appendChild(secondTitle) titleNodes = [dom.Text()] # minidom has issues with cloning documentless-nodes. See Python issue # 4851. titleNodes[0].ownerDocument = dom.Document() titleNodes[0].data = "foo bar" tree.setTitle(parent, titleNodes, None) self.assertEqual(firstTitle.toxml(), "<title>foo bar</title>") self.assertEqual(secondTitle.toxml(), '<span class="title">foo bar</span>')
def test_setTitle(self): """ L{tree.setTitle} inserts the given title into the first I{title} element and the first element with the I{title} class in the given template. """ parent = dom.Element('div') firstTitle = dom.Element('title') parent.appendChild(firstTitle) secondTitle = dom.Element('span') secondTitle.setAttribute('class', 'title') parent.appendChild(secondTitle) titleNodes = [dom.Text()] # minidom has issues with cloning documentless-nodes. See Python issue # 4851. titleNodes[0].ownerDocument = dom.Document() titleNodes[0].data = 'foo bar' tree.setTitle(parent, titleNodes, None) self.assertEqual(firstTitle.toxml(), '<title>foo bar</title>') self.assertEqual(secondTitle.toxml(), '<span class="title">foo bar</span>')