Skip to content

Commit

Permalink
feat: add a toggle for MS syntax in live preview
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Jan 11, 2022
1 parent f6c70a7 commit 8b73f47
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/@types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface ISettingsData {
injectColor: boolean;
parseTitles: boolean;
allowMSSyntax: boolean;
livePreviewMS: boolean;
}

export type AdmonitionIconDefinition = {
Expand Down
6 changes: 5 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ const DEFAULT_APP_SETTINGS: ISettingsData = {
enableMarkdownProcessor: false,
injectColor: true,
parseTitles: true,
allowMSSyntax: true
allowMSSyntax: true,
livePreviewMS: true
};

export default class ObsidianAdmonition extends Plugin {
Expand Down Expand Up @@ -524,6 +525,7 @@ export default class ObsidianAdmonition extends Plugin {
}

update(update: ViewUpdate) {
if (!self.data.livePreviewMS) return;
const md = update.view.state.field(editorViewField);
if (!md.leaf?.view) return;
const { state } = md.leaf?.getViewState() ?? {};
Expand Down Expand Up @@ -554,6 +556,8 @@ export default class ObsidianAdmonition extends Plugin {
destroy() {}

build(view: EditorView) {
if (!self.data.allowMSSyntax) return;
if (!self.data.livePreviewMS) return;
const targetElements: TokenSpec[] = [];
const md = view.state.field(editorViewField);
const { state } = md.leaf.getViewState() ?? {};
Expand Down
25 changes: 25 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,34 @@ export default class AdmonitionSetting extends PluginSettingTab {
.addToggle((t) => {
t.setValue(this.plugin.data.allowMSSyntax).onChange((v) => {
this.plugin.data.allowMSSyntax = v;
this.display();
this.plugin.saveSettings();
});
});
if (this.plugin.data.allowMSSyntax) {
new Setting(containerEl)
.setName("Render Microsoft Document Syntax in Live Preview")
.setDesc(
createFragment((e) => {
e.createSpan({
text: "The plugin will render blockquotes created using the "
});
e.createEl("a", {
href: "https://docs.microsoft.com/en-us/contribute/markdown-reference",
text: "Microsoft Document Syntax"
});
e.createSpan({
text: " in live preview mode."
});
})
)
.addToggle((t) => {
t.setValue(this.plugin.data.livePreviewMS).onChange((v) => {
this.plugin.data.livePreviewMS = v;
this.plugin.saveSettings();
});
});
}

const publish = new Setting(containerEl)
.setName("Generate JS for Publish")
Expand Down

0 comments on commit 8b73f47

Please sign in to comment.