mirror of
https://github.com/ytliu74/obsidian-pseudocode.git
synced 2026-07-22 07:40:25 +00:00
feat: Add scope line support
This commit is contained in:
parent
5b83128ca8
commit
f163b33861
3 changed files with 62 additions and 36 deletions
|
|
@ -1,39 +1,41 @@
|
||||||
// This is the setting for pseudocode.js
|
// This is the setting for pseudocode.js
|
||||||
export interface PseudocodeJsSettings {
|
export interface PseudocodeJsSettings {
|
||||||
indentSize: string;
|
indentSize: string;
|
||||||
commentDelimiter: string;
|
commentDelimiter: string;
|
||||||
lineNumber: boolean;
|
lineNumber: boolean;
|
||||||
lineNumberPunc: string;
|
lineNumberPunc: string;
|
||||||
noEnd: boolean;
|
noEnd: boolean;
|
||||||
captionCount: undefined;
|
captionCount: undefined;
|
||||||
|
scopeLines: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setting for this plugin
|
// Setting for this plugin
|
||||||
export interface PseudocodeSettings {
|
export interface PseudocodeSettings {
|
||||||
blockSize: number;
|
blockSize: number;
|
||||||
preamblePath: string;
|
preamblePath: string;
|
||||||
preambleLoadedNotice: boolean;
|
preambleLoadedNotice: boolean;
|
||||||
jsSettings: PseudocodeJsSettings;
|
jsSettings: PseudocodeJsSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DEFAULT_SETTINGS: PseudocodeSettings = {
|
export const DEFAULT_SETTINGS: PseudocodeSettings = {
|
||||||
blockSize: 99,
|
blockSize: 99,
|
||||||
preamblePath: "preamble.sty",
|
preamblePath: "preamble.sty",
|
||||||
preambleLoadedNotice: false,
|
preambleLoadedNotice: false,
|
||||||
jsSettings: {
|
jsSettings: {
|
||||||
indentSize: "1.2em",
|
indentSize: "1.2em",
|
||||||
commentDelimiter: "//",
|
commentDelimiter: "//",
|
||||||
lineNumber: false,
|
lineNumber: false,
|
||||||
lineNumberPunc: ":",
|
lineNumberPunc: ":",
|
||||||
noEnd: false,
|
noEnd: false,
|
||||||
captionCount: undefined,
|
captionCount: undefined,
|
||||||
}
|
scopeLines: false,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const PseudocodeBlockInit =
|
export const PseudocodeBlockInit =
|
||||||
"```pseudo\n" +
|
"```pseudo\n" +
|
||||||
"\t\\begin{algorithm}\n\t\\caption{Algo Caption}\n\t\\begin{algorithmic}" +
|
"\t\\begin{algorithm}\n\t\\caption{Algo Caption}\n\t\\begin{algorithmic}" +
|
||||||
"\n\n\t\\end{algorithmic}\n\t\\end{algorithm}" +
|
"\n\n\t\\end{algorithmic}\n\t\\end{algorithm}" +
|
||||||
"\n```";
|
"\n```";
|
||||||
|
|
||||||
export const BLOCK_NAME = "pseudo";
|
export const BLOCK_NAME = "pseudo";
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,4 @@
|
||||||
import {
|
import { App, PluginSettingTab, Setting } from "obsidian";
|
||||||
App,
|
|
||||||
PluginSettingTab,
|
|
||||||
Setting,
|
|
||||||
} from "obsidian";
|
|
||||||
|
|
||||||
import PseudocodePlugin from "main";
|
import PseudocodePlugin from "main";
|
||||||
|
|
||||||
|
|
@ -28,8 +24,8 @@ export class PseudocodeSettingTab extends PluginSettingTab {
|
||||||
.setName("Block Size")
|
.setName("Block Size")
|
||||||
.setDesc(
|
.setDesc(
|
||||||
"The width of the pseudocode block. The unit is 'em'." +
|
"The width of the pseudocode block. The unit is 'em'." +
|
||||||
" The default value is 99, which will work as the max width of the editor." +
|
" The default value is 99, which will work as the max width of the editor." +
|
||||||
" '30' looks good for me."
|
" '30' looks good for me."
|
||||||
)
|
)
|
||||||
.addText((text) =>
|
.addText((text) =>
|
||||||
text
|
text
|
||||||
|
|
@ -63,7 +59,8 @@ export class PseudocodeSettingTab extends PluginSettingTab {
|
||||||
text
|
text
|
||||||
.setValue(this.plugin.settings.jsSettings.commentDelimiter)
|
.setValue(this.plugin.settings.jsSettings.commentDelimiter)
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
this.plugin.settings.jsSettings.commentDelimiter = value;
|
this.plugin.settings.jsSettings.commentDelimiter =
|
||||||
|
value;
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
@ -111,6 +108,21 @@ export class PseudocodeSettingTab extends PluginSettingTab {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Instantiate scope lines toggle setting
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName("Scope Lines")
|
||||||
|
.setDesc(
|
||||||
|
"If enabled, pseudocode blocks will have lines indicating the scope of the block."
|
||||||
|
)
|
||||||
|
.addToggle((toggle) =>
|
||||||
|
toggle
|
||||||
|
.setValue(this.plugin.settings.jsSettings.scopeLines)
|
||||||
|
.onChange(async (value) => {
|
||||||
|
this.plugin.settings.jsSettings.scopeLines = value;
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
containerEl.createEl("h2", { text: "Preamble Settings" });
|
containerEl.createEl("h2", { text: "Preamble Settings" });
|
||||||
|
|
||||||
// Instantiate Preamble Path setting
|
// Instantiate Preamble Path setting
|
||||||
|
|
@ -132,7 +144,9 @@ export class PseudocodeSettingTab extends PluginSettingTab {
|
||||||
// Instantiate Preamble Load Sign setting
|
// Instantiate Preamble Load Sign setting
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName("Preamble Loaded Notice")
|
.setName("Preamble Loaded Notice")
|
||||||
.setDesc("Whether to show a notice everytime the preamble is loaded.")
|
.setDesc(
|
||||||
|
"Whether to show a notice everytime the preamble is loaded."
|
||||||
|
)
|
||||||
.addToggle((toggle) =>
|
.addToggle((toggle) =>
|
||||||
toggle
|
toggle
|
||||||
.setValue(this.plugin.settings.preambleLoadedNotice)
|
.setValue(this.plugin.settings.preambleLoadedNotice)
|
||||||
|
|
@ -142,4 +156,4 @@ export class PseudocodeSettingTab extends PluginSettingTab {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
10
styles.css
10
styles.css
|
|
@ -1425,6 +1425,16 @@ If your plugin does not need CSS, delete this file.
|
||||||
text-indent: 0;
|
text-indent: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* scope lines support */
|
||||||
|
.ps-root .ps-algorithmic.with-scopelines div.ps-block {
|
||||||
|
border-left-style: solid;
|
||||||
|
border-left-width: 0.1em;
|
||||||
|
padding-left: 0.6em;
|
||||||
|
}
|
||||||
|
.ps-root .ps-algorithmic.with-scopelines > div.ps-block {
|
||||||
|
border-left: none;
|
||||||
|
}
|
||||||
|
|
||||||
.error-message {
|
.error-message {
|
||||||
font-family: var(--font-monospace);
|
font-family: var(--font-monospace);
|
||||||
font-size: 0.875rem;
|
font-size: 0.875rem;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue