Unselectable code-block prompt

75 views
Skip to first unread message

Ron Stone

unread,
Sep 14, 2021, 5:42:38 AM9/14/21
to sphinx-users
Hi,

I originally posted this to sphinx-dev but now believe it belongs here. Apologies for cross-posting.

I am using Sphinx 4.2. I see this merge re making prompts in code blocks unelectable. 


I don't see any documentation of how this works here:

and building a typical code-block such as the following does not demonstrate changed behaviour. 

.. code-block:: bash
    
   ls

or 

.. code-block:: bash
    
   $ ls

Can someone please explain how this is configured and invoked?

Thanks.

Komiya Takeshi

unread,
Sep 14, 2021, 9:48:51 AM9/14/21
to sphinx...@googlegroups.com
Hi,

>Can someone please explain how this is configured and invoked?

The latest Sphinx uses CSS to make prompts unselectable.
refs: https://developer.mozilla.org/en-US/docs/Web/CSS/user-select

Thanks,
Takeshi KOMIYA

2021年9月14日(火) 18:42 Ron Stone <ronsto...@gmail.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 sphinx-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sphinx-users/29b9917f-6e18-430a-9765-42553f74a687n%40googlegroups.com.

Ron Stone

unread,
Sep 14, 2021, 10:22:05 AM9/14/21
to sphinx-users
Thanks, but I am still missing something here. How does the system distinguish between a prompt and non-prompt in a code block?

1. Is there a new mechanism to specify a prompt, similar to the sphinx-prompts extension?
2. Is there some markup within the block to identify the prompt?
3. Are certain characters at the front of a line detected and treated as prompts, such as '$' for bash?

R.

It would be useful to see a minimal working example of this.

Komiya Takeshi

unread,
Sep 14, 2021, 10:54:56 AM9/14/21
to sphinx...@googlegroups.com
Ah, sorry. I had to describe that. We use highlighting library
pygments to detect prompts. It can parse the code-block and can
recognize the kind of each token.

2021年9月14日(火) 23:22 Ron Stone <ronsto...@gmail.com>:
> To view this discussion on the web visit https://groups.google.com/d/msgid/sphinx-users/fd008e21-fca1-4e0b-8686-0f4b4180a04dn%40googlegroups.com.

Ron Stone

unread,
Sep 14, 2021, 11:02:59 AM9/14/21
to sphinx-users
Thanks again. That sounds simple enough from a user perspective. With:

.. code-block:: bash

   $ A prompt?

The '$' should be unelectable in the output, but this is pasted from the html:

$ A prompt?

I am using 4.2

Komiya Takeshi

unread,
Sep 14, 2021, 11:36:39 AM9/14/21
to sphinx...@googlegroups.com
In python's case, the pygmentize command (CLI of pygments) recognizes
">>>" as a prompt and gives <span class="o"> style to it.

$ echo '>>> A prompt' | pygmentize -l python -f html
<div class="highlight"><pre><span></span><span
class="o">&gt;&gt;&gt;</span> <span class="n">A</span> <span
class="n">prompt</span>
</pre></div>

On the other hand, in bash's case, it can't recognizes "$" as a
prompt. So there is no special styles on the output.

$ echo '$ A prompt' | pygmentize -l bash -f html
<div class="highlight"><pre><span></span>$ A prompt
</pre></div>

So some contribution would be needed for pygments, I think.

Note: I used pygments-2.10.0

$ pygmentize -V
Pygments version 2.10.0, (c) 2006-2021 by Georg Brandl, Matthäus
Chajdas and contributors.

2021年9月15日(水) 0:03 Ron Stone <ronsto...@gmail.com>:
> To view this discussion on the web visit https://groups.google.com/d/msgid/sphinx-users/b88e9e00-e69e-4654-8d2c-146832831640n%40googlegroups.com.

Slavko

unread,
Sep 14, 2021, 12:41:16 PM9/14/21
to sphinx...@googlegroups.com
Ahoj,

Dňa Wed, 15 Sep 2021 00:36:26 +0900 Komiya Takeshi
<i.tk...@gmail.com> napísal:

> On the other hand, in bash's case, it can't recognizes "$" as a
> prompt. So there is no special styles on the output.
>
> $ echo '$ A prompt' | pygmentize -l bash -f html
> <div class="highlight"><pre><span></span>$ A prompt
> </pre></div>
>
> So some contribution would be needed for pygments, I think.

I afraid, that it will be hard to implement in some generic way, as the
prompt are less standardized than in python.

But one can customize the bash lexer in sphinx to use exact prompts. I
have no example, i never play with bash lexer, but sphinx has
documented pygments API (or how ot name it) and i use some customized
lexers, e.g. for arduino code:

class AvrArduinoLexer(ArduinoLexer):
"""Extended Arduino lexer class
"""
constants = CONSTANTS
functions = ArduinoLexer.functions | {"ISR", "_delay_ms"}


def setup(app):
"""extension's setup
"""
app.add_lexer("arduino", AvrArduinoLexer)


--
Slavko
http://slavino.sk
Reply all
Reply to author
Forward
0 new messages