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

remove regex that breaks copy button #690

Merged
merged 1 commit into from
Aug 24, 2023

Conversation

proofconstruction
Copy link
Contributor

Fixes #688

Problem

The bug preventing copying the full block text is due to this regular expression in conf.py:

copybutton_prompt_text = r"# |\$ "

which does the following:

  • removes the prompt from the beginning of any lines that start with it, and
  • copies only the lines that contain the prompt(s), if they are found, or otherwise copies the full contents of the code block.

The current regex matches on the user and root shell prompts, so presumably this was originally meant to capture text from console or shell-session blocks, but actually results in the copy button ignoring any useful text in blocks that contain a comment (except for the comment text).

Investigating

I checked the directory for instances where we use a leading # character after opening a codeblock and found only these two files:

$ rg -U '^```.*\n#\s{1}+'                                                                                              [19:40:15]
tutorials/learning-journey/packaging-existing-software.md
66:```nix
67:# hello.nix
108:```nix
109:# default.nix
149:```nix
150:# hello.nix
211:```nix
212:# default.nix
224:```nix
225:# icat.nix
243:```nix
244:# icat.nix
284:```nix
285:# icat.nix
334:```nix
335:# icat.nix
391:```nix
392:# icat.nix
455:```nix
456:# icat.nix
500:```nix
501:# icat.nix

tutorials/nixos/installing-nixos-on-a-raspberry-pi.md
77:```shell-session
78:# wpa_supplicant -B -i wlan0 -c <(wpa_passphrase 'SSID' 'passphrase') &
89:```shell-session
90:# nix-shell -p raspberrypi-eeprom
159:```shell-session
160:# curl -L https://tinyurl.com/tutorial-nixos-install-rpi4 > /etc/nixos/configuration.nix
171:```shell-session
172:# nixos-rebuild boot

Every instance in packaging-existing-software.md is a comment containing a filename, which doesn't break anything. In installing-nixos-on-a-raspberry-pi.md, we have several instances of the root prompt, including several commands run as root in the same codeblock, but nobody reading that tutorial will ever be using the copy button and pasting what they get into a console (I hope), so it should be fine to copy the # in those cases, or the whole block in places where there are several commands, like here.

The Fix

Remove the root prompt from the regex:

- copybutton_prompt_text = r"# |\$ "
+ copybutton_prompt_text = r"\$ "

@proofconstruction proofconstruction requested a review from a team as a code owner August 24, 2023 01:07
@fricklerhandwerk fricklerhandwerk merged commit 92e4e1e into NixOS:master Aug 24, 2023
1 check passed
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-08-23-documentation-team-meeting-notes-75/32142/1

@fricklerhandwerk fricklerhandwerk added the site Improvements to the site infrastructure or content presentation label Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
site Improvements to the site infrastructure or content presentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Copying all text in a code block fails if the block contains a comment
4 participants