diff --git a/manifest.json b/manifest.json index 67fbdc6..753e421 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-excalidraw-plugin", "name": "Excalidraw", - "version": "1.7.20", + "version": "1.7.21", "minAppVersion": "0.15.6", "description": "An Obsidian plugin to edit and view Excalidraw drawings", "author": "Zsolt Viczian", diff --git a/src/EmbeddedFileLoader.ts b/src/EmbeddedFileLoader.ts index 6de6f44..4999725 100644 --- a/src/EmbeddedFileLoader.ts +++ b/src/EmbeddedFileLoader.ts @@ -422,7 +422,7 @@ export class EmbeddedFilesLoader { let fontName = plugin.settings.mdFont; if ( fileCache?.frontmatter && - fileCache.frontmatter[FRONTMATTER_KEY_FONT] != null + Boolean(fileCache.frontmatter[FRONTMATTER_KEY_FONT]) ) { fontName = fileCache.frontmatter[FRONTMATTER_KEY_FONT]; } @@ -442,6 +442,13 @@ export class EmbeddedFilesLoader { fontName = font.fontName; } + if ( + fileCache?.frontmatter && + fileCache.frontmatter["banner"] !== null + ) { + text = text.replace(/banner:\s*.*/,""); //patch https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/814 + } + const fontColor = fileCache?.frontmatter ? fileCache.frontmatter[FRONTMATTER_KEY_FONTCOLOR] ?? plugin.settings.mdFontColor diff --git a/src/ExcalidrawData.ts b/src/ExcalidrawData.ts index ed951cf..95fa84d 100644 --- a/src/ExcalidrawData.ts +++ b/src/ExcalidrawData.ts @@ -854,6 +854,7 @@ export class ExcalidrawData { let linkIcon = false; let urlIcon = false; let parts; + text = this.parseCheckbox(text); if (text.match(REG_LINKINDEX_HYPERLINK)) { link = text; urlIcon = true; @@ -869,8 +870,8 @@ export class ExcalidrawData { } if (REGEX_LINK.isTransclusion(parts)) { //transclusion //parts.value[1] || parts.value[4] - const contents = (await this.getTransclusion(REGEX_LINK.getLink(parts))) - .contents; + const contents = this.parseCheckbox((await this.getTransclusion(REGEX_LINK.getLink(parts))) + .contents); outString += text.substring(position, parts.value.index) + wrapText( @@ -907,6 +908,16 @@ export class ExcalidrawData { return { parsed: outString, link }; } + private parseCheckbox(text:string):string { + return this.plugin.settings.parseTODO + ? text + .replaceAll(/^- \[\s] /g,`${this.plugin.settings.todo} `) + .replaceAll(/\n- \[\s] /g,`\n${this.plugin.settings.todo} `) + .replaceAll(/^- \[[^\s]] /g,`${this.plugin.settings.done} `) + .replaceAll(/\n- \[[^\s]] /g,`\n${this.plugin.settings.done} `) + : text; + } + /** * Does a quick parse of the raw text. Returns the parsed string if raw text does not include a transclusion. * Return null if raw text includes a transclusion. @@ -936,6 +947,7 @@ export class ExcalidrawData { let linkIcon = false; let urlIcon = false; let parts; + text = this.parseCheckbox(text); if (text.match(REG_LINKINDEX_HYPERLINK)) { link = text; urlIcon = true; @@ -1065,7 +1077,7 @@ export class ExcalidrawData { const equation = this.getEquation(fileId); //const equation = this.equations.get(fileId as FileId); //images should have a single reference, but equations and markdown embeds should have as many as instances of the file in the scene - if(file && (file.file.extension !== "md" || this.plugin.isExcalidrawFile(file.file))) { + if(file && file.file && (file.file.extension !== "md" || this.plugin.isExcalidrawFile(file.file))) { return; } const newId = fileid(); diff --git a/src/ExcalidrawView.ts b/src/ExcalidrawView.ts index 07e35cf..5ecd289 100644 --- a/src/ExcalidrawView.ts +++ b/src/ExcalidrawView.ts @@ -457,6 +457,12 @@ export default class ExcalidrawView extends TextFileView { return; } this.semaphores.saving = true; + + //if there were no changes to the file super save will not save + //and consequently main.ts modifyEventHandler will not fire + //this.reload will not be called + //triggerReload is used to flag if there were no changes but file should be reloaded anyway + let triggerReload:boolean = false; if ( !this.getScene || @@ -500,6 +506,8 @@ export default class ExcalidrawView extends TextFileView { this.semaphores.preventReload = preventReload; await super.save(); + triggerReload = (this.lastSaveTimestamp === this.file.stat.mtime) && + !preventReload && forcesave; this.lastSaveTimestamp = this.file.stat.mtime; this.clearDirty(); @@ -512,7 +520,8 @@ export default class ExcalidrawView extends TextFileView { } } - if (!this.semaphores.autosaving && !this.semaphores.viewunload) { + // !triggerReload means file has not changed. No need to re-export + if (!triggerReload && !this.semaphores.autosaving && !this.semaphores.viewunload) { const autoexportPreference = this.excalidrawData.autoexportPreference; if ( (autoexportPreference === AutoexportPreference.inherit && this.plugin.settings.autoexportSVG) || @@ -542,6 +551,9 @@ export default class ExcalidrawView extends TextFileView { warningUnknowSeriousError(); } this.semaphores.saving = false; + if(triggerReload) { + this.reload(true, this.file); + } } // get the new file content @@ -1003,9 +1015,15 @@ export default class ExcalidrawView extends TextFileView { DISK_ICON_NAME, t("FORCE_SAVE"), async () => { - if (this.semaphores.autosaving) { + if (this.semaphores.autosaving || this.semaphores.saving) { + new Notice("Force Save aborted because saving is in progress)") return; } + if(this.preventReloadResetTimer) { + clearTimeout(this.preventReloadResetTimer); + this.preventReloadResetTimer = null; + } + this.semaphores.preventReload = false; this.semaphores.forceSaving = true; await this.save(false, true); this.plugin.triggerEmbedUpdates(); diff --git a/src/dialogs/Messages.ts b/src/dialogs/Messages.ts index 273b3e1..77daf79 100644 --- a/src/dialogs/Messages.ts +++ b/src/dialogs/Messages.ts @@ -16,6 +16,31 @@ export const RELEASE_NOTES: { [k: string]: string } = { I develop this plugin as a hobby, spending most of my free time doing this. If you'd like to contribute to the on-going work, I have a simple membership scheme with Bronze, Silver and Gold tiers. Many of you have already bought me a coffee. THANK YOU! It really means a lot to me! If you find this plugin valuable, please consider supporting me.
+`, +"1.7.21":` +# New from Excalidraw.com +- Image-mirroring in export preview and in exported SVG [#5700](https://github.com/excalidraw/excalidraw/pull/5700), [#811](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/811), [#617](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/617) + +# New +- Ctrl+s will force-save your drawing and update all your transclusions +- Added setting to parse ${String.fromCharCode(96)}- [ ] ${String.fromCharCode(96)} and ${String.fromCharCode(96)}- [x] ${String.fromCharCode(96)} todo items. Parsing is disabled by default. This feature can be found under "Links and Transclusions" in Plugin Settings. [#819](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/819) + + + + + + +- Added new scripts to the script library + - [Rename Image](https://github.com/zsviczian/obsidian-excalidraw-plugin/blob/master/ea-scripts/Rename%20Image.md) + - [Text Arch](https://github.com/zsviczian/obsidian-excalidraw-plugin/blob/master/ea-scripts/Text%20Arch.md) + + + + +# Fixed +- Fixed toast message to display script name on press and hold on mobile and iPad. +- Fixed save error when the embedded image file is not found (i.e. it was moved, renamed, or deleted) + `, "1.7.20":` # New from Excalidraw.com diff --git a/src/lang/locale/en.ts b/src/lang/locale/en.ts index b49fe15..584ff6f 100644 --- a/src/lang/locale/en.ts +++ b/src/lang/locale/en.ts @@ -77,7 +77,7 @@ export default { FILE_DOES_NOT_EXIST: "File does not exist. Hold down ALT (or ALT+SHIFT) and CLICK link button to create a new file.", FORCE_SAVE: - "Force-save to update transclusions in adjacent panes.\n(Check autosave settings in plugin settings.)", + "Save (will also update transclusions)", RAW: "Change to PREVIEW mode (only effects text-elements with links or transclusions)", PARSED: "Change to RAW mode (only effects text-elements with links or transclusions)", @@ -226,6 +226,12 @@ export default { "In PREVIEW mode, if the Text Element contains a URL link, precede the text with these characters. " + "You can override this setting for a specific drawing by adding"
}${FRONTMATTER_KEY_CUSTOM_URL_PREFIX}: "🌐 " to the file's frontmatter.`,
+ PARSE_TODO_NAME: "Parse todo",
+ PARSE_TODO_DESC: "Convert '- [ ] ' and '- [x] ' to checkpox and tick in the box.",
+ TODO_NAME: "Open TODO icon",
+ TODO_DESC: "Icon to use for open TODO items",
+ DONE_NAME: "Completed TODO icon",
+ DONE_DESC: "Icon to use for completed TODO items",
HOVERPREVIEW_NAME: "Hover preview without CTRL/CMD key",
HOVERPREVIEW_DESC:
"Toggle On: In Exalidraw view mode the hover preview for [[wiki links]] will be shown immediately, without the need to hold the CTRL/CMD key. " +
diff --git a/src/main.ts b/src/main.ts
index 4c727f0..c7bd011 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -15,7 +15,8 @@ import {
loadMathJax,
request,
MetadataCache,
- FrontMatterCache
+ FrontMatterCache,
+ Command
} from "obsidian";
import {
BLANK_DRAWING,
@@ -163,6 +164,7 @@ export default class ExcalidrawPlugin extends Plugin {
public fourthFontDef: string = VIRGIL_FONT;
private packageMap: WeakMap