twibiral / obsidian-execute-code

Obsidian Plugin to execute code in a note.
MIT License
1.06k stars 67 forks source link

Feature: Change execution output to be it's own code block #280

Open theshadow opened 1 year ago

theshadow commented 1 year ago

Overview

When executing code snippets I noticed that the output of the code isn't actually added to the resulting Markdown file. This made it difficult to create a report and/or how-to to share with others. It may be useful to have the results be it's own source block that may contain it's own meta-data.

Using meta-data on the source block you could also specify if the output should be entangled into the file this way or left with the default behavior.

Examples

Plaintext Results

```shell {"output":"result"}
echo "Hello, world!"
```
```result
Hello, world!
```

Syntax Highlighted Results

```shell {"output":"result", "result":"javascript"}
echo "{\"message\": \"Hello, world!\"}"
```
```result {"lang": "javascript"}
{"message": "Hello, world!"}
```

Syntax Highlighted Results w/Label

```shell {"output":"result", "result":"javascript", "label": "json-greeting"}
echo "{\"message\": \"Hello, world!\"}"
```
```result {"lang": "javascript", "for": "json-greeting"}
{"message": "Hello, world!"}
```

Syntax Highlighted Results w/File output for the Results

```shell {"output":"result", "result":"javascript", "file": "json-greeting.json"}
echo "{\"message\": \"Hello, world!\"}"
```

And here are the contents of the file json-greeting.json

{"message": "Hello, world!"}