Hi,

It seems your code does not use `altrubric` node in AltRubricDirective.
Let's look into AltRubric.run():

>    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

It generates a node via `nodes.rubric()`. It should be replaced by
`altrubric` class instead.

On my local, it works fine with above change and `app.add_directive()`
call in setup() function.

Thanks,
Takeshi KOMIYA

2019年11月15日(金) 3:22 Stefano David <[email protected]>:
>
> Hi Takeshi,
>
> On Saturday, 26 October 2019 07:16:25 UTC+2, Komiya Takeshi wrote:
>>
>> Hi,
>>
>> I'd like to see your your source code. Could you share it for us?
>
> 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.
>
>> BTW, rubric directive takes :class: option to give CSS class for the
>> node in HTML output. I think it might help your case.
>
> 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
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sphinx-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sphinx-users/39b36f73-1de5-4ba1-b391-ebd615140f21%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sphinx-users/CAFmkQAOG2_5c9DAJQcuamv7DgcCcg0b8FchFqGXzh%2BB6CK0Vmg%40mail.gmail.com.

Reply via email to