Skip to content

Commit

Permalink
Merge branch 'latenitecoding_develop' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
#	src/main.ts
#	src/settings/languageDisplayName.ts
  • Loading branch information
twibiral committed Dec 26, 2022
2 parents 3ba68d9 + 83ed3f9 commit 1a52938
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 21 deletions.
16 changes: 14 additions & 2 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, Racket, Shell & Powershell.
The following [languages are supported](#supported-programming-languages): C, CPP, Golang, Groovy, Kotlin, Java, JavaScript, TypeScript, Lean, Lua, CSharp, Prolog, Rust, Python, R, Wolfram Mathematica, Haskell, Scala, Racket, F#, 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 @@ -134,6 +134,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 @@ -360,7 +373,6 @@ The following magic commands are supported:
- `@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
- `@theme`: Inserts the color theme; either `"light"` or `"dark"`. For use with images, inline plots, and `@html()`.

(`@show(...)` and `@html(...)` are only supported for JavaScript and Python yet.)

Expand Down
25 changes: 6 additions & 19 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ 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", "racket", "fsharp", "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"] as const;
export const supportedLanguages = [...languageAliases, ...canonicalLanguages] as const;


Expand Down Expand Up @@ -108,8 +108,7 @@ export default class ExecuteCodePlugin extends Plugin {
.forEach((out: HTMLElement) => out.remove());

for (const executor of this.executors) {
executor.stop().then(_ => { /* do nothing */
});
executor.stop().then(_ => { /* do nothing */ });
}

console.log("Unloaded plugin: Execute Code");
Expand Down Expand Up @@ -152,7 +151,7 @@ export default class ExecuteCodePlugin extends Plugin {
private addRunButtons(element: HTMLElement, file: string) {
Array.from(element.getElementsByTagName("code"))
.forEach((codeBlock: HTMLElement) => {
if (codeBlock.className.match(/^language-\{\w+/i)) {
if (codeBlock.className.match(/^language-\{\w+/i)){
codeBlock.className = codeBlock.className.replace(/^language-\{(\w+)/i, "language-$1 {");
codeBlock.parentElement.className = codeBlock.className;
}
Expand Down Expand Up @@ -316,7 +315,7 @@ export default class ExecuteCodePlugin extends Plugin {
button.addEventListener("click", async () => {
button.className = runButtonDisabledClass;
const transformedCode = await new CodeInjector(this.app, this.settings, "haskell").injectCode(srcCode);
this.runCodeInShell(transformedCode, out, button, this.settings.useGhci ? this.settings.ghciPath : this.settings.runghcPath, this.settings.useGhci ? "" : "-f " + this.settings.ghcPath, "hs", language, file);
this.runCodeInShell(transformedCode, out, button, this.settings.useGhci ? this.settings.ghciPath : this.settings.runghcPath, this.settings.useGhci ? "" : "-f "+this.settings.ghcPath, "hs", language, file);
});

} else if (language === "mathematica") {
Expand All @@ -331,24 +330,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.scalaPath, this.settings.scalaArgs, this.settings.scalaFileExtension, language, file);
});
} else if (language === "fsharp") {
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.fsharpPath, this.settings.fsharpArgs, this.settings.fsharpFileExtension, language, file);
});
} else if (language === "c") {
} else if(language === "c") {
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.clingPath, this.settings.clingArgs, "c", language, file);
})
} else if (language === "racket") {
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.racketPath, this.settings.racketArgs, this.settings.racketFileExtension, language, file);
});
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/settings/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export interface ExecutorSettings {
tsPath: string;
tsArgs: string;
tsInject: string;
leanPath: string;
leanArgs: string;
leanInject: string;
luaPath: string;
luaArgs: string;
luaInject: string;
Expand Down Expand Up @@ -94,6 +97,7 @@ export interface ExecutorSettings {
jsInteractive: boolean;
tsInteractive: boolean;
csInteractive: boolean;
leanInteractive: boolean;
luaInteractive: boolean;
pythonInteractive: boolean;
cppInteractive: boolean;
Expand Down Expand Up @@ -131,6 +135,9 @@ export const DEFAULT_SETTINGS: ExecutorSettings = {
tsPath: "ts-node",
tsArgs: "",
tsInject: "",
leanPath: "lean",
leanArgs: "",
leanInject: "",
luaPath: "lua",
luaArgs: "",
luaInject: "",
Expand Down Expand Up @@ -210,6 +217,7 @@ export const DEFAULT_SETTINGS: ExecutorSettings = {
jsInteractive: true,
tsInteractive: false,
csInteractive: false,
leanInteractive: false,
luaInteractive: false,
pythonInteractive: true,
cppInteractive: false,
Expand Down
4 changes: 4 additions & 0 deletions src/settings/SettingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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 makeMathematicaSettings from "./per-lang/makeMathematicaSettings";
import makePowershellSettings from "./per-lang/makePowershellSettings";
Expand Down Expand Up @@ -119,6 +120,9 @@ export class SettingsTab extends PluginSettingTab {
// ========== TypeScript ==========
makeTsSettings(this, this.makeContainerFor("ts"));

// ========== Lean ==========
makeLeanSettings(this, this.makeContainerFor("lean"));

// ========== Lua ==========
makeLuaSettings(this, this.makeContainerFor("lua"));

Expand Down
1 change: 1 addition & 0 deletions src/settings/languageDisplayName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const DISPLAY_NAMES: Record<LanguageId, string> = {
java: "Java",
js: "Javascript",
kotlin: "Kotlin",
lean: "Lean",
lua: "Lua",
mathematica: "Mathematica",
powershell: "Powershell",
Expand Down
26 changes: 26 additions & 0 deletions src/settings/per-lang/makeLeanSettings.ts
Original file line number Diff line number Diff line change
@@ -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");
}

0 comments on commit 1a52938

Please sign in to comment.