示例#1
0
    def render(self, nodes, document):

        new_document = document.copy()

        new_document.children = nodes

        writer = TextWriter(TextBuilder(self.app))
        output = writer.write(new_document, FakeDestination())

        return output.strip()
示例#2
0
 def write(self, *ignored):
     writer = TextWriter(self)
     for label in self.status_iterator(pydoc_topic_labels, 'building topics... '):
         if label not in self.env.labels:
             self.warn('label %r not in documentation' % label)
             continue
         docname, labelid, sectname = self.env.labels[label]
         doctree = self.env.get_and_resolve_doctree(docname, self)
         document = new_document('<section node>')
         document.append(doctree.ids[labelid])
         destination = StringOutput(encoding='utf-8')
         writer.write(document, destination)
         self.topics[label] = writer.output
示例#3
0
    def format_description(self, lines: List[str]) -> str:
        """Format tables and fields descriptions from ReST to plain text."""

        # Unwrap lines
        unwrapped_lines = []
        for line in lines:
            empty = not unwrapped_lines or not unwrapped_lines[-1] or not line
            list_item = line and line.startswith('- ')
            block_start = (line and line.startswith('  ') and not empty
                           and not unwrapped_lines[-1].startswith('  '))
            if empty or list_item or block_start:
                unwrapped_lines.append(line)
            else:
                unwrapped_lines[-1] += ' ' + line.lstrip()

        # Manually format and remove useless information
        clean_lines = []
        for line in unwrapped_lines:
            line = line.replace(':class:', '')
            if not line:
                if clean_lines and clean_lines[-1]:
                    clean_lines.append(line)
                continue
            elif re.match('^:[A-Za-z ]*:', line):
                continue
            elif line.startswith('.. versionadded::'):
                continue
            elif line.startswith('See '):
                continue
            clean_lines.append(line)
        source = '\n'.join(clean_lines).strip()

        # Transform ReST into plain text
        writer = TextWriter(self)
        plain_text = publish_string(source=source.encode('utf-8'),
                                    writer=writer).decode('utf-8')
        plain_text = plain_text.replace('\n\n* ',
                                        '\n− ')  # Use hyphens as list bullets

        # Split description and points of interest
        lines = plain_text.split('\n')
        if len(lines) > 2 and lines[1] == '':
            return lines[0].strip(), '\n'.join(lines[2:]).strip()
        else:
            return '\n'.join(lines).strip(), None
 def write(self, *ignored):
     try:  # sphinx>=1.6
         from sphinx.util import status_iterator
     except ImportError:  # sphinx<1.6
         status_iterator = self.status_iterator
     writer = TextWriter(self)
     for label in status_iterator(pydoc_topic_labels,
                                       'building topics... ',
                                       length=len(pydoc_topic_labels)):
         if label not in self.env.domaindata['std']['labels']:
             self.warn('label %r not in documentation' % label)
             continue
         docname, labelid, sectname = self.env.domaindata['std']['labels'][label]
         doctree = self.env.get_and_resolve_doctree(docname, self)
         document = new_document('<section node>')
         document.append(doctree.ids[labelid])
         destination = StringOutput(encoding='utf-8')
         writer.write(document, destination)
         self.topics[label] = writer.output
示例#5
0
 def prepare_writing(self, docnames):
     # type: (Set[unicode]) -> None
     self.writer = TextWriter(self)
示例#6
0
 def prepare_writing(self, docnames):
     self.writer = TextWriter(self)
示例#7
0
文件: text.py 项目: jfbu/sphinx
 def prepare_writing(self, docnames: Set[str]) -> None:
     self.writer = TextWriter(self)