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
docs: add a "Copy Commands" button for shell-session snippets #16408
Conversation
e7d0b13
to
1a42b86
Compare
Add a "Copy Commands" to some code blocks. This new button attempts to copy only commands (and not their output) to the clipboard. The distinction between commands and output relies on the presence of a prompt symbol, either "$" or "#", at the beginning of the commands. If a command ends with a trailing backslash, copy the next line as well. For example, the following snippet: .. code-block:: shell-session $ ls -l foo cat $ echo 1 \ 2 \ 3\ 4 $nospace # exit should place the following text into the clipboard: ls -l echo 1 2 3 4 exit The button is added for the following blocks, when they contain several lines and at least one command is found in the block: - "code-block", but with language "shell-session" only, - Literal blocks ("::"), - Parsed literals. Signed-off-by: Quentin Monnet <quentin@isovalent.com>
1a42b86
to
46e0712
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DCO may foil your attempts at Jedi mindtrickery ;)
I can ack this. I'm OK with the idea and I understand that you've done some manual validation so it's not expected to break anything. I can't review the javascript; it looks reasonable enough at a glance but I'm not at all familiar with the language.
Here's a patch to apply on top of the PR if you want to play with it a little bit. Playing with code snippetsdiff --git a/Documentation/index.rst b/Documentation/index.rst
index e3e40bfbbdad..dbde908978bb 100644
--- a/Documentation/index.rst
+++ b/Documentation/index.rst
@@ -7,6 +7,103 @@
Welcome to Cilium's documentation!
==================================
+Parsed literals
+
+.. parsed-literal::
+
+ foo
+ bar
+ baz
+
+.. parsed-literal::
+
+ foo
+ bar
+ $ baz
+
+.. parsed-literal::
+
+ $ foo
+ $ bar
+ baz
+
+Literal blocks
+
+::
+
+ foo
+ bar
+ baz
+
+::
+
+ foo
+ bar
+ $ baz
+
+::
+
+ $ foo
+ $ bar
+ baz
+
+Code blocks (yaml)
+
+.. code-block:: yaml
+
+ foo:
+ - bar
+ - baz
+
+.. code-block:: yaml
+
+ foo:
+ - bar
+ $ baz
+
+.. code-block:: yaml
+
+ $ foo
+ $ bar
+ baz
+
+Code blocks (shell-session)
+
+.. code-block:: shell-session
+
+ foo:
+ - bar
+ - baz
+
+.. code-block:: shell-session
+
+ foo:
+ - bar
+ $ baz
+
+.. code-block:: shell-session
+
+ $ foo
+ $ bar
+ baz
+
+.. code-block:: shell-session
+
+ $ ls -l
+ foo
+ cat
+ $ echo 1 \
+ 2 \
+ 3\
+ 4
+ $nospace
+ $ foobar
+ # baz \
+ budo \
+ pouet
+ # exit
+
+
The documentation is divided into the following sections:
* :ref:`gs_guide`: Provides a simple tutorial for running a small Cilium |
Based on reviews and feedback from Slack (and Documentation test passing), I'm marking as |
@qmonnet I propose we backport this to 1.10, in case we backport other PRs that rely on the new system. |
Make sense to me. I'll mark for 1.8/1.9 too. I don't expect many conflicts on that button anyway :) |
Add a
Copy Commands
to some code blocks. This new button attempts to copy only commands (and not their output) to the clipboard. The distinction between commands and output relies on the presence of a prompt symbol, either$
or#
, at the beginning of the commands. If a command ends with a trailing backslash, copy the next line as well.For example, the following snippet:
should place the following text into the clipboard:
The button is added for the following blocks, when they contain several lines and at least one command is found in the block:
code-block
, but with languageshell-session
only,::
),If accepted, this PR would mean that we should favour using prompt symbols (
$
/#
) at the beginning of commands in snippet in the documentation, when a block contains both commands and output, to help with copy.Waves hands and speaks in a Jedi voice: “You did NOT see me write JavaScript”