First of all, I am very sorry for the late reply, I have been quite busy.
The good news is, however, that I made some more tests and I was able to have the ".. altrubric:: test" produce a \subsection*{test} in the latex output, as I wanted.
Unfortunately, in the HTML the .. altrubric:: directive produces only a <p class="rubric">test</p>, which is unexpected and I have no idea how I could fix.
The code is the following, adapted from a few examples found in this group and elsewhere:
*****
class altrubric(nodes.rubric):
pass
def visit_altrubric(self, node):
# type: (nodes.Element) -> None
if len(node) == 1 and node.astext() in ('Footnotes', _('Footnotes')):
raise nodes.SkipNode
self.body.append('\\subsubsection*{')
self.context.append('}\n')
self.in_title = 1
def depart_altrubric(self, node):
# type: (nodes.Element) -> None
self.in_title = 0
self.body.append(self.context.pop())
def visit_altrubric_html(self, node):
self.body.append(self.starttag(node, 'rubric', '',
CLASS='rubric altrubric'))
def depart_altrubric_html(self, node):
pass
class AltRubricDirective(SphinxDirective):
has_content = False
required_arguments = 1
def run(self):
set_classes(self.options)
altrubric_text = self.arguments[0]
textnodes, messages = self.state.inline_text(altrubric_text, self.lineno)
altrubric = nodes.rubric(altrubric_text, '', *textnodes, **self.options)
self.add_name(altrubric)
return [altrubric] + messages
def setup(app):
app.add_node(altrubric,
html=(visit_altrubric_html, depart_altrubric_html),
epub=(visit_altrubric, depart_altrubric),
latex=(visit_altrubric, depart_altrubric))
*****
I also tried to move visit_altrubric_html, depart_altrubric_html to the html.py writer class, without any change in the output. Same result even using other examples from the html builder, like e.g. atts['class'] += 'altrubric'. I also tried to add the class directly in the class altrubric(nodes.rubric), again with no results.
No, it does not seem to help in this case, because the container creates a <div> <p>...</p></div>, while the rubric a single <p class="rubric altrubric">..</p> which for some reasons receives only the rubric's CSS and the .altrubric>:before CSS rule does not work anymore. (but this is a problem which is OT here and I can not investigate right now, because it would require quite a number of changes).
Thank you and best regards,
Stefano