Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sphinx.ext.doctest] set language for doctest blocks #4137

Closed
wojdyr opened this issue Oct 10, 2017 · 1 comment
Closed

[sphinx.ext.doctest] set language for doctest blocks #4137

wojdyr opened this issue Oct 10, 2017 · 1 comment
Labels
extensions type:proposal a feature suggestion
Milestone

Comments

@wojdyr
Copy link
Contributor

wojdyr commented Oct 10, 2017

It would be nice to have the language of doctest blocks set to Python.
It matters in documents that have highlight_language set to something else (in my case c++).
I think in such cases it's currently necessary is to use the highlight directive before (and after) doctests.

It's not very convenient, so I monkey-patched it in my conf.py:

import sphinx.ext.doctest
def DoctestDirective_run(self):
    nodes = sphinx.ext.doctest.TestDirective.run(self)
    nodes[0]['language'] = 'pycon'
    return nodes
sphinx.ext.doctest.DoctestDirective.run = DoctestDirective_run

but it'd be more elegant to have it in ext/doctest.py, maybe next to these lines:

    if self.name == 'testoutput':
        # don't try to highlight output
        node['language'] = 'none'
@tk0miya
Copy link
Member

tk0miya commented Oct 12, 2017

Good point!

@tk0miya tk0miya added extensions type:proposal a feature suggestion labels Oct 12, 2017
@tk0miya tk0miya added this to the 1.7 milestone Oct 12, 2017
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 14, 2018
tk0miya added a commit that referenced this issue Jan 14, 2018
Fix #4137: doctest: doctest block is always highlighted as python con…
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
extensions type:proposal a feature suggestion
Projects
None yet
Development

No branches or pull requests

2 participants