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

Way to disable code execution in markdown editor. #7193

Open
mforbes opened this issue Jan 19, 2024 · 4 comments
Open

Way to disable code execution in markdown editor. #7193

mforbes opened this issue Jan 19, 2024 · 4 comments
Labels
A-markdown I-bug jupyter-api things involving the stateless jupyter api

Comments

@mforbes
Copy link

mforbes commented Jan 19, 2024

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:

  • Different syntax for executable cells. (This is sort of following the Jupyter book syntax.)
    ```bash
    # This will only render as code
    ls -la
    ```
    ```{code-cell} bash
    # This will execute.
    ls -la
    ```
    
  • Code only executes if there is a preamble defining the kernels for which code should be executed.

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 williamstein added I-bug A-markdown jupyter-api things involving the stateless jupyter api labels Jan 19, 2024
@williamstein
Copy link
Contributor

williamstein commented Jan 19, 2024

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
Copy link
Author

mforbes commented Jan 19, 2024

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

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

```bash
# 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
Copy link
Contributor

Please keep thinking about this!

@mforbes
Copy link
Author

mforbes commented Jan 23, 2024

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.)

  • The cache is really nice, but there needs some way to manage/clear the cache. If you edit a package that you are using, the editor does not see the change, and so will not produce an update. It is not clear how to trigger this refresh from the current interface. Since editing the code automatically greys the output, and/or loads previous executions, I suggest the following:
    Suggestion: The Run button should always rerun the code, invalidating that particular cache. The should also be some way (thought maybe somewhat hidden) to refresh the entire cache.
    Workaround: change the code (add a comment for example).
    Related: Is there a way to refresh the image cache. (I.e. when viewing a saved image?) Update: This might be a browser-cache related issue, which would need something triggering the browser to reload the file when it changes.

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

Some relevant issues etc.:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-markdown I-bug jupyter-api things involving the stateless jupyter api
Projects
None yet
Development

No branches or pull requests

2 participants