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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding hooks to code blocks to transfer their content to external scripts #562

Open
lgersman opened this issue Feb 4, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@lgersman
Copy link

lgersman commented Feb 4, 2024

Is your feature request related to a problem? Please describe.

I would like to use glow as "jupyter for the poor" 馃槄.

I want to write regular markdown with some code blocks. The code should be executed step by the step by the user - but without copy/pasting the code to a terminal.

The easiest would be if the user could have a button or so, to trigger the code execution.

Just like this image shows (the "execute" button on each code block is missing, i hope you can imaging it :-)) :

image

Describe the solution you'd like

I would like to propose a generic and open solution resulting in endless use cases - configurable "hooks" for glow to provide custom interactive markdown documents. just like jupyter notebooks - but simpler and targeting just the terminal.

  • glow should support configurable hooks as cli arguments

  • individual markdown documents should even support glow hook declarations (defined in the markdown frontmatter section) to provide self contained "executable" markdown documents

  • the minimal initial hooks supported by glow should be :

    • the init hook for running a custom script configuring/creating the environment/dependencies to run the code blocks in the markdown document. this might be preparing a terminal window and checking the required software is already installed. if the script configured as init hook returns a status code != 0 glow should disable code block execution an just show up the stderr console output of the init hook. If glow hooks are configured, glow should initially ask the user for confirmation of hook execution is really safe for the user.

    • the onCode hook for running script whenever the user clicks the code block's "execute" action (=> might be a button or whatever). The label of the action might be derived from the configured script (i.e. its name). Whenever the action gets triggered by the user, glow should transfer the content of the code block to the script. It's up to the script to so something with the text. It might even just transfer the code to the clipboard, execute it in a terminal or whatever.

    • the destroy hook should be called when (1) glow exists or (2) loads another markdown document. This hook can be used to cleanup generated files/folders/whatever.

I hope you've got the whole idea.

This feature might empower glow to be usable for terminal based

  • interactive tutorials

  • setup documents

  • terminal based jupyter a like notebooks

and many many more.

I wouldn鈥檛 be surprised if it would be heavily used at universities because it鈥檚 so beautifully simple to use.

@lgersman lgersman added the enhancement New feature or request label Feb 4, 2024
@lgersman
Copy link
Author

lgersman commented Feb 6, 2024

Using these "hooks" effort could also be used to configure a "copy-to-clipboard" action to code blocks.

Would be useful too 鉂わ笍

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

1 participant