[Docstring-checkins] CVS: dps/dps/transforms frontmatter.py,1.3,1.4
Status: Pre-Alpha
Brought to you by:
goodger
From: David G. <go...@us...> - 2002-02-12 02:18:01
|
Update of /cvsroot/docstring/dps/dps/transforms In directory usw-pr-cvs1:/tmp/cvs-serv31109/dps/dps/transforms Modified Files: frontmatter.py Log Message: refactored a bit Index: frontmatter.py =================================================================== RCS file: /cvsroot/docstring/dps/dps/transforms/frontmatter.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** frontmatter.py 6 Feb 2002 02:51:57 -0000 1.3 --- frontmatter.py 12 Feb 2002 02:17:56 -0000 1.4 *************** *** 110,148 **** def promote_document_title(self): ! doctree = self.doctree ! index = doctree.findnonclass((nodes.comment, nodes.system_warning)) ! if self.check_promotion_candidate(index): ! candidate = doctree[index] ! else: return None ! doctree.attributes.update(candidate.attributes) ! doctree[:] = candidate[:1] + doctree[:index] + candidate[1:] return 1 def promote_document_subtitle(self): ! doctree = self.doctree ! # Check for a lone second-level section. ! index = doctree.findnonclass((nodes.comment, nodes.system_warning, ! nodes.title)) # skip the new title ! if self.check_promotion_candidate(index): ! candidate = doctree[index] ! else: return None - # Create a subtitle element based on the title element: subtitle = nodes.subtitle() ! subtitle.attributes.update(candidate[0].attributes) ! subtitle[:] = candidate[0][:] ! # Put the subtitle element into the doctree ! doctree[:] = doctree[:1] + [subtitle] + doctree[1:index] + candidate[1:] return 1 ! def check_promotion_candidate(self, index): """ ! Return 1 iff the index'th child of node should be promoted. """ ! if index is None or len(self.doctree) > (index + 1) or \ ! not isinstance(self.doctree[index], nodes.section): ! return None ! return 1 --- 110,155 ---- def promote_document_title(self): ! section, index = self.candidate_index() ! if index is None: return None ! doctree = self.doctree ! # Transfer the section's attributes to the document element (at root): ! doctree.attributes.update(section.attributes) ! doctree[:] = (section[:1] # section title ! + doctree[:index] # everything that was in the document ! # before the section ! + section[1:]) # everything that was in the section return 1 def promote_document_subtitle(self): ! subsection, index = self.candidate_index() ! if index is None: return None subtitle = nodes.subtitle() ! # Transfer the subsection's attributes to the new subtitle: ! subtitle.attributes.update(subsection.attributes) ! # Transfer the contents of the subsection's title to the subtitle: ! subtitle[:] = subsection[0][:] ! doctree = self.doctree ! doctree[:] = (doctree[:1] # document title ! + [subtitle] ! + doctree[1:index] # everything that was in the document ! # before the section ! + subsection[1:]) # everything that was in the subsection return 1 ! def candidate_index(self): """ ! Find and return the promotion candidate and its index. ! ! Return (None, None) if no valid candidate was found. """ ! doctree = self.doctree ! index = doctree.findnonclass(nodes.PreBibliographic) ! if index is None or len(doctree) > (index + 1) or \ ! not isinstance(doctree[index], nodes.section): ! return None, None ! else: ! return doctree[index], index *************** *** 223,233 **** def process_docinfo(self): doctree = self.doctree ! index = doctree.findnonclass((nodes.title, nodes.subtitle, ! nodes.comment, nodes.system_warning)) if index is None: return candidate = doctree[index] if isinstance(candidate, nodes.field_list): ! biblioindex = doctree.findnonclass((nodes.title, nodes.subtitle)) nodelist, remainder = self.extract_bibliographic(candidate) if remainder: --- 230,239 ---- def process_docinfo(self): doctree = self.doctree ! index = doctree.findnonclass(nodes.PreBibliographic) if index is None: return candidate = doctree[index] if isinstance(candidate, nodes.field_list): ! biblioindex = doctree.findnonclass(nodes.Titular) nodelist, remainder = self.extract_bibliographic(candidate) if remainder: |