Code Monkey home page Code Monkey logo

markdown-execute's Introduction

makrdown-execute

VSCode Extension which allows you to execute code from markdown files.

  • Detects code blocks in your markdown-files starting with:

    • ```sh
    • ```bash
    • ```js
    • ```python
  • Adds 'Execute command in terminal as Shell-Script', 'Execute command in terminal as NodeJs-Script', 'Execute command in terminal as python-Script' label.

  • Clicking on the label executes code-block until the closing ticks ``` in the terminal as Shell, NodeJs or Python script.

Alternatively, use cmd+f1 (mac) / ctrl+f1 (windows) shortcut to execute current selection.

Features

Execute code blocks in terminal

demo-execute

Execute Selection

Select code and either use shortcut cmd+f1 (mac) / ctrl+f1 (windows) to execute or open the VSCode command palette and type markdown execute to find the command:

demo-shortcut

Side By Side view

If you interact with terminal very often, I recomment using the terminal in editor area side by side in split view.:

side-by-side-view

Extension Settings

This extension contributes the following settings:

  • markdown-execute.executeInSsh: enable/disable execution of code in a SSH session. If disabled and active terminal is running a SSH session, a new terminal is used as target for commands.
  • markdown-execute.executeSelection: Shortcut to execute selection. Defaults to cmd+f1 (mac) / ctrl+f1 (windows).

Backlog

  1. Analyse and fix why the watch-task in debugging terminal is ignored
  2. Add PHP & TypeScript as execution runtimes:
    1. commandCodeLensProvider:
      1. Execute command with TS
      2. Execute command PHP
    2. extension.ts & execute.ts:
      1. Add PHP and TS as execution runtimes
  3. Add quick select keybinding without promting:
    1. cmd+f1 s Execute command as Shell
    2. cmd+f1 s Execute command with Nodejs

Appreciations

Sycl´s Markdown Command Runner Extension served as inspiration. Thanks!

It was lacking execution of code blocks in active SSH sessions, shortcuts and NodeJs-support, so I made my own.

markdown-execute's People

Contributors

hanskre avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

markdown-execute's Issues

TypeScript Support

Would you consider adding TypeScript?
I think you can use ts-node.

Example:
ts-node -e "console.log('Hello');"

Exception on markdown-execute.execute

I get the following exception upon invoking markdown-execute.execute with ctrl+f1.

[2022-09-03 07:59:51.727] [exthost] [error] TypeError: Cannot read properties of undefined (reading 'runtime')
	at /home/jpambrun/.vscode-server/extensions/hanskre.markdown-execute-0.0.13/dist/extension.js:1:2455
	at c._executeContributedCommand (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:85:63770)
	at c.$executeContributedCommand (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:85:64474)
	at i._doInvokeHandler (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:95:13689)
	at i._invokeHandler (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:95:13371)
	at i._receiveRequest (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:95:12141)
	at i._receiveOneMessage (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:95:10843)
	at /home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:95:8950
	at b.invoke (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:61:145)
	at p.deliver (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:61:2266)
	at v.fire (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:61:1844)
	at a.fire (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:69:19042)
	at /home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:111:17079
	at b.invoke (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:61:145)
	at p.deliver (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:61:2266)
	at v.fire (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:61:1844)
	at a.fire (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:69:19042)
	at r._receiveMessage (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:69:23854)
	at /home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:69:21224
	at b.invoke (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:61:145)
	at p.deliver (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:61:2266)
	at v.fire (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:61:1844)
	at v.acceptChunk (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:69:15873)
	at /home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:69:15003
	at b.invoke (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:61:145)
	at p.deliver (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:61:2266)
	at v.fire (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:61:1844)
	at v._processReadQueue (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:69:34271)
	at v.acceptFrame (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:69:33927)
	at b._acceptChunk (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:69:31891)
	at /home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:69:28880
	at Socket.d (/home/jpambrun/.vscode-server/bin/784b0177c56c607789f9638da7b6bf3230d47a8c/out/vs/workbench/api/node/extensionHostProcess.js:69:26763)
	at Socket.emit (node:events:526:28)
	at addChunk (node:internal/streams/readable:315:12)
	at readableAddChunk (node:internal/streams/readable:289:9)
	at Socket.Readable.push (node:internal/streams/readable:228:10)
	at TCP.onStreamRead (node:internal/stream_base_commons:190:23) markdown-execute.execute {"value":"hanskre.markdown-execute","_lower":"hanskre.markdown-execute"}

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Pending Status Checks

These updates await pending status checks. To force their creation now, click the checkbox below.

  • Update dependency @types/node to v18.19.4

Pending Branch Automerge

These updates await pending status checks before automerging. Click on a checkbox to abort the branch automerge, and create a PR instead.

  • Update typescript-eslint monorepo to v6.17.0 (@typescript-eslint/eslint-plugin, @typescript-eslint/parser)

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

npm
package.json
  • @types/vscode ^1.85.0
  • @types/glob ^8.1.0
  • @types/mocha ^10.0.6
  • @types/node ^18.19.3
  • @typescript-eslint/eslint-plugin ^6.16.0
  • @typescript-eslint/parser ^6.16.0
  • eslint ^8.56.0
  • glob ^10.3.10
  • mocha ^10.2.0
  • typescript ^5.3.3
  • ts-loader ^9.5.1
  • webpack ^5.89.0
  • webpack-cli ^5.1.4
  • @vscode/test-electron ^2.3.8
  • vscode ^1.63.0

  • Check this box to trigger a request for Renovate to run again on this repository

Many characters must be escaped for JS

The following doesn't work:

let i = 12;
console.log("ab$cd")
console.log("ab$$cd")
console.log('sdfdsgdfg')
console.log(`ab${i}cd`)

as it results in

❯ node -e "let i = 12;
∙ console.log('ab$cd')
∙ console.log('ab$$cd')
∙ console.log('sdfdsgdfg')
∙ console.log(`ab${i}cd`)
∙ "
bash: abcd: command not found
ab
ab2847cd
sdfdsgdfg

Many characters needs to be escaped. Alternatively, the markdown block can the piped into node's stdin.

Add binding to execute current cell

The "execute command in terminal" well fine, but I don't want to touch the mouse. Is there any way to add a binding to execute the entire markdown cell where the cursor is?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.