def setTitle(template, title, chapterNumber): """ Add title and chapter number information to the template document. The title is added to the end of the first C{title} tag and the end of the first tag with a C{class} attribute set to C{title}. If specified, the chapter is inserted before the title. @type template: A DOM Node or Document @param template: The output template which defines the presentation of the version information. @type title: C{list} of DOM Nodes @param title: Nodes from the input document defining its title. @type chapterNumber: C{int} @param chapterNumber: The chapter number of this content in an overall document. If not applicable, any C{False} value will result in this information being omitted. @return: C{None} """ for nodeList in ( domhelpers.findNodesNamed(template, "title"), domhelpers.findElementsWithAttribute(template, "class", "title"), ): if nodeList: if numberer.getNumberSections() and chapterNumber: nodeList[0].childNodes.append(microdom.Text("%s. " % chapterNumber)) nodeList[0].childNodes.extend(title)
def setTitle(template, title, chapterNumber): """ Add title and chapter number information to the template document. The title is added to the end of the first C{title} tag and the end of the first tag with a C{class} attribute set to C{title}. If specified, the chapter is inserted before the title. @type template: A DOM Node or Document @param template: The output template which defines the presentation of the version information. @type title: C{list} of DOM Nodes @param title: Nodes from the input document defining its title. @type chapterNumber: C{int} @param chapterNumber: The chapter number of this content in an overall document. If not applicable, any C{False} value will result in this information being omitted. @return: C{None} """ for nodeList in (domhelpers.findNodesNamed(template, "title"), domhelpers.findElementsWithAttribute( template, "class", 'title')): if nodeList: if numberer.getNumberSections() and chapterNumber: nodeList[0].childNodes.append( microdom.Text('%s. ' % chapterNumber)) nodeList[0].childNodes.extend(title)
def setTitle(template, title, chapterNumber): for nodeList in (domhelpers.findNodesNamed(template, "title"), domhelpers.findElementsWithAttribute(template, "class", 'title')): if nodeList: if numberer.getNumberSections() and chapterNumber: nodeList[0].childNodes.append(microdom.Text('%s. ' % chapterNumber)) nodeList[0].childNodes.extend(title)
def munge(document, template, linkrel, dir, fullpath, ext, url, config, outfileGenerator=getOutputFileName): fixRelativeLinks(template, linkrel) addMtime(template, fullpath) removeH1(document) if not config.get('noapi', False): fixAPI(document, url) fontifyPython(document) fixLinks(document, ext) addPyListings(document, dir) addHTMLListings(document, dir) addPlainListings(document, dir) putInToC(template, generateToC(document)) footnotes(document) notes(document) setIndexLink(template, indexer.getIndexFilename()) setVersion(template, config.get('version', '')) # Insert the document into the template chapterNumber = htmlbook.getNumber(fullpath) title = domhelpers.findNodesNamed(document, 'title')[0].childNodes setTitle(template, title, chapterNumber) if numberer.getNumberSections() and chapterNumber: numberDocument(document, chapterNumber) index(document, outfileGenerator(os.path.split(fullpath)[1], ext), htmlbook.getReference(fullpath)) authors = domhelpers.findNodesNamed(document, 'link') authors = [(node.getAttribute('title',''), node.getAttribute('href', '')) for node in authors if node.getAttribute('rel', '') == 'author'] setAuthors(template, authors) body = domhelpers.findNodesNamed(document, "body")[0] tmplbody = domhelpers.findElementsWithAttribute(template, "class", "body")[0] tmplbody.childNodes = body.childNodes tmplbody.setAttribute("class", "content")
def setTitle(template, title, chapterNumber): """ Add title and chapter number information to the template document. The title is added to the end of the first C{title} tag and the end of the first tag with a C{class} attribute set to C{title}. If specified, the chapter is inserted before the title. @type template: A DOM Node or Document @param template: The output template which defines the presentation of the version information. @type title: C{list} of DOM Nodes @param title: Nodes from the input document defining its title. @type chapterNumber: C{int} @param chapterNumber: The chapter number of this content in an overall document. If not applicable, any C{False} value will result in this information being omitted. @return: C{None} """ if numberer.getNumberSections() and chapterNumber: titleNode = dom.Text() # This is necessary in order for cloning below to work. See Python # isuse 4851. titleNode.ownerDocument = template.ownerDocument titleNode.data = '%s. ' % (chapterNumber, ) title.insert(0, titleNode) for nodeList in (domhelpers.findNodesNamed(template, "title"), domhelpers.findElementsWithAttribute( template, "class", 'title')): if nodeList: for titleNode in title: nodeList[0].appendChild(titleNode.cloneNode(True))
def setTitle(template, title, chapterNumber): """ Add title and chapter number information to the template document. The title is added to the end of the first C{title} tag and the end of the first tag with a C{class} attribute set to C{title}. If specified, the chapter is inserted before the title. @type template: A DOM Node or Document @param template: The output template which defines the presentation of the version information. @type title: C{list} of DOM Nodes @param title: Nodes from the input document defining its title. @type chapterNumber: C{int} @param chapterNumber: The chapter number of this content in an overall document. If not applicable, any C{False} value will result in this information being omitted. @return: C{None} """ if numberer.getNumberSections() and chapterNumber: titleNode = dom.Text() # This is necessary in order for cloning below to work. See Python # isuse 4851. titleNode.ownerDocument = template.ownerDocument titleNode.data = '%s. ' % (chapterNumber,) title.insert(0, titleNode) for nodeList in (domhelpers.findNodesNamed(template, "title"), domhelpers.findElementsWithAttribute(template, "class", 'title')): if nodeList: for titleNode in title: nodeList[0].appendChild(titleNode.cloneNode(True))
def munge(document, template, linkrel, dir, fullpath, ext, url, config, outfileGenerator=getOutputFileName): """ Mutate C{template} until it resembles C{document}. @type document: A DOM Node or Document @param document: The input document which contains all of the content to be presented. @type template: A DOM Node or Document @param template: The template document which defines the desired presentation format of the content. @type linkrel: C{str} @param linkrel: An prefix to apply to all relative links in C{src} or C{href} attributes in the input document when generating the output document. @type dir: C{str} @param dir: The directory in which to search for source listing files. @type fullpath: C{str} @param fullpath: The file name which contained the input document. @type ext: C{str} @param ext: The extension to use when selecting an output file name. This replaces the extension of the input file name. @type url: C{str} @param url: A string which will be interpolated with the fully qualified Python name of any API reference encountered in the input document, the result of which will be used as a link to API documentation for that name in the output document. @type config: C{dict} @param config: Further specification of the desired form of the output. Valid keys in this dictionary:: noapi: If present and set to a True value, links to API documentation will not be generated. version: A string which will be included in the output to indicate the version of this documentation. @type outfileGenerator: Callable of C{str}, C{str} returning C{str} @param outfileGenerator: Output filename factory. This is invoked with the intput filename and C{ext} and the output document is serialized to the file with the name returned. @return: C{None} """ fixRelativeLinks(template, linkrel) addMtime(template, fullpath) removeH1(document) if not config.get("noapi", False): fixAPI(document, url) fontifyPython(document) fixLinks(document, ext) addPyListings(document, dir) addHTMLListings(document, dir) addPlainListings(document, dir) putInToC(template, generateToC(document)) footnotes(document) notes(document) setIndexLink(template, indexer.getIndexFilename()) setVersion(template, config.get("version", "")) # Insert the document into the template chapterNumber = htmlbook.getNumber(fullpath) title = domhelpers.findNodesNamed(document, "title")[0].childNodes setTitle(template, title, chapterNumber) if numberer.getNumberSections() and chapterNumber: numberDocument(document, chapterNumber) index(document, outfileGenerator(os.path.split(fullpath)[1], ext), htmlbook.getReference(fullpath)) authors = domhelpers.findNodesNamed(document, "link") authors = [ (node.getAttribute("title", ""), node.getAttribute("href", "")) for node in authors if node.getAttribute("rel", "") == "author" ] setAuthors(template, authors) body = domhelpers.findNodesNamed(document, "body")[0] tmplbody = domhelpers.findElementsWithAttribute(template, "class", "body")[0] tmplbody.childNodes = body.childNodes tmplbody.setAttribute("class", "content")
def munge(document, template, linkrel, dir, fullpath, ext, url, config, outfileGenerator=getOutputFileName): """ Mutate C{template} until it resembles C{document}. @type document: A DOM Node or Document @param document: The input document which contains all of the content to be presented. @type template: A DOM Node or Document @param template: The template document which defines the desired presentation format of the content. @type linkrel: C{str} @param linkrel: An prefix to apply to all relative links in C{src} or C{href} attributes in the input document when generating the output document. @type dir: C{str} @param dir: The directory in which to search for source listing files. @type fullpath: C{str} @param fullpath: The file name which contained the input document. @type ext: C{str} @param ext: The extension to use when selecting an output file name. This replaces the extension of the input file name. @type url: C{str} @param url: A string which will be interpolated with the fully qualified Python name of any API reference encountered in the input document, the result of which will be used as a link to API documentation for that name in the output document. @type config: C{dict} @param config: Further specification of the desired form of the output. Valid keys in this dictionary:: noapi: If present and set to a True value, links to API documentation will not be generated. version: A string which will be included in the output to indicate the version of this documentation. @type outfileGenerator: Callable of C{str}, C{str} returning C{str} @param outfileGenerator: Output filename factory. This is invoked with the intput filename and C{ext} and the output document is serialized to the file with the name returned. @return: C{None} """ fixRelativeLinks(template, linkrel) addMtime(template, fullpath) removeH1(document) if not config.get('noapi', False): fixAPI(document, url) fontifyPython(document) fixLinks(document, ext) addPyListings(document, dir) addHTMLListings(document, dir) addPlainListings(document, dir) putInToC(template, generateToC(document)) footnotes(document) notes(document) setIndexLink(template, indexer.getIndexFilename()) setVersion(template, config.get('version', '')) # Insert the document into the template chapterNumber = htmlbook.getNumber(fullpath) title = domhelpers.findNodesNamed(document, 'title')[0].childNodes setTitle(template, title, chapterNumber) if numberer.getNumberSections() and chapterNumber: numberDocument(document, chapterNumber) index(document, outfileGenerator(os.path.split(fullpath)[1], ext), htmlbook.getReference(fullpath)) authors = domhelpers.findNodesNamed(document, 'link') authors = [(node.getAttribute('title') or '', node.getAttribute('href') or '') for node in authors if node.getAttribute('rel') == 'author'] setAuthors(template, authors) body = domhelpers.findNodesNamed(document, "body")[0] tmplbody = domhelpers.findElementsWithAttribute(template, "class", "body")[0] tmplbody.childNodes = body.childNodes tmplbody.setAttribute("class", "content")