diff --git a/CHANGELOG.md b/CHANGELOG.md
index b1338cbb..801cb672 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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)
@@ -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)
diff --git a/README.md b/README.md
index d273fc53..3d699456 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@ The result is shown only after the execution is finished. It is not possible to

-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.
@@ -58,6 +58,18 @@ Console.WriteLine("Hello, World!");
```
+
+Dart
+
+- Requirements: dart sdk is installed and the correct path is set in the settings.
+
+```dart
+void main() {
+ print("Hello World");
+}
+```
+
+
Python
@@ -134,6 +146,19 @@ print('Hello, World!')
```
+
+Lean
+
+- Requirements: install lean and config lean path.
+
+```lean
+def main : IO Unit :=
+ IO.println s!"Hello, World!"
+
+#eval main
+```
+
+
C++
@@ -209,8 +234,23 @@ ls -la
```powershell
echo "Hello World!"
```
+
+- If you prefer batch: change the path settings in the menu for powershell
+
+
+
+
+
+Batch
+
+- 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!
+```
+
Prolog
@@ -328,6 +368,26 @@ println("Hello, World!")
```
+
+Racket
+
+- Requirements: Racket is installed and the correct path is set in the settings.
+
+```racket
+"Hello, world!"
+```
+
+
+
+Ruby
+
+- Requirements: Ruby is installed and the correct path is set in the settings.
+
+```ruby
+puts "Hello, World!"
+```
+
+
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:
@@ -343,8 +403,10 @@ 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.
@@ -352,6 +414,7 @@ The following magic commands are supported:
- `@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.)

diff --git a/images/batch_settings.png b/images/batch_settings.png
new file mode 100644
index 00000000..d165bb87
Binary files /dev/null and b/images/batch_settings.png differ
diff --git a/manifest.json b/manifest.json
index 51d53066..4bee03e0 100644
--- a/manifest.json
+++ b/manifest.json
@@ -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",
diff --git a/package-lock.json b/package-lock.json
index ef12d6f0..340fcb98 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "execute-code",
- "version": "1.5.0",
+ "version": "1.6.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
diff --git a/package.json b/package.json
index 820e82ee..24f5dfb7 100644
--- a/package.json
+++ b/package.json
@@ -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": {
diff --git a/src/ExecutorContainer.ts b/src/ExecutorContainer.ts
index 880829d3..59698969 100644
--- a/src/ExecutorContainer.ts
+++ b/src/ExecutorContainer.ts
@@ -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> = {
"js": NodeJSExecutor,
@@ -18,7 +19,8 @@ const interactiveExecutors: Partial> = {
const nonInteractiveExecutors: Partial> = {
"prolog": PrologExecutor,
"cpp": CppExecutor,
- "c": CExecutor
+ "c": CExecutor,
+ "fsharp": FSharpExecutor
};
export default class ExecutorContainer extends EventEmitter implements Iterable {
diff --git a/src/Vault.ts b/src/Vault.ts
index c50d3e87..f2d2264d 100644
--- a/src/Vault.ts
+++ b/src/Vault.ts
@@ -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
}
}
diff --git a/src/executors/FSharpExecutor.ts b/src/executors/FSharpExecutor.ts
new file mode 100644
index 00000000..7438904b
--- /dev/null
+++ b/src/executors/FSharpExecutor.ts
@@ -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");
+ }
+}
diff --git a/src/main.ts b/src/main.ts
index 12903c0b..ea64aca9 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -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;
@@ -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;
+ }
}
/**
@@ -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;
@@ -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;
@@ -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);
+ })
}
}
diff --git a/src/settings/Settings.ts b/src/settings/Settings.ts
index f4cbfe7e..9eca8f95 100644
--- a/src/settings/Settings.ts
+++ b/src/settings/Settings.ts
@@ -15,9 +15,15 @@ export interface ExecutorSettings {
tsPath: string;
tsArgs: string;
tsInject: string;
+ leanPath: string;
+ leanArgs: string;
+ leanInject: string;
luaPath: string;
luaArgs: string;
luaInject: string;
+ dartPath: string;
+ dartArgs: string;
+ dartInject: string;
csPath: string;
csArgs: string;
csInject: string;
@@ -29,6 +35,10 @@ export interface ExecutorSettings {
shellArgs: string;
shellFileExtension: string;
shellInject: string;
+ batchPath: string;
+ batchArgs: string;
+ batchFileExtension: string;
+ batchInject: string;
groovyPath: string;
groovyArgs: string;
groovyFileExtension: string;
@@ -79,18 +89,32 @@ export interface ExecutorSettings {
scalaArgs: string;
scalaFileExtension: string;
scalaInject: string;
+ racketPath: string;
+ racketArgs: string;
+ racketFileExtension: string;
+ racketInject: string;
+ fsharpPath: string;
+ fsharpArgs: string;
+ fsharpInject: "";
+ fsharpFileExtension: string;
cArgs: string;
cUseMain: boolean;
cInject: string;
+ rubyPath: string;
+ rubyArgs: string;
+ rubyInject: string;
jsInteractive: boolean;
tsInteractive: boolean;
csInteractive: boolean;
+ leanInteractive: boolean;
luaInteractive: boolean;
+ dartInteractive: boolean;
pythonInteractive: boolean;
cppInteractive: boolean;
prologInteractive: boolean;
shellInteractive: boolean;
+ batchInteractive: boolean;
bashInteractive: boolean;
groovyInteractive: boolean;
rInteractive: boolean;
@@ -102,7 +126,10 @@ export interface ExecutorSettings {
mathematicaInteractive: boolean;
haskellInteractive: boolean;
scalaInteractive: boolean;
+ racketInteractive: boolean;
+ fsharpInteractive: boolean;
cInteractive: boolean;
+ rubyInteractive: boolean;
}
@@ -121,9 +148,15 @@ export const DEFAULT_SETTINGS: ExecutorSettings = {
tsPath: "ts-node",
tsArgs: "",
tsInject: "",
+ leanPath: "lean",
+ leanArgs: "",
+ leanInject: "",
luaPath: "lua",
luaArgs: "",
luaInject: "",
+ dartPath: "dart",
+ dartArgs: "",
+ dartInject: "",
csPath: "dotnet-script",
csArgs: "",
csInject: "",
@@ -135,6 +168,10 @@ export const DEFAULT_SETTINGS: ExecutorSettings = {
shellArgs: "",
shellFileExtension: "sh",
shellInject: "",
+ batchPath: "call",
+ batchArgs: "",
+ batchFileExtension: "bat",
+ batchInject: "",
groovyPath: "groovy",
groovyArgs: "",
groovyFileExtension: "groovy",
@@ -185,18 +222,32 @@ export const DEFAULT_SETTINGS: ExecutorSettings = {
scalaArgs: "",
scalaFileExtension: "scala",
scalaInject: "",
+ racketPath: "racket",
+ racketArgs: "",
+ racketFileExtension: "rkt",
+ racketInject: "#lang racket",
+ fsharpPath: "dotnet",
+ fsharpArgs: "",
+ fsharpInject: "",
+ fsharpFileExtension: "fsx",
cArgs: "",
cUseMain: true,
cInject: "",
+ rubyPath: "ruby",
+ rubyArgs: "",
+ rubyInject: "",
jsInteractive: true,
tsInteractive: false,
csInteractive: false,
+ leanInteractive: false,
luaInteractive: false,
+ dartInteractive: false,
pythonInteractive: true,
cppInteractive: false,
prologInteractive: false,
shellInteractive: false,
+ batchInteractive: false,
bashInteractive: false,
groovyInteractive: false,
rInteractive: false,
@@ -208,5 +259,8 @@ export const DEFAULT_SETTINGS: ExecutorSettings = {
mathematicaInteractive: false,
haskellInteractive: false,
scalaInteractive: false,
- cInteractive: false
+ fsharpInteractive: false,
+ cInteractive: false,
+ racketInteractive: false,
+ rubyInteractive: false
}
diff --git a/src/settings/SettingsTab.ts b/src/settings/SettingsTab.ts
index 7f252c75..0deb905d 100644
--- a/src/settings/SettingsTab.ts
+++ b/src/settings/SettingsTab.ts
@@ -4,21 +4,27 @@ import { DISPLAY_NAMES } from "./languageDisplayName";
import makeCppSettings from "./per-lang/makeCppSettings";
import makeCSettings from "./per-lang/makeCSettings.js";
import makeCsSettings from "./per-lang/makeCsSettings";
+import makeFSharpSettings from "./per-lang/makeFSharpSettings";
import makeGoSettings from "./per-lang/makeGoSettings";
import makeGroovySettings from "./per-lang/makeGroovySettings";
import makeHaskellSettings from "./per-lang/makeHaskellSettings";
import makeJavaSettings from "./per-lang/makeJavaSettings";
import makeJsSettings from "./per-lang/makeJsSettings";
import makeKotlinSettings from "./per-lang/makeKotlinSettings";
+import makeLeanSettings from "./per-lang/makeLeanSettings";
import makeLuaSettings from "./per-lang/makeLuaSettings";
+import makeDartSettings from "./per-lang/makeDartSettings";
import makeMathematicaSettings from "./per-lang/makeMathematicaSettings";
import makePowershellSettings from "./per-lang/makePowershellSettings";
import makePrologSettings from "./per-lang/makePrologSettings";
import makePythonSettings from "./per-lang/makePythonSettings";
import makeRSettings from "./per-lang/makeRSettings";
+import makeRubySettings from "./per-lang/makeRubySettings";
import makeRustSettings from "./per-lang/makeRustSettings";
import makeScalaSettings from "./per-lang/makeScalaSettings.js";
+import makeRacketSettings from "./per-lang/makeRacketSettings.js";
import makeShellSettings from "./per-lang/makeShellSettings";
+import makeBatchSettings from "./per-lang/makeBatchSettings";
import makeTsSettings from "./per-lang/makeTsSettings";
import {ExecutorSettings} from "./Settings";
@@ -117,68 +123,74 @@ export class SettingsTab extends PluginSettingTab {
// ========== TypeScript ==========
makeTsSettings(this, this.makeContainerFor("ts"));
+ // ========== Lean ==========
+ makeLeanSettings(this, this.makeContainerFor("lean"));
+
// ========== Lua ==========
makeLuaSettings(this, this.makeContainerFor("lua"));
+ // ========== Dart ==========
+ makeDartSettings(this, this.makeContainerFor("dart"));
+
// ========== CSharp ==========
makeCsSettings(this, this.makeContainerFor("cs"));
// ========== Java ==========
makeJavaSettings(this, this.makeContainerFor("java"));
-
// ========== Python ==========
makePythonSettings(this, this.makeContainerFor("python"));
-
// ========== Golang =========
makeGoSettings(this, this.makeContainerFor("go"));
-
// ========== Rust ===========
makeRustSettings(this, this.makeContainerFor("rust"));
-
// ========== C++ ===========
makeCppSettings(this, this.makeContainerFor("cpp"));
// ========== C ===========
makeCSettings(this, this.makeContainerFor("c"));
-
+ // ========== Batch ==========
+ makeBatchSettings(this, this.makeContainerFor("batch"));
// ========== Shell ==========
makeShellSettings(this, this.makeContainerFor("shell"));
-
// ========== Powershell ==========
makePowershellSettings(this, this.makeContainerFor("powershell"));
-
// ========== Prolog ==========
makePrologSettings(this, this.makeContainerFor("prolog"));
-
// ========== Groovy ==========
makeGroovySettings(this, this.makeContainerFor("groovy"));
-
// ========== R ==========
makeRSettings(this, this.makeContainerFor("r"));
-
// ========== Kotlin ==========
makeKotlinSettings(this, this.makeContainerFor("kotlin"));
// ========== Mathematica ==========
makeMathematicaSettings(this, this.makeContainerFor("mathematica"));
-
// ========== Haskell ===========
makeHaskellSettings(this, this.makeContainerFor("haskell"));
// ========== Scala ===========
makeScalaSettings(this, this.makeContainerFor("scala"));
-
+
+ // ========== Racket ===========
+ makeRacketSettings(this, this.makeContainerFor("racket"));
+
+ // ========== FSharp ===========
+ makeFSharpSettings(this, this.makeContainerFor("fsharp"));
+
+ // ========== Ruby ============
+ makeRubySettings(this, this.makeContainerFor("ruby"));
+
this.focusContainer(this.plugin.settings.lastOpenLanguageTab || canonicalLanguages[0]);
}
diff --git a/src/settings/languageDisplayName.ts b/src/settings/languageDisplayName.ts
index f90dfbd5..88c8a1d2 100644
--- a/src/settings/languageDisplayName.ts
+++ b/src/settings/languageDisplayName.ts
@@ -1,4 +1,4 @@
-import { LanguageId } from "src/main";
+import {LanguageId} from "src/main";
export const DISPLAY_NAMES: Record = {
cpp: "C++",
@@ -17,7 +17,13 @@ export const DISPLAY_NAMES: Record = {
r: "R",
rust: "Rust",
shell: "Shell",
+ batch: "Batch",
ts: "Typescript",
scala: "Scala",
- c: "C"
-} as const;
\ No newline at end of file
+ racket: "Racket",
+ c: "C",
+ fsharp: "F#",
+ ruby: "Ruby",
+ dart: "Dart",
+ lean: "Lean"
+} as const;
diff --git a/src/settings/per-lang/makeBatchSettings.ts b/src/settings/per-lang/makeBatchSettings.ts
new file mode 100644
index 00000000..fc0d49cf
--- /dev/null
+++ b/src/settings/per-lang/makeBatchSettings.ts
@@ -0,0 +1,37 @@
+import { Setting } from "obsidian";
+import { SettingsTab } from "../SettingsTab";
+
+export default (tab: SettingsTab, containerEl: HTMLElement) => {
+ containerEl.createEl('h3', { text: 'Batch Settings' });
+ new Setting(containerEl)
+ .setName('Batch path')
+ .setDesc('The path to the terminal. Default is command prompt.')
+ .addText(text => text
+ .setValue(tab.plugin.settings.batchPath)
+ .onChange(async (value) => {
+ const sanitized = tab.sanitizePath(value);
+ tab.plugin.settings.batchPath = sanitized;
+ console.log('Batch path set to: ' + sanitized);
+ await tab.plugin.saveSettings();
+ }));
+ new Setting(containerEl)
+ .setName('Batch arguments')
+ .addText(text => text
+ .setValue(tab.plugin.settings.batchArgs)
+ .onChange(async (value) => {
+ tab.plugin.settings.batchArgs = value;
+ console.log('Batch args set to: ' + value);
+ await tab.plugin.saveSettings();
+ }));
+ new Setting(containerEl)
+ .setName('Batch file extension')
+ .setDesc('Changes the file extension for generated batch scripts. Default is .bat')
+ .addText(text => text
+ .setValue(tab.plugin.settings.batchFileExtension)
+ .onChange(async (value) => {
+ tab.plugin.settings.batchFileExtension = value;
+ console.log('Batch file extension set to: ' + value);
+ await tab.plugin.saveSettings();
+ }));
+ tab.makeInjectSetting(containerEl, "batch");
+}
diff --git a/src/settings/per-lang/makeDartSettings.ts b/src/settings/per-lang/makeDartSettings.ts
new file mode 100644
index 00000000..def8ef5a
--- /dev/null
+++ b/src/settings/per-lang/makeDartSettings.ts
@@ -0,0 +1,26 @@
+import { Setting } from "obsidian";
+import { SettingsTab } from "../SettingsTab";
+
+export default (tab: SettingsTab, containerEl: HTMLElement) => {
+ containerEl.createEl('h3', { text: 'Dart Settings' });
+ new Setting(containerEl)
+ .setName('dart path')
+ .addText(text => text
+ .setValue(tab.plugin.settings.dartPath)
+ .onChange(async (value) => {
+ const sanitized = tab.sanitizePath(value);
+ tab.plugin.settings.dartPath = sanitized;
+ console.log('dart path set to: ' + sanitized);
+ await tab.plugin.saveSettings();
+ }));
+ new Setting(containerEl)
+ .setName('Dart arguments')
+ .addText(text => text
+ .setValue(tab.plugin.settings.dartArgs)
+ .onChange(async (value) => {
+ tab.plugin.settings.dartArgs = value;
+ console.log('Dart args set to: ' + value);
+ await tab.plugin.saveSettings();
+ }));
+ tab.makeInjectSetting(containerEl, "dart");
+}
diff --git a/src/settings/per-lang/makeFSharpSettings.ts b/src/settings/per-lang/makeFSharpSettings.ts
new file mode 100644
index 00000000..b45f4205
--- /dev/null
+++ b/src/settings/per-lang/makeFSharpSettings.ts
@@ -0,0 +1,37 @@
+import { Setting } from "obsidian";
+import { SettingsTab } from "../SettingsTab";
+
+export default (tab: SettingsTab, containerEl: HTMLElement) => {
+ containerEl.createEl('h3', { text: 'F# Settings' });
+ new Setting(containerEl)
+ .setName('F# path')
+ .setDesc('The path to dotnet.')
+ .addText(text => text
+ .setValue(tab.plugin.settings.fsharpPath)
+ .onChange(async (value) => {
+ const sanitized = tab.sanitizePath(value);
+ tab.plugin.settings.fsharpPath = sanitized;
+ console.log('F# path set to: ' + sanitized);
+ await tab.plugin.saveSettings();
+ }));
+ new Setting(containerEl)
+ .setName('F# arguments')
+ .addText(text => text
+ .setValue(tab.plugin.settings.fsharpArgs)
+ .onChange(async (value) => {
+ tab.plugin.settings.fsharpArgs = value;
+ console.log('F# args set to: ' + value);
+ await tab.plugin.saveSettings();
+ }));
+ new Setting(containerEl)
+ .setName('F# file extension')
+ .setDesc('Changes the file extension for generated F# scripts.')
+ .addText(text => text
+ .setValue(tab.plugin.settings.fsharpFileExtension)
+ .onChange(async (value) => {
+ tab.plugin.settings.fsharpFileExtension = value;
+ console.log('F# file extension set to: ' + value);
+ await tab.plugin.saveSettings();
+ }));
+ tab.makeInjectSetting(containerEl, "fsharp");
+}
\ No newline at end of file
diff --git a/src/settings/per-lang/makeLeanSettings.ts b/src/settings/per-lang/makeLeanSettings.ts
new file mode 100644
index 00000000..e1d8101a
--- /dev/null
+++ b/src/settings/per-lang/makeLeanSettings.ts
@@ -0,0 +1,26 @@
+import { Setting } from "obsidian";
+import { SettingsTab } from "../SettingsTab";
+
+export default (tab: SettingsTab, containerEl: HTMLElement) => {
+ containerEl.createEl('h3', { text: 'Lean Settings' });
+ new Setting(containerEl)
+ .setName('lean path')
+ .addText(text => text
+ .setValue(tab.plugin.settings.leanPath)
+ .onChange(async (value) => {
+ const sanitized = tab.sanitizePath(value);
+ tab.plugin.settings.leanPath = sanitized;
+ console.log('lean path set to: ' + sanitized);
+ await tab.plugin.saveSettings();
+ }));
+ new Setting(containerEl)
+ .setName('Lean arguments')
+ .addText(text => text
+ .setValue(tab.plugin.settings.leanArgs)
+ .onChange(async (value) => {
+ tab.plugin.settings.leanArgs = value;
+ console.log('Lean args set to: ' + value);
+ await tab.plugin.saveSettings();
+ }));
+ tab.makeInjectSetting(containerEl, "lean");
+}
diff --git a/src/settings/per-lang/makeRacketSettings.ts b/src/settings/per-lang/makeRacketSettings.ts
new file mode 100644
index 00000000..0e00ba15
--- /dev/null
+++ b/src/settings/per-lang/makeRacketSettings.ts
@@ -0,0 +1,27 @@
+import { Setting } from "obsidian";
+import { SettingsTab } from "../SettingsTab";
+
+export default (tab: SettingsTab, containerEl: HTMLElement) => {
+ containerEl.createEl('h3', { text: 'Racket Settings' });
+ new Setting(containerEl)
+ .setName('racket path')
+ .setDesc("Path to your racket installation")
+ .addText(text => text
+ .setValue(tab.plugin.settings.racketPath)
+ .onChange(async (value) => {
+ const sanitized = tab.sanitizePath(value);
+ tab.plugin.settings.racketPath = sanitized;
+ console.log('racket path set to: ' + sanitized);
+ await tab.plugin.saveSettings();
+ }));
+ new Setting(containerEl)
+ .setName('Racket arguments')
+ .addText(text => text
+ .setValue(tab.plugin.settings.racketArgs)
+ .onChange(async (value) => {
+ tab.plugin.settings.racketArgs = value;
+ console.log('Racket args set to: ' + value);
+ await tab.plugin.saveSettings();
+ }));
+ tab.makeInjectSetting(containerEl, "racket");
+}
diff --git a/src/settings/per-lang/makeRubySettings.ts b/src/settings/per-lang/makeRubySettings.ts
new file mode 100644
index 00000000..094ae343
--- /dev/null
+++ b/src/settings/per-lang/makeRubySettings.ts
@@ -0,0 +1,27 @@
+import { Setting } from "obsidian";
+import { SettingsTab } from "../SettingsTab";
+
+export default (tab: SettingsTab, containerEl: HTMLElement) => {
+ containerEl.createEl('h3', { text: 'Ruby Settings' });
+ new Setting(containerEl)
+ .setName('ruby path')
+ .setDesc("Path to your ruby installation")
+ .addText(text => text
+ .setValue(tab.plugin.settings.rubyPath)
+ .onChange(async (value) => {
+ const sanitized = tab.sanitizePath(value);
+ tab.plugin.settings.rubyPath = sanitized;
+ console.log('ruby path set to: ' + sanitized);
+ await tab.plugin.saveSettings();
+ }));
+ new Setting(containerEl)
+ .setName('ruby arguments')
+ .addText(text => text
+ .setValue(tab.plugin.settings.rubyArgs)
+ .onChange(async (value) => {
+ tab.plugin.settings.rubyArgs = value;
+ console.log('ruby args set to: ' + value);
+ await tab.plugin.saveSettings();
+ }));
+ tab.makeInjectSetting(containerEl, "ruby");
+}
diff --git a/src/transforms/Magic.ts b/src/transforms/Magic.ts
index c17d63b3..e3352646 100644
--- a/src/transforms/Magic.ts
+++ b/src/transforms/Magic.ts
@@ -8,6 +8,7 @@
* - `@vault`: Inserts the vault path as string.
* - `@note`: Inserts the note path as string.
* - `@title`: Inserts the note title as string.
+ * - `@theme`: Inserts the color theme; either `"light"` or `"dark"`. For use with images, inline plots, and `@html()`.
*/
import * as os from "os";
@@ -17,8 +18,13 @@ import { TOGGLE_HTML_SIGIL } from "src/Outputter";
const SHOW_REGEX = /@show\(["'](?[^<>?*=!\n#()\[\]{}]+)["'](,\s*(?\d+[\w%]+),?\s*(?\d+[\w%]+))?(,\s*(?left|center|right))?\)/g;
const HTML_REGEX = /@html\((?[^)]+)\)/g;
const VAULT_REGEX = /@vault/g
+const VAULT_PATH_REGEX = /@vault_path/g
+const VAULT_URL_REGEX = /@vault_url/g
const CURRENT_NOTE_REGEX = /@note/g;
+const CURRENT_NOTE_PATH_REGEX = /@note_path/g;
+const CURRENT_NOTE_URL_REGEX = /@note_url/g;
const NOTE_TITLE_REGEX = /@title/g;
+const COLOR_THEME_REGEX = /@theme/g;
// Regex that are only used by one language.
const PYTHON_PLOT_REGEX = /^(plt|matplotlib.pyplot|pyplot)\.show\(\)/gm;
@@ -32,7 +38,11 @@ const R_PLOT_REGEX = /^plot\(.*\)/gm;
* @returns The transformed source code.
*/
export function insertVaultPath(source: string, vaultPath: string): string {
- return source.replace(VAULT_REGEX, `"app://local/${vaultPath.replace(/\\/g, "/")}"`);
+ source = source.replace(VAULT_REGEX, `"app://local/${vaultPath.replace(/\\/g, "/")}"`);
+ source = source.replace(VAULT_URL_REGEX, `"app://local/${vaultPath.replace(/\\/g, "/")}"`);
+ source = source.replace(VAULT_PATH_REGEX, `"${vaultPath.replace(/\\/g, "/")}"`);
+
+ return source;
}
@@ -44,7 +54,11 @@ export function insertVaultPath(source: string, vaultPath: string): string {
* @returns The transformed source code.
*/
export function insertNotePath(source: string, notePath: string): string {
- return source.replace(CURRENT_NOTE_REGEX, `"app://local/${notePath.replace(/\\/g, "/")}"`);
+ source = source.replace(CURRENT_NOTE_REGEX, `"app://local/${notePath.replace(/\\/g, "/")}"`);
+ source = source.replace(CURRENT_NOTE_URL_REGEX, `"app://local/${notePath.replace(/\\/g, "/")}"`);
+ source = source.replace(CURRENT_NOTE_PATH_REGEX, `"${notePath.replace(/\\/g, "/")}"`);
+
+ return source;
}
@@ -63,6 +77,16 @@ export function insertNoteTitle(source: string, noteTitle: string): string {
return source.replace(NOTE_TITLE_REGEX, `"${t}"`);
}
+/**
+ * Parses the source code for the @theme command and replaces it with the colour theme.
+ *
+ * @param source The source code to parse.
+ * @param noteTitle The current colour theme.
+ * @returns The transformed source code.
+ */
+export function insertColorTheme(source: string, theme: string): string {
+ return source.replace(COLOR_THEME_REGEX, `"${theme}"`);
+}
/**
* Add the @show command to python. @show is only supported in python and javascript.
diff --git a/src/transforms/TransformCode.ts b/src/transforms/TransformCode.ts
index ad4377a1..c5cf527e 100644
--- a/src/transforms/TransformCode.ts
+++ b/src/transforms/TransformCode.ts
@@ -1,4 +1,4 @@
-import {insertNotePath, insertNoteTitle, insertVaultPath} from "./Magic";
+import {insertColorTheme, insertNotePath, insertNoteTitle, insertVaultPath} from "./Magic";
import {getVaultVariables} from "src/Vault";
import {canonicalLanguages} from 'src/main';
import type {App} from "obsidian";
@@ -42,6 +42,7 @@ export function transformMagicCommands(app: App, srcCode: string) {
ret = insertVaultPath(ret, vars.vaultPath);
ret = insertNotePath(ret, vars.filePath);
ret = insertNoteTitle(ret, vars.fileName);
+ ret = insertColorTheme(ret, vars.theme);
} else {
console.warn(`Could not load all Vault variables! ${vars}`)
}
diff --git a/versions.json b/versions.json
index ebd78511..d66bb797 100644
--- a/versions.json
+++ b/versions.json
@@ -34,5 +34,6 @@
"1.2.0": "0.12.0",
"1.3.0": "0.12.0",
"1.4.0": "0.12.0",
- "1.5.0": "0.12.0"
+ "1.5.0": "0.12.0",
+ "1.6.0": "0.12.0"
}
\ No newline at end of file