Links from SVG images: Detail: How to call a super method of an overwritten Tranlator?

11 views
Skip to first unread message

Volker Jaenisch

unread,
Feb 18, 2024, 6:38:25 PMFeb 18
to sphinx-dev
In my patch of MsytParser I like to overwrite the standard behavior of the hmtl Translator in sphinx for the formation of the image node.

    # override only the html writer visit methods for image,
    # to react on image-link classes
    app.add_node(
        nodes.image,
        override=True,
        html=(visit_image_html, depart_image_html),
    )

This overwrite works well, the overwriting function is called.

The overwriting function is here and it should do nothing but call the original bahavior.

# This will become the overwrite
def visit_image_html(self, node: nodes.Node):
    return self.visit_image(node)

But how do I call the standard behavior? The above version leads as expected to an infinite recursion.

def visit_image_html(self, node: nodes.Node):
    return super(self).visit_image(node)

Does not work either.

Any help is truly appreciated.

Cheers,
Volker

danwos

unread,
Feb 19, 2024, 4:32:48 AMFeb 19
to sphinx-dev
I think you need to import the original "visit_image()" function first, under a different name.

Some pseudo-code, as I haven't looked into the Sphinx code to identify the correct modules:

from sphinx.images import visit_image as org_visit_image

def visit_image_html(self, node: nodes.Node):
    return org_visit_image(node)

I hope this goes in the right direction.

Cheers,
  Danielöö

Volker Jaenisch

unread,
Feb 20, 2024, 4:30:11 AMFeb 20
to sphinx-dev
Dear Danielöö!

Thank you for the hints.

> I think you need to import the original "visit_image()" function first, under a different name.

Unfortunately the function visit_image() is a member function of the HTML5-Writer class. And therfore not importable.

Cheers,
Volker
Reply all
Reply to author
Forward
0 new messages