r-devel / r-dev-day

Repo to organize tasks for R Dev Days
7 stars 2 forks source link

R Dev Container: restrict copy-paste to code input in mkdocs documentation #60

Open hturner opened 2 months ago

hturner commented 2 months ago

This is issue 106 on the R Dev Container repo.

An example of where it would be helpful to restrict input is in the Example Contribution Workflow:

> askYesNo("Is this a good example?")
Is this a good example? (Yes/no/cancel) Yes
[1] TRUE 

It would be good if the copy-to-clipboard function only copied askYesNo("Is this a good example?").

Code to implement this is linked in the above issue, but you will need to work out how to integrate this with our current process for building the docs from source. The docs are built with mkdocs using Python, as described in the Contributing to docs section.

tim-band commented 2 months ago

Some findings from the RSEcon24 hackathon:

Firstly, this is not R, and should not be fenced with ```R. It should be fenced with ```Rconsole and the indentation should be removed.

Sadly, this does not fix the actual issue here.

I do not like the Issue 106 fix. The idea is to add this wodge of code to every page, which installs an onload handler for the page. It will scan the page and do the following things:

  1. Find code within code blocks that begins with # and mark it with the CSS user-select: none.
  2. Find code that begins with $ and mark the $ with user-select: none.
  3. Find code that begins with << and mark it with user-select: none.
  4. Find code that begins with << and delete the <<.
  5. Gather all the code that is still user-selectable and add a data-clipboard-text attribute with this text to the box.

I would argue that this isn't what we want.

What we really want is essentially just number 5 (we are using clipboard.js and this data-clipboard-text attribute is how to make the text whatever we want). I don't think that making a mouse drag fail to select the prompt or the output is right -- if people want to copy that why not let them? The copy text button is the thing. But ideally this shouldn't be done by post-processing every page onload. But how to do it? Not with a new Pygments lexer, not with a renderer, maybe a filter?

Sadly, I have not managed to find out where best to do this.