feat: Add scope line support

This commit is contained in:
Yaotian-Liu 2023-05-28 15:53:29 +08:00
parent 5b83128ca8
commit f163b33861
No known key found for this signature in database
GPG key ID: 160A5464FF2FBA1F
3 changed files with 62 additions and 36 deletions

View file

@ -1,39 +1,41 @@
// This is the setting for pseudocode.js
export interface PseudocodeJsSettings {
indentSize: string;
commentDelimiter: string;
lineNumber: boolean;
lineNumberPunc: string;
noEnd: boolean;
captionCount: undefined;
indentSize: string;
commentDelimiter: string;
lineNumber: boolean;
lineNumberPunc: string;
noEnd: boolean;
captionCount: undefined;
scopeLines: boolean;
}
// Setting for this plugin
export interface PseudocodeSettings {
blockSize: number;
preamblePath: string;
preambleLoadedNotice: boolean;
jsSettings: PseudocodeJsSettings;
blockSize: number;
preamblePath: string;
preambleLoadedNotice: boolean;
jsSettings: PseudocodeJsSettings;
}
export const DEFAULT_SETTINGS: PseudocodeSettings = {
blockSize: 99,
preamblePath: "preamble.sty",
preambleLoadedNotice: false,
jsSettings: {
indentSize: "1.2em",
commentDelimiter: "//",
lineNumber: false,
lineNumberPunc: ":",
noEnd: false,
captionCount: undefined,
}
blockSize: 99,
preamblePath: "preamble.sty",
preambleLoadedNotice: false,
jsSettings: {
indentSize: "1.2em",
commentDelimiter: "//",
lineNumber: false,
lineNumberPunc: ":",
noEnd: false,
captionCount: undefined,
scopeLines: false,
},
};
export const PseudocodeBlockInit =
"```pseudo\n" +
"\t\\begin{algorithm}\n\t\\caption{Algo Caption}\n\t\\begin{algorithmic}" +
"\n\n\t\\end{algorithmic}\n\t\\end{algorithm}" +
"\n```";
"```pseudo\n" +
"\t\\begin{algorithm}\n\t\\caption{Algo Caption}\n\t\\begin{algorithmic}" +
"\n\n\t\\end{algorithmic}\n\t\\end{algorithm}" +
"\n```";
export const BLOCK_NAME = "pseudo";
export const BLOCK_NAME = "pseudo";

View file

@ -1,8 +1,4 @@
import {
App,
PluginSettingTab,
Setting,
} from "obsidian";
import { App, PluginSettingTab, Setting } from "obsidian";
import PseudocodePlugin from "main";
@ -28,8 +24,8 @@ export class PseudocodeSettingTab extends PluginSettingTab {
.setName("Block Size")
.setDesc(
"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." +
" '30' looks good for me."
" The default value is 99, which will work as the max width of the editor." +
" '30' looks good for me."
)
.addText((text) =>
text
@ -63,7 +59,8 @@ export class PseudocodeSettingTab extends PluginSettingTab {
text
.setValue(this.plugin.settings.jsSettings.commentDelimiter)
.onChange(async (value) => {
this.plugin.settings.jsSettings.commentDelimiter = value;
this.plugin.settings.jsSettings.commentDelimiter =
value;
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" });
// Instantiate Preamble Path setting
@ -132,7 +144,9 @@ export class PseudocodeSettingTab extends PluginSettingTab {
// Instantiate Preamble Load Sign setting
new Setting(containerEl)
.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) =>
toggle
.setValue(this.plugin.settings.preambleLoadedNotice)
@ -142,4 +156,4 @@ export class PseudocodeSettingTab extends PluginSettingTab {
})
);
}
}
}

View file

@ -1425,6 +1425,16 @@ If your plugin does not need CSS, delete this file.
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 {
font-family: var(--font-monospace);
font-size: 0.875rem;