mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2025-08-06 05:46:28 +00:00
1.4.10
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "obsidian-excalidraw-plugin",
|
||||
"name": "Excalidraw",
|
||||
"version": "1.4.9",
|
||||
"version": "1.4.10",
|
||||
"minAppVersion": "0.12.16",
|
||||
"description": "An Obsidian plugin to edit and view Excalidraw drawings",
|
||||
"author": "Zsolt Viczian",
|
||||
|
||||
@@ -197,17 +197,13 @@ export default class ExcalidrawView extends TextFileView {
|
||||
let header = this.data.substring(0,trimLocation)
|
||||
.replace(/excalidraw-plugin:\s.*\n/,FRONTMATTER_KEY+": " + ( (this.textMode == TextMode.raw) ? "raw\n" : "parsed\n"));
|
||||
|
||||
if (header.search(/cssclass:[\s]*excalidraw-hide-preview-text/) === -1) {
|
||||
header = header.replace(/(excalidraw-plugin:\s.*\n)/,"$1cssclass: excalidraw-hide-preview-text\n");
|
||||
}
|
||||
|
||||
|
||||
//this should be removed at a later time. Left it here to remediate 1.4.9 mistake
|
||||
const REG_IMG = /(^---[\w\W]*?---\n)(!\[\[.*?]]\n(%%\n)?)/m; //(%%\n)? because of 1.4.8-beta... to be backward compatible with anyone who installed that version
|
||||
if(header.match(REG_IMG)) {
|
||||
header = header.replace(REG_IMG,"$1![["+this.file.path+"]]\n");
|
||||
} else {
|
||||
header = header.replace(/(^---[\w\W]*?---\n)/m, "$1![["+this.file.path+"]]\n");
|
||||
}
|
||||
header = header.replace(REG_IMG,"$1");
|
||||
}
|
||||
//end of remove
|
||||
|
||||
return header + this.excalidrawData.generateMD();
|
||||
}
|
||||
if(this.compatibilityMode) {
|
||||
|
||||
@@ -79,13 +79,13 @@ export class OneOffs {
|
||||
|
||||
if(this.plugin.settings.patchCommentBlock) return; //the comment block patch needs to happen first (unlikely that someone has waited this long with the update...)
|
||||
//This is a once off process to patch excalidraw files remediate incorrectly placed comment %% before # Text Elements
|
||||
if(!this.plugin.settings.runWYSIWYGpatch) return;
|
||||
if(!(this.plugin.settings.runWYSIWYGpatch||this.plugin.settings.fixInfinitePreviewLoop)) return;
|
||||
const plugin = this.plugin;
|
||||
|
||||
console.log(window.moment().format("HH:mm:ss") + ": Excalidraw will patch drawings to support WYSIWYG in 7 minutes");
|
||||
setTimeout(async ()=>{
|
||||
await plugin.loadSettings();
|
||||
if (!plugin.settings.runWYSIWYGpatch) {
|
||||
if (!(this.plugin.settings.runWYSIWYGpatch||this.plugin.settings.fixInfinitePreviewLoop)) {
|
||||
console.log(window.moment().format("HH:mm:ss") + ": Excalidraw patching aborted because synched data.json is already patched");
|
||||
return;
|
||||
}
|
||||
@@ -108,16 +108,12 @@ export class OneOffs {
|
||||
let header = data.substring(0,trimLocation)
|
||||
.replace(/excalidraw-plugin:\s.*\n/,FRONTMATTER_KEY+": " + ( (textMode == TextMode.raw) ? "raw\n" : "parsed\n"));
|
||||
|
||||
if (header.search(/cssclass:[\s]*excalidraw-hide-preview-text/) === -1) {
|
||||
header = header.replace(/(excalidraw-plugin:\s.*\n)/,"$1cssclass: excalidraw-hide-preview-text\n");
|
||||
}
|
||||
header = header.replace(/cssclass:[\s]*excalidraw-hide-preview-text[\s]*\n/,"");
|
||||
|
||||
const REG_IMG = /(^---[\w\W]*?---\n)(!\[\[.*?]]\n(%%\n)?)/m; //(%%\n)? because of 1.4.8-beta... to be backward compatible with anyone who installed that version
|
||||
if(header.match(REG_IMG)) {
|
||||
header = header.replace(REG_IMG,"$1![["+f.path+"]]\n");
|
||||
} else {
|
||||
header = header.replace(/(^---[\w\W]*?---\n)/m, "$1![["+f.path+"]]\n");
|
||||
}
|
||||
header = header.replace(REG_IMG,"$1");
|
||||
}
|
||||
const newData = header + excalidrawData.generateMD();
|
||||
|
||||
if (data !== newData) {
|
||||
@@ -132,6 +128,7 @@ export class OneOffs {
|
||||
}
|
||||
}
|
||||
plugin.settings.runWYSIWYGpatch = false;
|
||||
plugin.settings.fixInfinitePreviewLoop = false;
|
||||
plugin.saveSettings();
|
||||
console.log(window.moment().format("HH:mm:ss") + ": Excalidraw patched in total " + i + " files");
|
||||
},420000) //7 minutes
|
||||
|
||||
77
src/main.ts
77
src/main.ts
@@ -259,6 +259,49 @@ export default class ExcalidrawPlugin extends Plugin {
|
||||
return img;
|
||||
}
|
||||
|
||||
const createImageDiv = async (attr:imgElementAttributes):Promise<HTMLDivElement> => {
|
||||
const img = await getIMG(attr);
|
||||
return createDiv(attr.style, (el)=>{
|
||||
el.append(img);
|
||||
el.setAttribute("src",attr.file.path);
|
||||
if(attr.fwidth) el.setAttribute("w",attr.fwidth);
|
||||
if(attr.fheight) el.setAttribute("h",attr.fheight);
|
||||
el.onClickEvent((ev)=>{
|
||||
if(ev.target instanceof Element && ev.target.tagName.toLowerCase() != "img") return;
|
||||
let src = el.getAttribute("src");
|
||||
if(src) this.openDrawing(this.app.vault.getAbstractFileByPath(src) as TFile,ev.ctrlKey||ev.metaKey);
|
||||
});
|
||||
el.addEventListener(RERENDER_EVENT, async(e) => {
|
||||
e.stopPropagation;
|
||||
el.empty();
|
||||
const img = await getIMG({
|
||||
fname:el.getAttribute("src"),
|
||||
fwidth:el.getAttribute("w"),
|
||||
fheight:el.getAttribute("h"),
|
||||
style:el.getAttribute("class")
|
||||
});
|
||||
el.append(img);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const tmpObsidianWYSIWYG = async (el:HTMLElement,ctx:MarkdownPostProcessorContext) => {
|
||||
if(!ctx.frontmatter) return;
|
||||
if(!ctx.frontmatter.hasOwnProperty("excalidraw-plugin")) return;
|
||||
//@ts-ignore
|
||||
if(ctx.remainingNestLevel<4) return;
|
||||
if(!el.querySelector(".frontmatter")) {
|
||||
el.style.display="none";
|
||||
return;
|
||||
}
|
||||
const attr:imgElementAttributes={fname:ctx.sourcePath,fheight:"",fwidth:this.settings.width,style:"excalidraw-svg"};
|
||||
|
||||
attr.file = this.app.metadataCache.getFirstLinkpathDest(ctx.sourcePath,"");
|
||||
const div = await createImageDiv(attr);
|
||||
el.childNodes.forEach((child:HTMLElement)=>child.style.display="none");
|
||||
el.appendChild(div)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param el
|
||||
@@ -266,13 +309,20 @@ export default class ExcalidrawPlugin extends Plugin {
|
||||
*/
|
||||
const markdownPostProcessor = async (el:HTMLElement,ctx:MarkdownPostProcessorContext) => {
|
||||
const embeddedItems = el.querySelectorAll('.internal-embed');
|
||||
if(embeddedItems.length==0) return;
|
||||
if(embeddedItems.length===0) {
|
||||
tmpObsidianWYSIWYG(el,ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
let attr:imgElementAttributes={fname:"",fheight:"",fwidth:"",style:""};
|
||||
let alt:string, parts, div, file:TFile;
|
||||
for (const drawing of embeddedItems) {
|
||||
attr.fname = drawing.getAttribute("src");
|
||||
file = this.app.metadataCache.getFirstLinkpathDest(attr.fname, ctx.sourcePath);
|
||||
if(!file && ctx.frontmatter?.hasOwnProperty("excalidraw-plugin")) {
|
||||
attr.fname = ctx.sourcePath;
|
||||
file = this.app.metadataCache.getFirstLinkpathDest(attr.fname, ctx.sourcePath);
|
||||
}
|
||||
if(file && file instanceof TFile && this.isExcalidrawFile(file)) {
|
||||
attr.fwidth = drawing.getAttribute("width") ? drawing.getAttribute("width") : this.settings.width;
|
||||
attr.fheight = drawing.getAttribute("height");
|
||||
@@ -292,29 +342,8 @@ export default class ExcalidrawPlugin extends Plugin {
|
||||
}
|
||||
|
||||
attr.fname = file?.path;
|
||||
const img = await getIMG(attr);
|
||||
div = createDiv(attr.style, (el)=>{
|
||||
el.append(img);
|
||||
el.setAttribute("src",file.path);
|
||||
if(attr.fwidth) el.setAttribute("w",attr.fwidth);
|
||||
if(attr.fheight) el.setAttribute("h",attr.fheight);
|
||||
el.onClickEvent((ev)=>{
|
||||
if(ev.target instanceof Element && ev.target.tagName.toLowerCase() != "img") return;
|
||||
let src = el.getAttribute("src");
|
||||
if(src) this.openDrawing(this.app.vault.getAbstractFileByPath(src) as TFile,ev.ctrlKey||ev.metaKey);
|
||||
});
|
||||
el.addEventListener(RERENDER_EVENT, async(e) => {
|
||||
e.stopPropagation;
|
||||
el.empty();
|
||||
const img = await getIMG({
|
||||
fname:el.getAttribute("src"),
|
||||
fwidth:el.getAttribute("w"),
|
||||
fheight:el.getAttribute("h"),
|
||||
style:el.getAttribute("class")
|
||||
});
|
||||
el.append(img);
|
||||
});
|
||||
});
|
||||
attr.file = file;
|
||||
const div = await createImageDiv(attr);
|
||||
drawing.parentElement.replaceChild(div,drawing);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ export interface ExcalidrawSettings {
|
||||
patchCommentBlock: boolean, //1.3.12
|
||||
imageElementNotice: boolean, //1.4.0
|
||||
runWYSIWYGpatch: boolean, //1.4.9
|
||||
fixInfinitePreviewLoop: boolean, //1.4.10
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: ExcalidrawSettings = {
|
||||
@@ -85,6 +86,7 @@ export const DEFAULT_SETTINGS: ExcalidrawSettings = {
|
||||
patchCommentBlock: true,
|
||||
imageElementNotice: true,
|
||||
runWYSIWYGpatch: true,
|
||||
fixInfinitePreviewLoop: true
|
||||
}
|
||||
|
||||
export class ExcalidrawSettingTab extends PluginSettingTab {
|
||||
|
||||
30
styles.css
30
styles.css
@@ -95,33 +95,3 @@ li[data-testid] {
|
||||
margin-bottom: 20px;
|
||||
|
||||
}
|
||||
|
||||
/*hide text elements in markdown preview*/
|
||||
.markdown-preview-view.excalidraw-hide-preview-text {
|
||||
font-size: 0px;
|
||||
}
|
||||
|
||||
.markdown-preview-view mark,
|
||||
.markdown-preview-view.excalidraw-hide-preview-text span:not(.image-embed),
|
||||
.markdown-preview-view.excalidraw-hide-preview-text ol,
|
||||
.markdown-preview-view.excalidraw-hide-preview-text li,
|
||||
.markdown-preview-view.excalidraw-hide-preview-text table,
|
||||
.markdown-preview-view.excalidraw-hide-preview-text pre,
|
||||
.markdown-preview-view.excalidraw-hide-preview-text hr,
|
||||
.markdown-preview-view.excalidraw-hide-preview-text a,
|
||||
.markdown-preview-view.excalidraw-hide-preview-text h1,
|
||||
.markdown-preview-view.excalidraw-hide-preview-text h2,
|
||||
.markdown-preview-view.excalidraw-hide-preview-text h3,
|
||||
.markdown-preview-view.excalidraw-hide-preview-text h4,
|
||||
.markdown-preview-view.excalidraw-hide-preview-text h5 {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.markdown-preview-view.excalidraw-hide-preview-text p:first-child {
|
||||
margin-top:0px !important;
|
||||
}
|
||||
|
||||
.markdown-preview-view.excalidraw-hide-preview-text div.markdown-preview-sizer.markdown-preview-section {
|
||||
padding-bottom:0px !important;
|
||||
min-height: 0px !important;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"1.4.9": "0.12.16",
|
||||
"1.4.10": "0.12.16",
|
||||
"1.4.2": "0.11.13"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user