Skip to content

Commit

Permalink
Version 1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
twibiral authored Dec 26, 2022
2 parents d181938 + 17cc72b commit 6459903
Show file tree
Hide file tree
Showing 22 changed files with 422 additions and 30 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),


## [1.6.0]
### Added
- New magic command `@theme` to get if obsidian is in dark or light mode (Thanks to @chlohal)
- New magic commands `@vault_path` and `@note_path` to get the path, and `@vault_url` and `@note_url` to get the url. They replace the old magic commands `@vault` and `@note`.
- Support for Racket (Thanks to @Ghexor)
- Support for F# (Thanks to @chlohal)
- Support for Dart (Thanks to @andremeireles)
- Support for Ruby (Thanks to @santry)
- Support for Batch scripts (Thanks to @hannesdelbeke)

## [1.5.0]
### Added
- Support for C (Thanks to @chlohal)
Expand All @@ -13,7 +23,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix the wrong options for wolframscript (Thanks to @davnn)
- Escape ANSI color codes in the output (Thanks to @chlohal)


## [1.4.0]
### Added
- Notebook mode for R (Thanks to @chlohal)
Expand Down
69 changes: 66 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The result is shown only after the execution is finished. It is not possible to
![Video that shows how the plugin works.](https://github.com/twibiral/obsidian-execute-code/blob/master/images/execute_code_example.gif?raw=true)


The following [languages are supported](#supported-programming-languages): C, CPP, Golang, Groovy, Kotlin, Java, JavaScript, TypeScript, Lua, CSharp, Prolog, Rust, Python, R, Wolfram Mathematica, Haskell, Scala, Shell & Powershell.
The following [languages are supported](#supported-programming-languages): C, CPP, Dart, Golang, Groovy, Kotlin, Java, JavaScript, TypeScript, Lean, Lua, CSharp, Prolog, Rust, Python, R, Ruby, Wolfram Mathematica, Haskell, Scala, Racket, F#, Batch, Shell & Powershell.


Python and Rust support embedded plots. All languages support ["magic" commands](#magic-commands) that help you to access paths in obsidian or show images in your notes.
Expand Down Expand Up @@ -58,6 +58,18 @@ Console.WriteLine("Hello, World!");
```
</details>

<details>
<summary>Dart</summary>

- Requirements: dart sdk is installed and the correct path is set in the settings.

```dart
void main() {
print("Hello World");
}
```
</details>

<details>
<summary>Python</summary>

Expand Down Expand Up @@ -134,6 +146,19 @@ print('Hello, World!')
```
</details>

<details>
<summary>Lean</summary>

- Requirements: install lean and config lean path.

```lean
def main : IO Unit :=
IO.println s!"Hello, World!"
#eval main
```
</details>

<details>
<summary>C++</summary>

Expand Down Expand Up @@ -209,8 +234,23 @@ ls -la
```powershell
echo "Hello World!"
```

- If you prefer batch: change the path settings in the menu for powershell
![Example how to use the magic commands.](https://github.com/twibiral/obsidian-execute-code/blob/master/images/batch_settings.png?raw=true)
</details>


<details>
<summary>Batch</summary>

- Requirements: Used to execute batch commands on Windows (also known as BAT or CMD). Default is command prompt, but can be set to your preferred shell in the settings.

```batch
ECHO Hello World!
```
</details>


<details>
<summary>Prolog</summary>

Expand Down Expand Up @@ -328,6 +368,26 @@ println("Hello, World!")
```
</details>

<details>
<summary>Racket</summary>

- Requirements: Racket is installed and the correct path is set in the settings.

```racket
"Hello, world!"
```
</details>

<details>
<summary>Ruby</summary>

- Requirements: Ruby is installed and the correct path is set in the settings.

```ruby
puts "Hello, World!"
```
</details>

Squiggle: For Squiggle support take a look at the [Obsidian Squiggle plugin](https://github.com/jqhoogland/obsidian-squiggle) by @jqhoogland.

Support for the following is planned:
Expand All @@ -343,15 +403,18 @@ Magic commands are some meta commands that can be used in the code block. They a

The following magic commands are supported:

- `@vault`: Inserts the vault path as string.
- `@note`: Inserts the note path as string.
- `@vault_path`: Inserts the vault path as string (e.g. "/User/path/to/vault")
- `@vault_url`: Inserts the vault url as string. (e.g. "app://local/path/to/vault")
- `@note_path`: Inserts the vault path as string (e.g. "/User/path/to/vault/Note.md")
- `@note_url`: Inserts the vault url as string. (e.g. "app://local/path/to/vault/Note.md")
- `@title`: Inserts the note title as string.
- `@show(ImagePath)`: Displays an image at the given path in the note.
- `@show(ImagePath, Width, Height)`: Displays an image at the given path in the note.
- `@show(ImagePath, Width, Height, Alignment[center|left|right])`: Displays an image at the given path in the note.
- `@html(HtmlSource)`: Displays HTML in the note

(`@show(...)` and `@html(...)` are only supported for JavaScript and Python yet.)
(The old commands `@note` and `@vault` are still supported, but may be removed in the future.)

![Example how to use the magic commands.](https://github.com/twibiral/obsidian-execute-code/blob/master/images/magic_example.png?raw=true)

Expand Down
Binary file added images/batch_settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "execute-code",
"name": "Execute Code",
"version": "1.5.0",
"version": "1.6.0",
"minAppVersion": "0.12.0",
"description": "Allows to execute code snippets within a note.",
"author": "twibiral",
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "execute-code",
"version": "1.5.0",
"version": "1.6.0",
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
"main": "src/main.js",
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion src/ExecutorContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import CppExecutor from './executors/CppExecutor';
import ExecuteCodePlugin, {LanguageId} from "./main";
import RExecutor from "./executors/RExecutor.js";
import CExecutor from "./executors/CExecutor";
import FSharpExecutor from "./executors/FSharpExecutor";

const interactiveExecutors: Partial<Record<LanguageId, any>> = {
"js": NodeJSExecutor,
Expand All @@ -18,7 +19,8 @@ const interactiveExecutors: Partial<Record<LanguageId, any>> = {
const nonInteractiveExecutors: Partial<Record<LanguageId, any>> = {
"prolog": PrologExecutor,
"cpp": CppExecutor,
"c": CExecutor
"c": CExecutor,
"fsharp": FSharpExecutor
};

export default class ExecutorContainer extends EventEmitter implements Iterable<Executor> {
Expand Down
3 changes: 3 additions & 0 deletions src/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ export function getVaultVariables(app: App) {
const fileName = activeView.file.name
const filePath = activeView.file.path

const theme = document.body.classList.contains("theme-light") ? "light" : "dark";

return {
vaultPath: vaultPath,
folder: folder,
fileName: fileName,
filePath: filePath,
theme: theme
}
}
13 changes: 13 additions & 0 deletions src/executors/FSharpExecutor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import NonInteractiveCodeExecutor from './NonInteractiveCodeExecutor';
import type {Outputter} from "src/Outputter";
import type {ExecutorSettings} from "src/settings/Settings";

export default class FSharpExecutor extends NonInteractiveCodeExecutor {
constructor(settings: ExecutorSettings, file: string) {
super(settings, false, file, "fsharp");
}

override run(codeBlockContent: string, outputter: Outputter, cmd: string, args: string, ext: string) {
return super.run(codeBlockContent, outputter, cmd, `fsi ${args}`, "cpp");
}
}
28 changes: 26 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import ExecutorManagerView, {
import runAllCodeBlocks from './runAllCodeBlocks';

export const languageAliases = ["javascript", "typescript", "bash", "csharp", "wolfram", "nb", "wl", "hs", "py"] as const;
export const canonicalLanguages = ["js", "ts", "cs", "lua", "python", "cpp",
"prolog", "shell", "groovy", "r", "go", "rust", "java", "powershell", "kotlin", "mathematica", "haskell", "scala", "c"] as const;
export const canonicalLanguages = ["js", "ts", "cs", "lean", "lua", "python", "cpp", "prolog", "shell", "groovy", "r",
"go", "rust", "java", "powershell", "kotlin", "mathematica", "haskell", "scala", "racket", "fsharp", "c", "dart",
"ruby", "batch"] as const;
export const supportedLanguages = [...languageAliases, ...canonicalLanguages] as const;


Expand Down Expand Up @@ -119,6 +120,9 @@ export default class ExecuteCodePlugin extends Plugin {
*/
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
if (process.platform !== "win32") {
this.settings.wslMode = false;
}
}

/**
Expand Down Expand Up @@ -227,6 +231,13 @@ export default class ExecuteCodePlugin extends Plugin {
this.runCodeInShell(transformedCode, out, button, this.settings.shellPath, this.settings.shellArgs, this.settings.shellFileExtension, language, file);
});

} else if (language === "batch") {
button.addEventListener("click", async () => {
button.className = runButtonDisabledClass;
const transformedCode = await new CodeInjector(this.app, this.settings, language).injectCode(srcCode);
this.runCodeInShell(transformedCode, out, button, this.settings.batchPath, this.settings.batchArgs, this.settings.batchFileExtension, language, file);
});

} else if (language === "powershell") {
button.addEventListener("click", async () => {
button.className = runButtonDisabledClass;
Expand Down Expand Up @@ -304,6 +315,13 @@ export default class ExecuteCodePlugin extends Plugin {
this.runCodeInShell(transformedCode, out, button, this.settings.luaPath, this.settings.luaArgs, "lua", language, file);
});

} else if (language === "dart") {
button.addEventListener("click", async () => {
button.className = runButtonDisabledClass;
const transformedCode = await new CodeInjector(this.app, this.settings, language).injectCode(srcCode);
this.runCodeInShell(transformedCode, out, button, this.settings.dartPath, this.settings.dartArgs, "dart", language, file);
});

} else if (language === "cs") {
button.addEventListener("click", async () => {
button.className = runButtonDisabledClass;
Expand Down Expand Up @@ -336,6 +354,12 @@ export default class ExecuteCodePlugin extends Plugin {
const transformedCode = await new CodeInjector(this.app, this.settings, language).injectCode(srcCode);
this.runCodeInShell(transformedCode, out, button, this.settings.clingPath, this.settings.clingArgs, "c", language, file);
})
} else if(language ==="ruby") {
button.addEventListener("click", async () => {
button.className = runButtonDisabledClass;
const transformedCode = await new CodeInjector(this.app, this.settings, language).injectCode(srcCode);
this.runCodeInShell(transformedCode, out, button, this.settings.rubyPath, this.settings.rubyArgs, "rb", language, file);
})
}
}

Expand Down
Loading

0 comments on commit 6459903

Please sign in to comment.