sphinx-prompt with confluence-builder?

37 views
Skip to first unread message

Ron Stone

unread,
Sep 23, 2021, 10:37:45 AM9/23/21
to sphinx-users
Hi,

Trying to combine sphinx-prompt (for standardized, non selectable prompts) and confluence-builder is resulting in no content appearing where code should be displayed in the output when the viewing the published confluence pages.

Has anyone gotten them working together? 

Thanks!

James Knight

unread,
Nov 19, 2021, 6:21:14 PM11/19/21
to sphinx-users
Ron,

On Thursday, September 23, 2021 at 10:37:45 AM UTC-4 Ron Stone wrote:
Trying to combine sphinx-prompt (for standardized, non selectable prompts) and confluence-builder is resulting in no content appearing where code should be displayed in the output when the viewing the published confluence pages.

Has anyone gotten them working together?

Unfortunately, the sphinx-prompt extension only generates raw HTML (or LaTeX) nodes, which cannot be processed by the sphinxcontrib-confluencebuilder extension (hence why the empty blocks).

A crude workaround if you wanted you target multiple builders (e.g. HTML and Confluence), you could inject the following in your documentation's configuration:

```
from docutils import nodes
import importlib

sphinx_prompt = importlib.import_module('sphinx-prompt')

class PromptDirectiveOverride(sphinx_prompt.PromptDirective):
    def run(self):
        text = '\n'.join(self.content)
        lang = self.options.get('language') or 'text'

        new_node = nodes.literal_block(text, text)
        new_node['language'] = lang
        return [ new_node ]

def setup(app):
    app.connect('builder-inited', builder_inited)

def builder_inited(app):
    if app.builder.name not in ('html', 'latex'):
        app.add_directive('prompt', PromptDirectiveOverride, override=True)
```

Note that this only makes a simple literal block for this sections so content can be processing by the translator (e.g. Confluence will generate code blocks). You would not gain the advantage of non-selectable prompts in Confluence; however, you will at least be able to see the content in Confluence.
Reply all
Reply to author
Forward
0 new messages