On 2017-06-07, Benoit Barthelet wrote:
> [-- Type: text/plain, Encoding: --]
> Hello,
> I'm finding myself writing in rst and pasting long parts of code using the
> .. code:: directive
(BTW For complete code files, you can also use the "include" directive
with the "code" option.
http://docutils.sourceforge.net/docs/ref/rst/directives.html#including-an-external-document-fragment
)
> I'd like to be able to have togglable code when using rst2html.
> If I'm correct I can achieve that with or without javascript, in both case
> I seem to be missing one part of the puzzle to make it work effortlessly.
> With javascript, as described in
> https://stackoverflow.com/a/25543713/3581357 I can create a container and
> have the js code handle the toggle, this works fine for me, except that I'm
> unable to find a way to add the js code in question to the rst2html cli.
You can specify a custom html template to replace the default
docutils/writers/html4css1/template.txt
http://docutils.sourceforge.net/docs/user/config.html#template
Also, you can pass class arguments to (almost) any rST element using either
the "class" directive or (for directives) the "class" option::
.. code-block:: xml
:class: toggle-hide
So, maybe you don't need to wrap in a "container".
> I see there is a --script flag but only for rst2html5.
There is no such thing for rst2html5.py shipping with docutils.
http://docutils.sourceforge.net/docs/user/config.html#html5-writer
> Without javascript it seems like css can be used to get the toggle effect
> as described here:
> https://siongui.github.io/2017/02/27/css-only-toggle-dom-element/
> That solution would be quite elegant, ids could be changed to classes and
> the css modified accordingly, but I don't see a way to add a <input
> id="element-toggle" type="checkbox" /> which this solution is ultimately
> based on.
There is indeed not rST for an HTML <input> element.
You could use raw HTML.
> Is it where I should write my own directive as described here
> http://docutils.sourceforge.net/docs/howto/rst-directives.html ?
You would not only need a custom directive, but also an extension to the
HTML writer (unless you let the custom directive generate raw HTML).
Günter
|