nodes.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:chalktalk_docs 作者: loremIpsum1771 项目源码 文件源码
def apply_source_workaround(node):
    # workaround: nodes.term have wrong rawsource if classifier is specified.
    # The behavior of docutils-0.11, 0.12 is:
    # * when ``term text : classifier1 : classifier2`` is specified,
    # * rawsource of term node will have: ``term text : classifier1 : classifier2``
    # * rawsource of classifier node will be None
    if isinstance(node, nodes.classifier) and not node.rawsource:
        definition_list_item = node.parent
        node.source = definition_list_item.source
        node.line = definition_list_item.line - 1
        node.rawsource = node.astext()  # set 'classifier1' (or 'classifier2')
    if isinstance(node, nodes.term):
        # strip classifier from rawsource of term
        for classifier in reversed(node.parent.traverse(nodes.classifier)):
            node.rawsource = re.sub(
                '\s*:\s*%s' % re.escape(classifier.astext()), '', node.rawsource)

    # workaround: recommonmark-0.2.0 doesn't set rawsource attribute
    if not node.rawsource:
        node.rawsource = node.astext()

    if node.source and node.rawsource:
        return

    # workaround: docutils-0.10.0 or older's nodes.caption for nodes.figure
    # and nodes.title for nodes.admonition doesn't have source, line.
    # this issue was filed to Docutils tracker:
    # sf.net/tracker/?func=detail&aid=3599485&group_id=38414&atid=422032
    # sourceforge.net/p/docutils/patches/108/
    if (isinstance(node, (
            nodes.caption,
            nodes.title,
            nodes.rubric,
            nodes.line,
    ))):
        node.source = find_source_node(node)
        node.line = 0  # need fix docutils to get `node.line`
        return
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号