Exemple #1
0
    def apply(self, **kwargs):
        # type: (Any) -> None
        for math_node in self.document.traverse(nodes.math):
            # case: old styled ``math`` node generated by old extensions
            if len(math_node) == 0:
                warnings.warn(
                    "math node for Sphinx was replaced by docutils'. "
                    "Please use ``docutils.nodes.math`` instead.",
                    RemovedInSphinx30Warning)
                equation = math_node['latex']
                math_node += nodes.Text(equation, equation)

        translator = self.app.builder.get_translator_class()
        if hasattr(translator,
                   'visit_displaymath') and translator != XMLTranslator:
            # case: old translators which does not support ``math_block`` node
            warnings.warn(
                "Translator for %s does not support math_block node'. "
                "Please update your extension." % translator,
                RemovedInSphinx30Warning)
            for old_math_block_node in self.document.traverse(math_block):
                alt = displaymath(latex=old_math_block_node.astext(),
                                  number=old_math_block_node.get('number'),
                                  label=old_math_block_node.get('label'),
                                  nowrap=old_math_block_node.get('nowrap'),
                                  docname=old_math_block_node.get('docname'))
                old_math_block_node.replace_self(alt)
        elif getattr(self.app.builder, 'math_renderer_name',
                     None) == 'unknown':
            # case: math extension provides old styled math renderer
            for math_block_node in self.document.traverse(nodes.math_block):
                math_block_node['latex'] = math_block_node.astext()

        # case: old styled ``displaymath`` node generated by old extensions
        for math_block_node in self.document.traverse(math_block):
            if len(math_block_node) == 0:
                warnings.warn(
                    "math node for Sphinx was replaced by docutils'. "
                    "Please use ``docutils.nodes.math_block`` instead.",
                    RemovedInSphinx30Warning)
                if isinstance(math_block_node, displaymath):
                    newnode = nodes.math_block('', math_block_node['latex'],
                                               **math_block_node.attributes)
                    math_block_node.replace_self(newnode)
                else:
                    latex = math_block_node['latex']
                    math_block_node += nodes.Text(latex, latex)
Exemple #2
0
    def apply(self, **kwargs):
        # type: (Any) -> None
        for math_node in self.document.traverse(nodes.math):
            # case: old styled ``math`` node generated by old extensions
            if len(math_node) == 0:
                warnings.warn("math node for Sphinx was replaced by docutils'. "
                              "Please use ``docutils.nodes.math`` instead.",
                              RemovedInSphinx30Warning)
                equation = math_node['latex']
                math_node += nodes.Text(equation, equation)

        translator = self.app.builder.get_translator_class()
        if hasattr(translator, 'visit_displaymath') and translator != XMLTranslator:
            # case: old translators which does not support ``math_block`` node
            warnings.warn("Translator for %s does not support math_block node'. "
                          "Please update your extension." % translator,
                          RemovedInSphinx30Warning)
            for old_math_block_node in self.document.traverse(math_block):
                alt = displaymath(latex=old_math_block_node.astext(),
                                  number=old_math_block_node.get('number'),
                                  label=old_math_block_node.get('label'),
                                  nowrap=old_math_block_node.get('nowrap'),
                                  docname=old_math_block_node.get('docname'))
                old_math_block_node.replace_self(alt)
        elif getattr(self.app.builder, 'math_renderer_name', None) == 'unknown':
            # case: math extension provides old styled math renderer
            for math_block_node in self.document.traverse(nodes.math_block):
                math_block_node['latex'] = math_block_node.astext()

        # case: old styled ``displaymath`` node generated by old extensions
        for math_block_node in self.document.traverse(math_block):
            if len(math_block_node) == 0:
                warnings.warn("math node for Sphinx was replaced by docutils'. "
                              "Please use ``docutils.nodes.math_block`` instead.",
                              RemovedInSphinx30Warning)
                if isinstance(math_block_node, displaymath):
                    newnode = nodes.math_block('', math_block_node['latex'],
                                               **math_block_node.attributes)
                    math_block_node.replace_self(newnode)
                else:
                    latex = math_block_node['latex']
                    math_block_node += nodes.Text(latex, latex)
Exemple #3
0
    def apply(self):
        # type: () -> None
        for node in self.document.traverse(nodes.math):
            # case: old styled ``math`` node generated by old extensions
            if len(node) == 0:
                warnings.warn(
                    "math node for Sphinx was replaced by docutils'. "
                    "Please use ``docutils.nodes.math`` instead.",
                    RemovedInSphinx30Warning)
                equation = node['latex']
                node += nodes.Text(equation, equation)

        translator = self.app.builder.get_translator_class()
        if hasattr(translator,
                   'visit_displaymath') and translator != XMLTranslator:
            # case: old translators which does not support ``math_block`` node
            warnings.warn(
                "Translator for %s does not support math_block node'. "
                "Please update your extension." % translator,
                RemovedInSphinx30Warning)
            for node in self.document.traverse(math_block):
                alt = displaymath(latex=node.astext(),
                                  number=node.get('number'),
                                  label=node.get('label'),
                                  nowrap=node.get('nowrap'),
                                  docname=node.get('docname'))
                node.replace(alt)
        else:
            # case: old styled ``displaymath`` node generated by old extensions
            for node in self.document.traverse(math_block):
                if len(node) == 0:
                    warnings.warn(
                        "math node for Sphinx was replaced by docutils'. "
                        "Please use ``docutils.nodes.math_block`` instead.",
                        RemovedInSphinx30Warning)
                    latex = node['latex']
                    node += nodes.Text(latex, latex)