Skip to content

Commit 546710d

Browse files
committed
add ignore code block restrictions setting
1 parent 375ccc1 commit 546710d

File tree

5 files changed

+48
-37
lines changed

5 files changed

+48
-37
lines changed
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
---
22
editor: |-
3-
This is some text.
3+
test
44
5-
**Some bold text.**
6-
7-
# And a Heading
5+
**test**
86
---
97

10-
118
```meta-bind
129
INPUT[editor(showcase):editor]
1310
```

exampleVault/examples.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
slider1: 1
3+
---
4+
15
---
26
slider1: 7
37
nested:

package-lock.json

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

src/inputFields/InputFieldFactory.ts

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
import { ToggleInputField } from './ToggleInputField';
2-
import { InputFieldMarkdownRenderChild, InputFieldMarkdownRenderChildType } from '../InputFieldMarkdownRenderChild';
3-
import { TextInputField } from './TextInputField';
4-
import { SliderInputField } from './SliderInputField';
5-
import { TextAreaInputField } from './TextAreaInputField';
6-
import { SelectInputField } from './SelectInputField';
7-
import { MultiSelectInputField } from './MultiSelectInputField';
8-
import { DateInputField } from './DateInputField';
9-
import { TimeInputField } from './TimeInputField';
10-
import { AbstractInputField } from './AbstractInputField';
11-
import { InputFieldType } from '../parsers/InputFieldDeclarationParser';
12-
import { DatePickerInputField } from './DatePicker/DatePickerInputField';
13-
import { NumberInputField } from './NumberInputField';
14-
import { SuggestInputField } from './Suggest/SuggestInputField';
15-
import { MetaBindParsingError } from '../utils/MetaBindErrors';
16-
import { EditorInputField } from './Editor/EditorInputField';
17-
import { ImageSuggestInputField } from './ImageSuggest/ImageSuggestInputField';
1+
import {ToggleInputField} from './ToggleInputField';
2+
import {InputFieldMarkdownRenderChild, InputFieldMarkdownRenderChildType} from '../InputFieldMarkdownRenderChild';
3+
import {TextInputField} from './TextInputField';
4+
import {SliderInputField} from './SliderInputField';
5+
import {TextAreaInputField} from './TextAreaInputField';
6+
import {SelectInputField} from './SelectInputField';
7+
import {MultiSelectInputField} from './MultiSelectInputField';
8+
import {DateInputField} from './DateInputField';
9+
import {TimeInputField} from './TimeInputField';
10+
import {AbstractInputField} from './AbstractInputField';
11+
import {InputFieldType} from '../parsers/InputFieldDeclarationParser';
12+
import {DatePickerInputField} from './DatePicker/DatePickerInputField';
13+
import {NumberInputField} from './NumberInputField';
14+
import {SuggestInputField} from './Suggest/SuggestInputField';
15+
import {MetaBindParsingError} from '../utils/MetaBindErrors';
16+
import {EditorInputField} from './Editor/EditorInputField';
17+
import {ImageSuggestInputField} from './ImageSuggest/ImageSuggestInputField';
18+
import MetaBindPlugin from '../main';
1819

