lem
lem copied to clipboard
Interactive markdown
This adds interactive features to markdown code blocks, like how src blocks in org-mode work.
The API consists of 3 commands: markdown-eval-block
, markdown-eval-block-and-insert
, and markdown-kill-block-result
, as well as one macro, register-block-evaluator
for users to add support for other languages (lisp and bash work by default).
markdown-eval-block
evaluates the source block your cursor is in, and outputs the result to a popup buffer (just like lisp-macroexpand
)
markdown-eval-block-and-insert
evaluates the block and inserts it's result below the block. If there was already a result there, it first deletes the old one.
markdown-kill-block-result
deletes the result block below the code block your cursor is in, this is run automatically before markdown-eval-block-and-insert
.
If you try to evaluate a block and there is no registered evaluator, a message is displayed saying so. If you use any of these commands outside a code block, nothing happens. If you use these commands while not in markdown-mode, a warning is displayed.
Evaluation commands work asynchronously and you can do whatever you want while it is working.
Here is a demo: Screencast from 2024-02-17 14-15-46.webm
What is your guys' opinions on adding a feature like this that allows custom post-processing:
```http
GET http://localhost/json
```json
The idea is that this could be added on to output formatted JSON, this could be used in any situation where the ~a
format is not desired. Examples include formatted JSON and HTML as well as using ~s
or custom functions handling database tables.
Downside is that it doesn't look pretty in a markdown renderer, although for default behavior it would change nothing.
What are your thoughts?
Edit: prototype here https://github.com/garlic0x1/lem/tree/block-metadata