sagemathinc / cocalc

CoCalc: Collaborative Calculation in the Cloud
https://CoCalc.com
Other
1.14k stars 207 forks source link

Way to disable code execution in markdown editor. #7193

Open mforbes opened 5 months ago

mforbes commented 5 months ago

While the ability to execute code in a markdown file is awesome, there needs to be some way to disable this. I.e. in usecases like this:

If you want to delete everything on your harddrive, you can do this

sudo rm -rf /

Needless to say, someone should not be able to accidentally execute this cell with shift-enter... but I still want to be able to use code-fences to format code.

Not sure of the best option. Here are some alternatives:

This would break the case where people upload a markdown file and then want to execute cells, but they are all dead. The UI could easily fix this.

williamstein commented 5 months ago

Code only executes if there is a preamble defining the kernels for which code should be executed.

This seems reasonable, along with a clear switch at the top of the editor to turn code execution on and off, probably with the default being "off".

I'm labeling this as "bug" due to "there needs to be some way to disable this".

mforbes commented 5 months ago

Actually, the way the UI works right now is not too bad:

```bash {kernel="bash"}
# This will execute
# This will not execute


Perhaps the only change needed is:
* Allow the cell to be execute iff one of the following is true:
  * there is a valid`{kernel=}`
  * there is a kernel specified for the file in the "preamble" comments (for compatibility with Jupyter book).
* There should be a "no kernel" option or something in the UI that is the default.
williamstein commented 5 months ago

Please keep thinking about this!

mforbes commented 5 months ago

Suggestions (still incomplete)

Here are some general suggestions as I work with code cells (probably should be migrated to a new issue once the execution pattern in established, but I am keeping there here for now.)

(For CoCalc Devs: I am playing here if you want some code.)

Some relevant issues etc.: