Custom writer specified in conf.py

41 views
Skip to first unread message

Dan Sandberg

unread,
May 24, 2022, 5:26:13 PM5/24/22
to sphinx-users
From posts like:


It seems like in the past you could specify a custom writer by setting the html_translator_class attribute in conf.py.

Is there any replacement that can be done through the conf.py configuration rather than by programatically creating a sphinx instance?

I'm trying to modify the HTML output without changing the source-code itself, and without creating a python instance so that I can continue to use the command line tools like sphinx-build.

Thanks,

-Dan

Jean Abou Samra

unread,
May 25, 2022, 11:44:53 AM5/25/22
to sphinx...@googlegroups.com, Dan Sandberg

Dan Sandberg

unread,
May 25, 2022, 1:23:53 PM5/25/22
to Jean Abou Samra, sphinx...@googlegroups.com
Hi Jean,

Thanks for the reply.  I saw that, but how do you use it from the config file?  If there's no way, then it isn't really a replacement.

Thanks,

-Dan

Jean Abou Samra

unread,
May 25, 2022, 3:06:42 PM5/25/22
to sphinx...@googlegroups.com, Dan Sandberg
Le 25/05/2022 à 19:23, Dan Sandberg a écrit :
> Hi Jean,
>
> Thanks for the reply.  I saw that, but how do you use it from the
> config file?  If there's no way, then it isn't really a replacement.


The setup() function in the configuration file takes the application
object and can mutate it. For example, this code in conf.py would
interpret all emphasis markup as bold:


from sphinx.writers.html import HTMLTranslator

class MyTranslator(HTMLTranslator):
    def visit_emphasis(self, node):
        self.visit_strong(node)
    def depart_emphasis(self, node):
        self.depart_strong(node)

def setup(app):
    app.set_translator('html', MyTranslator)


Dan Sandberg

unread,
May 25, 2022, 3:56:47 PM5/25/22
to sphinx...@googlegroups.com
Thanks Jean -- that's exactly what I needed.  I looked at the source-code but didn't see where the conf file was being used in an executable way.

I'll update the Stackoverflow question with your answer.

Thanks again,

-Dan

--
You received this message because you are subscribed to a topic in the Google Groups "sphinx-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sphinx-users/tjyi1dtqpRA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sphinx-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sphinx-users/8f2a219c-bf5a-2e9d-2903-b30fae8e64b3%40abou-samra.fr.
Reply all
Reply to author
Forward
0 new messages