sphinx-copybutton icon indicating copy to clipboard operation
sphinx-copybutton copied to clipboard

Improvement: support also parsed-literal blocks

Open cmouse opened this issue 4 years ago • 7 comments

It would be nice if it was possible to also copy text from parsed-literal blocks too.

cmouse avatar Mar 16 '20 07:03 cmouse

Could you give an example of a page w/ a parsed-literal block? It would make it easier for folks to implement a selector to add buttons to this

choldgraf avatar Mar 16 '20 15:03 choldgraf

https://doc.dovecot.org/configuration_manual/protocols/lmtp_server/#lmtp-proxying

cmouse avatar Mar 16 '20 18:03 cmouse

Sounds good 👍 I think the fix would need to be here for anyone interested in implementing this:

https://github.com/choldgraf/sphinx-copybutton/blob/master/sphinx_copybutton/init.py#L28

Seems like parsed_literal would be reasonable to add to the list of default selectors.

choldgraf avatar Mar 17 '20 15:03 choldgraf

FWIW the suggestion in this comment can be used as a workaround: https://github.com/sphinx-doc/sphinx/issues/4054#issuecomment-329097229

I hope this helps!

christiam avatar Apr 14 '20 01:04 christiam

I think this is a Sphinx bug, see also https://github.com/sphinx-doc/sphinx/issues/2167.

IMHO Sphinx should generate nested highlight-none and highlight <div>s for parsed-literal blocks. This would automatically solve the issue here.

Strangely, if you don't use any special formatting (which is against the whole purpose of parsed-literal), the resulting code block is properly wrapped (but default-syntax-highlighted, which is probably not expected).

mgeier avatar May 23 '20 16:05 mgeier

Hello,

On my end, (like @mgeier said I think) the issue is that:

.. parsed-literal:: has the div.highlight pre selector like any other code block when not used with special formatting.

But when used with special formatting (i.e. a |version| variable in my case), it loses the div.highlight pre selector and gets a new one pre#codecell0.litteral-block.

I found a simple fix worth trying:

.. raw:: html

   <div class=highlight>

.. parsed-literal::

   # env_deploy_version: |version|

.. raw:: html

   </div>

*the 3 directives must be on the same indentation level.

With this syntax, you force a div.highlight pre selector on your code block.

It does not support syntax highlighting (in the form .. parsed-literal:: bash) though.

LMK if it works and if you have any suggestion !

Samy-Oubouaziz avatar Feb 22 '23 10:02 Samy-Oubouaziz

Linking issue https://github.com/executablebooks/sphinx-copybutton/issues/115 as it seems to be the same problem.

Samy-Oubouaziz avatar Feb 22 '23 10:02 Samy-Oubouaziz