当前位置: 首页>>代码示例>>Python>>正文


Python Writer.document方法代码示例

本文整理汇总了Python中docutils.writers.html4css1.Writer.document方法的典型用法代码示例。如果您正苦于以下问题:Python Writer.document方法的具体用法?Python Writer.document怎么用?Python Writer.document使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在docutils.writers.html4css1.Writer的用法示例。


在下文中一共展示了Writer.document方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parse

# 需要导入模块: from docutils.writers.html4css1 import Writer [as 别名]
# 或者: from docutils.writers.html4css1.Writer import document [as 别名]
    def parse(self, content):
        settings = OptionParser(components=(Parser, Writer)) \
                   .get_default_values()
        doc = new_document('doc', settings)
        parser = Parser()
        parser.parse(content, doc)

        stories = []
        for node in doc:
            if isinstance(node, docutils.nodes.section):
                # Каждая секция - это история
                if isinstance(node[0], docutils.nodes.title):
                    story_title = node.pop(0).astext()
                else:
                    warnings.warn('Найдена история без заголовка: %r' % node)
                    continue

                tasks = []
                points = None
                if isinstance(node[-1], docutils.nodes.bullet_list):
                    # Задачи расположены в списке в конце истории
                    tasklist = node.pop()
                    for line in tasklist:
                        line = line.astext()
                        # Оценка задачи указывается в круглых скобках в самом
                        # конце, слово "дней" опционально.
                        match = re.search(ur'^.+\((\d+)[^\)]{0,5}\)$', line,
                                          re.UNICODE | re.DOTALL)
                        if match:
                            points = int(match.group(1))
                            line = re.sub(ur'^(.+?)\(\d+[^\)]{0,5}\)$', r'\1',
                                          line)
                        else:
                            points = 0

                        # Ответственный указывается перед задачей и отделяется
                        # двоеточием.
                        match = re.search(ur'^\+?([\w]+):\s*(.+)$', line,
                                          re.UNICODE | re.DOTALL)
                        if match:
                            person = match.group(1)
                            task_title = match.group(2)
                            state = Task.WORK
                        else:
                            task_title = line
                            person = None
                            state = Task.NEW

                        if line.startswith('+'):
                            state = Task.DONE

                        task = Task(task_title, state, person=person, points=points)
                        tasks.append(task)

                # Все остальное в истории - ее описание.
                writer = Writer()
                pseudo_doc = new_document(story_title, settings)
                pseudo_doc.children = [node]
                writer.document = pseudo_doc
                writer.translate()
                description = ''.join(writer.body)

                stories.append(Story(story_title, description, tasks))

        return stories
开发者ID:alexmorozov,项目名称:pyscrum,代码行数:67,代码来源:loaders.py

示例2: translate_to_parts

# 需要导入模块: from docutils.writers.html4css1 import Writer [as 别名]
# 或者: from docutils.writers.html4css1.Writer import document [as 别名]
def translate_to_parts(document):
  writer = Writer()
  writer.document = document
  writer.translate()
  writer.assemble_parts()
  return dict(writer.parts)
开发者ID:bossjones,项目名称:etc-python,代码行数:8,代码来源:simple2.py


注:本文中的docutils.writers.html4css1.Writer.document方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。