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

docs: add a "Copy Commands" button for shell-session snippets #16408

Merged
merged 1 commit into from Jun 8, 2021

Conversation

qmonnet
Copy link
Member

@qmonnet qmonnet commented Jun 2, 2021

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.

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”

@qmonnet qmonnet added area/documentation Impacts the documentation, including textual changes, sphinx, or other doc generation code. release-note/misc This PR makes changes that have no direct user impact. labels Jun 2, 2021
@qmonnet qmonnet force-pushed the pr/doc_copy_commands_button branch 2 times, most recently from e7d0b13 to 1a42b86 Compare June 3, 2021 11:16
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>
@qmonnet qmonnet force-pushed the pr/doc_copy_commands_button branch from 1a42b86 to 46e0712 Compare June 3, 2021 12:10
@qmonnet qmonnet marked this pull request as ready for review June 3, 2021 12:22
@qmonnet qmonnet requested a review from a team as a code owner June 3, 2021 12:22
@qmonnet qmonnet requested a review from joestringer June 3, 2021 12:22
Copy link
Member

@nbusseneau nbusseneau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@qmonnet qmonnet changed the title [RFC] docs: add a "Copy Commands" button for shell-session snippets docs: add a "Copy Commands" button for shell-session snippets Jun 3, 2021
Copy link
Member

@joestringer joestringer left a 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.

@qmonnet
Copy link
Member Author

qmonnet commented Jun 4, 2021

Here's a patch to apply on top of the PR if you want to play with it a little bit.

Playing with code snippets
diff --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

@qmonnet
Copy link
Member Author

qmonnet commented Jun 8, 2021

Based on reviews and feedback from Slack (and Documentation test passing), I'm marking as ready-to-merge.

@qmonnet qmonnet added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jun 8, 2021
@aanm aanm merged commit 869e678 into cilium:master Jun 8, 2021
@nbusseneau
Copy link
Member

@qmonnet I propose we backport this to 1.10, in case we backport other PRs that rely on the new system.

@qmonnet
Copy link
Member Author

qmonnet commented Jun 8, 2021

Make sense to me. I'll mark for 1.8/1.9 too. I don't expect many conflicts on that button anyway :)

@qmonnet qmonnet deleted the pr/doc_copy_commands_button branch June 8, 2021 12:35
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from master in 1.9.9 Jun 8, 2021
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from master in 1.8.11 Jun 8, 2021
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Needs backport from master to Backport pending to v1.8 in 1.8.11 Jun 10, 2021
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Backport pending to v1.8 to Backport done to v1.8 in 1.8.11 Jun 16, 2021
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Needs backport from master to Backport pending to v1.9 in 1.9.9 Jun 16, 2021
@joestringer joestringer added this to Backport pending to v1.9 in 1.9.10 Jul 19, 2021
@joestringer joestringer removed this from Backport pending to v1.9 in 1.9.9 Jul 19, 2021
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Backport done to v1.9 in 1.9.9 Jul 19, 2021
@joestringer joestringer removed this from Backport pending to v1.9 in 1.9.10 Jul 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/documentation Impacts the documentation, including textual changes, sphinx, or other doc generation code. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact.
Projects
No open projects
1.8.11
Backport done to v1.8
1.9.9
Backport done to v1.9
Development

Successfully merging this pull request may close these issues.

None yet

8 participants