documentation/copy-clipboard.js: Copy shell examples without the prompt
Shell blocks include the prompt ("% git remote -v") and the output of
the command, and the copy button handed all of it to the clipboard, so
the result could not be pasted into a shell. Asciidoctor callouts went
along with it, as "<1>" is rendered as markup inside the block.
Rebuild the copied text from the commands alone, reading the block with
the callout markup taken out, and keep the lines that carry a command
on: a trailing "\", "|" or "&&", and heredoc bodies up to their
delimiter.
Take "%", "$" and "#" for prompts, together with the host name they
sometimes carry, as in "freefall% gen-gitconfig.sh" in the Committer's
Guide or "ellington% ypcat -k netgroup" in the Handbook. A "#" is also
a comment and a common first character of output, so it only counts as
the root prompt where the block opens as root or gets there part way
through, as the Handbook example that runs "% su -" and goes on with "#
make install". The "# extended LDIF" header that ldapsearch(1) prints
is left behind with the rest of the output, and blocks that only look
like a session, such as the Makefile quoted in the FDP Primer, are
copied unchanged.
PR: 272669
Reviewed by: carlavilla
Pull Request: https://ron-dev.freebsd.org/FreeBSD/doc/pulls/4