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

[FR] Code Chunk execution #120

Open
jnslr opened this issue Jun 12, 2020 · 0 comments
Open

[FR] Code Chunk execution #120

jnslr opened this issue Jun 12, 2020 · 0 comments

Comments

@jnslr
Copy link

jnslr commented Jun 12, 2020

Description

Currently i'm using VsCode with the Markdown Preview Enhanced extension.

This allows me to integrate code chunks, meaning code snippets that are automatically executed (when saving) and produce dynamic markdown output.

Having a code execution feature would be great.
Of course in the context of a PWA, this would only be possible for Javascript code.

Example

This allows me to create dynamic calculations, such as this one

``` javascript {cmd="node", hide=true output="markdown" run-on-save=true id="calcs"}
var U = 3; //Voltage in V
var R= 1.5; //Resistance in Ohms

var I = U/R; //Current in Amps
var P = U*I; //Power in W

```

# Calc Test

This shows how dynamic calculations in Markdown can be done.

# The Data
``` javascript {cmd="node", hide output="markdown", run-on-save continue="calcs"}
console.log(
    `|Data|Value|Unit|\n`,
    `| :--: | :--: | :--: |\n`,
    `|U|${U}|V|\n`,
    `|I|${R}|Ω|\n`,
);

```

# Calc Current

The current can be calculeted by


``` javascript {cmd="node", hide output="markdown", run-on-save continue="calcs"}
console.log(
  `$$`,
  `I=\\frac{U}{R}`,
  `=\\frac{${U.toFixed(2)}V}{${R.toFixed(2)}\\Omega}`,
  `=${I.toFixed(2)}A`,
  `$$`,
)
```

# Calc Power

The power can be calculated by 

``` javascript {cmd="node", hide output="markdown", run-on-save continue="calcs"}
console.log(
  `$$`,
  `P= U \\cdot I`,
  `= ${U.toFixed(2)}V \\cdot ${I.toFixed(2)} A`,
  `=${P.toFixed(2)}W`,
  `$$`,
)
```

Which produces the following output, where all the calculations dynamically adapt to the variables specified in the first JS section.
Test

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

No branches or pull requests

1 participant