Skip to content

Commit f4fd48b

Browse files
authored
Update to version 1.9.1
Update to version 1.9.1
2 parents e3d9184 + 9c70dba commit f4fd48b

10 files changed

Lines changed: 56 additions & 9 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ data.json
2020

2121
# Exclude macOS Finder (System Explorer) View States
2222
.DS_Store
23+
*.log

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77

8+
## [1.9.1]
9+
### Changed
10+
- Fix bug produced by duplicate labeled code blocks (Thanks to @qiaogaojian)
11+
12+
### Added
13+
- Option for better handling of logs (Thanks to @qiaogaojian)
14+
- Make labels work with code blocks with `run-` prefix (Thanks to @qiaogaojian)
15+
16+
817
## [1.9.0]
918
### Changed
1019
- Fix app://local deprecation (New minimal Obsidian version: v1.2.8) (Thanks to @mayurankv)

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "execute-code",
33
"name": "Execute Code",
4-
"version": "1.9.0",
4+
"version": "1.9.1",
55
"minAppVersion": "1.2.8",
66
"description": "Allows to execute code snippets within a note. 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.",
77
"author": "twibiral",

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "execute-code",
3-
"version": "1.9.0",
3+
"version": "1.9.1",
44
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
55
"main": "src/main.js",
66
"scripts": {

src/settings/Settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface ExecutorSettings {
99
timeout: number;
1010
allowInput: boolean;
1111
wslMode: boolean;
12+
onlyCurrentBlock: boolean;
1213
nodePath: string;
1314
nodeArgs: string;
1415
jsFileExtension: string;
@@ -170,6 +171,7 @@ export const DEFAULT_SETTINGS: ExecutorSettings = {
170171
timeout: 10000,
171172
allowInput: true,
172173
wslMode: false,
174+
onlyCurrentBlock: false,
173175
nodePath: "node",
174176
nodeArgs: "",
175177
jsFileExtension: "js",

src/settings/SettingsTab.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ export class SettingsTab extends PluginSettingTab {
100100
}));
101101
}
102102

103+
new Setting(containerEl)
104+
.setName('Only Current Log')
105+
.setDesc("Whether or not show print log only in current code block.")
106+
.addToggle(text => text
107+
.setValue(this.plugin.settings.onlyCurrentBlock)
108+
.onChange(async (value) => {
109+
console.log('Only Show Current Block Log set to: ' + value);
110+
this.plugin.settings.onlyCurrentBlock = value
111+
await this.plugin.saveSettings();
112+
}));
113+
103114
// TODO setting per language that requires main function if main function should be implicitly made or not, if not, non-main blocks will not have a run button
104115

105116
containerEl.createEl("hr");

src/transforms/CodeInjector.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class CodeInjector {
8585
new Notice(`Named export "${namedImport}" does not exist but was imported`);
8686
return true;
8787
}
88-
this.namedImportSrcCode += `${this.namedExports[namedImport]}\n`;
88+
this.namedImportSrcCode += `${this.disable_print(this.namedExports[namedImport])}\n`;
8989
return false;
9090
};
9191
// Single import
@@ -145,13 +145,13 @@ export class CodeInjector {
145145
if (!Array.isArray(currentArgs.export))
146146
currentArgs.export = [currentArgs.export];
147147
if (currentArgs.export.contains("pre"))
148-
this.prependSrcCode += `${currentCode}\n`;
148+
this.prependSrcCode += `${this.disable_print(currentCode)}\n`;
149149
if (currentArgs.export.contains("post"))
150-
this.appendSrcCode += `${currentCode}\n`;
150+
this.appendSrcCode += `${this.disable_print(currentCode)}\n`;
151151
currentLanguage = "";
152152
currentCode = "";
153153
insideCodeBlock = false;
154-
154+
currentArgs = {};
155155
}
156156

157157
// reached start of code block
@@ -170,4 +170,13 @@ export class CodeInjector {
170170
}
171171
}
172172
}
173+
174+
private disable_print(code: String): String {
175+
if (!this.settings.onlyCurrentBlock) {
176+
return code;
177+
}
178+
const pattern: RegExp = /^print\s*(.*)/gm;
179+
// 使用正则表达式替换函数将符合条件的内容注释掉
180+
return code.replace(pattern, ' ');
181+
}
173182
}

src/transforms/TransformCode.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,19 @@ export function transformMagicCommands(app: App, srcCode: string) {
5757
* @returns The language of the code block.
5858
*/
5959
export function getCodeBlockLanguage(firstLineOfCode: string) {
60-
return getLanguageAlias(firstLineOfCode.split("```")[1].trim().split(" ")[0].split("{")[0])
60+
let currentLanguage: string = firstLineOfCode.split("```")[1].trim().split(" ")[0].split("{")[0];
61+
if (isStringNotEmpty(currentLanguage) && currentLanguage.startsWith("run-")) {
62+
currentLanguage = currentLanguage.replace("run-", "");
63+
}
64+
return getLanguageAlias(currentLanguage);
65+
}
66+
67+
/**
68+
* Check if a string is not empty
69+
*
70+
* @param str Input string
71+
* @returns True when string not empty, False when the string is Empty
72+
*/
73+
export function isStringNotEmpty(str: string): boolean {
74+
return !!str && str.trim().length > 0;
6175
}

versions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@
4242
"1.7.1": "0.12.0",
4343
"1.8.0": "0.12.0",
4444
"1.8.1": "0.12.0",
45-
"1.9.0": "1.2.8"
45+
"1.9.0": "1.2.8",
46+
"1.9.1": "1.2.8"
4647
}

0 commit comments

Comments
 (0)