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

Improvement: support also parsed-literal blocks #68

Open
cmouse opened this issue Mar 16, 2020 · 7 comments
Open

Improvement: support also parsed-literal blocks #68

cmouse opened this issue Mar 16, 2020 · 7 comments

Comments

@cmouse
Copy link

cmouse commented Mar 16, 2020

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

@choldgraf
Copy link
Member

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

@cmouse
Copy link
Author

cmouse commented Mar 16, 2020

@choldgraf
Copy link
Member

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.

@christiam
Copy link

FWIW the suggestion in this comment can be used as a workaround: sphinx-doc/sphinx#4054 (comment)

I hope this helps!

@mgeier
Copy link
Contributor

mgeier commented May 23, 2020

I think this is a Sphinx bug, see also sphinx-doc/sphinx#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).

@Samy-Oubouaziz
Copy link

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
Copy link

Samy-Oubouaziz commented Feb 22, 2023

Linking issue #115 as it seems to be the same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants