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

An official way to add extra Confluence nodes #970

Closed
neongreen-sc opened this issue May 23, 2024 · 4 comments
Closed

An official way to add extra Confluence nodes #970

neongreen-sc opened this issue May 23, 2024 · 4 comments
Labels
enhancement Something that can better improve this extension

Comments

@neongreen-sc
Copy link

Right now it looks like you can add extra nodes without modifying the extension, but it depends on private methods of the translator.

Example for the panel macro:

from docutils import nodes
from sphinxcontrib.confluencebuilder.storage.translator import (
    ConfluenceStorageFormatTranslator,
)

def setup(app: Sphinx):
    app.add_node(
        confluence_panel,
        confluence=(visit_confluence_panel, depart_confluence_panel),
    )

class confluence_panel(nodes.General, nodes.Element):
    pass

def visit_confluence_panel(
    self: ConfluenceStorageFormatTranslator, node: confluence_panel
):
    self.body.append(self._start_ac_macro(node, "panel"))
    if "title" in node:
        self.body.append(self._build_ac_param(node, "title", node["title"]))
    self.body.append(self._start_ac_rich_text_body_macro(node))
    self.context.append(
        self._end_ac_rich_text_body_macro(node) + self._end_ac_macro(node)
    )

def depart_confluence_panel(
    self: ConfluenceStorageFormatTranslator, node: confluence_panel
):
    self.body.append(self.context.pop())

Is there a better way to do this?

@jdknight
Copy link
Member

The approach made is in general the way to inject custom modifications for individual documentation configurations.

If the main concern is trying to avoid the use of internal calls of this extension, an (untested) alternative would be to just perform something such as the following:

    self.body.append('<ac:structured-macro ac:name="panel">')
    if "title" in node:
        self.body.append('<ac:parameter ac:name="title">{}</ac:parameter>'.format(node["title"]))
    self.body.append('<ac:rich-text-body>')
    self.context.append('</ac:rich-text-body></ac:structured-macro>')

Calls such as _start_ac_macro, _build_ac_param, etc. were left internal solely since there was plan to support both Confluence storage and ADF formatting in this extension. Although, progression to support ADF was stopped mainly due to the confirmation that storage format was not going to be removed (at the time when they were introduced the v2 "fabric" editor).

We could look at providing "proper" API calls to help support custom modifications for users and other extensions wanting to use helper calls such as the ones mentioned.

@neongreen-sc
Copy link
Author

For me, either proper API calls, or documentation on supporting custom Confluence nodes would be lovely. I'm worried about someone else inheriting my Sphinx code and not being able to figure out what's going on.

@jdknight jdknight self-assigned this Jun 22, 2024
@jdknight
Copy link
Member

Changes have been introduced in this extension to adjust various "internal" helper calls to be "public" calls (#989). Also added an initial document to provide a general overview and pull documentation for the helper calls from source.

@jdknight jdknight removed their assignment Jun 23, 2024
@jdknight jdknight added enhancement Something that can better improve this extension available-next-release Merged into the main branch but waiting for PyPI release labels Jun 23, 2024
@jdknight
Copy link
Member

v2.6 is now available on PyPI -- marking as closed.

@jdknight jdknight removed the available-next-release Merged into the main branch but waiting for PyPI release label Jul 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Something that can better improve this extension
Projects
None yet
Development

No branches or pull requests

2 participants