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

Feature request: Force execution of all code cells without adding .cb-run and .cb-nb #59

Open
mfhepp opened this issue Sep 26, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@mfhepp
Copy link

mfhepp commented Sep 26, 2022

Hi,
it would be handy to have a command-line option that automatically adds either

  • .cb-run
    or
  • .cb-run and .cb-nb

or the respective behavior to all Python code block.

Motivation: I often create Python materials in Pandoc markdown and would want to produce a lecture note with the code snippets and their effects side-by-side. While I could manually add {.python .cb-run .cb-nb} to each code block, that seems like unnecessary redundancy. Before I start writing a custom Pandoc filter that adds .cb-run and .cb-nb to all code blocks in a Pandoc document, I wanted to check if there is another way with batteries supplied.

Implementation: I would use a CLI option like

  • all supported code block types: --runall
  • all code blocks of a single type --runall python
  • all code blocks of a a list of types --runall python,bash
@mfhepp
Copy link
Author

mfhepp commented Sep 26, 2022

Alternative implementation:

Support a YAML keyword runall, like so:

---
codebraid:
jupyter:
    kernel: python3
    timeout: 120
    runall: 
        - python
        - bash        
---

@gpoore
Copy link
Owner

gpoore commented Sep 27, 2022

To get something working immediately, I'd suggest running Pandoc with a filter on the original file to add the Codebraid classes, and then piping the Pandoc output through Codebraid.

Something like this should work for the filter:

function CodeBlock(elem)
    elem.classes:insert('python')
    elem.classes:insert('cb-nb')
    return elem
end

And then run with a command like this:

pandoc -f markdown -t markdown -L ./add_attr.lua ./attr.md | codebraid pandoc -f markdown -t markdown

I like the idea of adding a feature like this in the YAML. I'm planning to add YAML features for setting default code chunk options, and adding a feature like this would basically amount to the same thing except setting defaults for all code chunks, not just those marked with Codebraid classes. I'm currently working on updating some of my other open-source projects after focusing on Codebraid Preview earlier this year, so I may not be able to work on adding new features for a while.

@gpoore gpoore added the enhancement New feature or request label Sep 27, 2022
@mfhepp
Copy link
Author

mfhepp commented Sep 27, 2022

Thanks a lot! Yes, I will be using a filter for the time being!
Btw, the defaults files route is very powerful; I am developing a huge library of output formats mostly based on a hierarchy of defaults.yaml and meta.yaml files that reference their parent directory - very good for maintenance, because you minimize redundancy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants