Skip to content

Commit

Permalink
fix(dataview): add barrage to prevent crash if no dataview found
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara-Li committed Dec 29, 2023
1 parent bfd7360 commit 5328c58
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/conversion/compiler/dataview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export async function convertDataviewQueries(
): Promise<string> {
let replacedText = text;
const dataViewRegex = /```dataview\s(.+?)```/gsm;
if (!isPluginEnabled(app)) return replacedText;
//@ts-ignore
const isDataviewEnabled = app.plugins.plugins.dataview;
if (!isDataviewEnabled || !isPluginEnabled(app)) return replacedText;
const dvApi = getAPI();
if (!dvApi) return replacedText;
const matches = text.matchAll(dataViewRegex);
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
"settings": {
"conversion": {
"dataview": {
"desc": "Convert dataview to markdown.",
"desc": "Convert dataview to markdown. Only works if Dataview is enabled.",
"title": "Dataview"
},
"desc": "Theses option won't change the content of the file in your Obsidian Vault, but will change the content of the file in GitHub.",
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
"settings": {
"conversion": {
"dataview": {
"desc": "Convertir les requêtes Dataview en markdown.",
"desc": "Convertir les requêtes Dataview en markdown. Ne fonctionne que si Dataview est activé.",
"title": "Dataview"
},
"desc": "Ces options ne changent pas le contenu du fichier dans votre coffre Obsidian, mais changeront le contenu du fichier publié sur GitHub.",
Expand Down
7 changes: 6 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,18 +737,23 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
await this.plugin.saveSettings();
});
});
//@ts-ignore
const isDataviewEnabled = this.app.plugins.plugins.dataview;
new Setting(this.settingsPage)
.setName(i18next.t("settings.conversion.dataview.title"))
.setDesc(i18next.t("settings.conversion.dataview.desc"))
.addToggle((toggle) => {
toggle
.setValue(textSettings.dataview)
.setValue(textSettings.dataview && isDataviewEnabled)
.setDisabled(!isDataviewEnabled)
.onChange(async (value) => {
textSettings.dataview = value;
await this.plugin.saveSettings();
});
});



new Setting(this.settingsPage)
.setName(i18next.t("settings.regexReplacing.modal.title.text"))
.setDesc(i18next.t("settings.regexReplacing.modal.desc"))
Expand Down

0 comments on commit 5328c58

Please sign in to comment.