1920
export class InputFieldFactory {
2021
static allowCodeBlockMap: Record<string, { codeBlock: boolean; inlineCodeBlock: boolean }> = {
@@ -76,51 +77,46 @@ export class InputFieldFactory {
7677
inputFieldType: InputFieldType,
7778
args: { type: InputFieldMarkdownRenderChildType; inputFieldMarkdownRenderChild: InputFieldMarkdownRenderChild; onValueChanged: (value: any) => void | Promise<void> }
7879
): AbstractInputField | undefined {
80+
if (inputFieldType !== InputFieldType.INVALID) {
81+
InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type, args.inputFieldMarkdownRenderChild.plugin);
82+
}
83+
7984
if (inputFieldType === InputFieldType.TOGGLE) {
80-
InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type);
8185
return new ToggleInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged);
8286
} else if (inputFieldType === InputFieldType.SLIDER) {
83-
InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type);
8487
return new SliderInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged);
8588
} else if (inputFieldType === InputFieldType.TEXT) {
86-
InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type);
8789
return new TextInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged);
8890
} else if (inputFieldType === InputFieldType.TEXT_AREA) {
89-
InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type);
9091
return new TextAreaInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged);
9192
} else if (inputFieldType === InputFieldType.SELECT) {
92-
InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type);
9393
return new SelectInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged);
9494
} else if (inputFieldType === InputFieldType.MULTI_SELECT) {
95-
InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type);
9695
return new MultiSelectInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged);
9796
} else if (inputFieldType === InputFieldType.DATE) {
98-
InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type);
9997
return new DateInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged);
10098
} else if (inputFieldType === InputFieldType.TIME) {
101-
InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type);
10299
return new TimeInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged);
103100
} else if (inputFieldType === InputFieldType.DATE_PICKER) {
104-
InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type);
105101
return new DatePickerInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged);
106102
} else if (inputFieldType === InputFieldType.NUMBER) {
107-
InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type);
108103
return new NumberInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged);
109104
} else if (inputFieldType === InputFieldType.SUGGESTER) {
110-
InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type);
111105
return new SuggestInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged);
112106
} else if (inputFieldType === InputFieldType.EDITOR) {
113-
InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type);
114107
return new EditorInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged);
115108
} else if (inputFieldType === InputFieldType.IMAGE_SUGGESTER) {
116-
InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type);
117109
return new ImageSuggestInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged);
118110
}
119111

120112
return undefined;
121113
}
122114

123-
static checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType: InputFieldType, type: InputFieldMarkdownRenderChildType): void {
115+
static checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType: InputFieldType, type: InputFieldMarkdownRenderChildType, plugin: MetaBindPlugin): void {
116+
if (plugin.settings.ignoreCodeBlockRestrictions) {
117+
return;
118+
}
119+
124120
const allowCodeBlock: { codeBlock: boolean; inlineCodeBlock: boolean } = InputFieldFactory.allowCodeBlockMap[inputFieldType];
125121
if (type === InputFieldMarkdownRenderChildType.CODE_BLOCK && !allowCodeBlock.codeBlock) {
126122
throw new MetaBindParsingError(`'${inputFieldType}' is not allowed as code block`);

src/settings/Settings.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import MetaBindPlugin from '../main';
33

44
export interface MetaBindPluginSettings {
55
devMode: boolean;
6+
ignoreCodeBlockRestrictions: boolean,
67
preferredDateFormat: string;
78
useUsDateInputOrder: boolean;
89
syncInterval: number;
@@ -14,6 +15,7 @@ export interface MetaBindPluginSettings {
1415

1516
export const DEFAULT_SETTINGS: MetaBindPluginSettings = {
1617
devMode: false,
18+
ignoreCodeBlockRestrictions: false,
1719
preferredDateFormat: 'YYYY-MM-DD',
1820
useUsDateInputOrder: false,
1921
syncInterval: 200,
@@ -108,5 +110,16 @@ export class MetaBindSettingTab extends PluginSettingTab {
108110
this.plugin.saveSettings();
109111
});
110112
});
113+
114+
new Setting(containerEl)
115+
.setName('Ignore Code Block Restrictions')
116+
.setDesc('Ignore restrictions, which input fields can be created in which code blocks. Not recommended unless you know what you are doing.')
117+
.addToggle(cb => {
118+
cb.setValue(this.plugin.settings.ignoreCodeBlockRestrictions);
119+
cb.onChange(data => {
120+
this.plugin.settings.ignoreCodeBlockRestrictions = data;
121+
this.plugin.saveSettings();
122+
});
123+
});
111124
}
112125
}

0 commit comments

Comments
 (0)