From 0fbaffc7e7c08ff4e64d5971b98f335a1594a83e Mon Sep 17 00:00:00 2001 From: valentine195 <38669521+valentine195@users.noreply.github.com> Date: Mon, 29 Mar 2021 11:12:47 -0400 Subject: [PATCH] 0.2.2 - Removes Notice from error catch and instead renders error message inside code block element - Added Object.fromEntries es-shim - Updated Obsidian type definitions --- manifest.json | 2 +- package.json | 50 ++++++++++++++++++++++++++------------------------ src/main.ts | 34 +++++++++++++++++++++++++++++++--- tsconfig.json | 34 ++++++++++++++-------------------- versions.json | 2 +- 5 files changed, 73 insertions(+), 49 deletions(-) diff --git a/manifest.json b/manifest.json index 1e8a31e..f79900c 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-admonition", "name": "Admonition", - "version": "0.2.0", + "version": "0.2.2", "minAppVersion": "0.11.0", "description": "Admonition block-styled content for Obsidian.md", "author": "Jeremy Valentine", diff --git a/package.json b/package.json index ab31c8f..b9477a1 100644 --- a/package.json +++ b/package.json @@ -1,26 +1,28 @@ { - "name": "obsidian-admonition", - "version": "0.2.0", - "description": "Admonition block-styled content for Obsidian.md", - "main": "main.js", - "scripts": { - "dev": "rollup --config rollup.config-dev.js -w", - "build": "rollup --config rollup.config.js" - }, - "keywords": [], - "author": "Jeremy Valentine", - "license": "MIT", - "devDependencies": { - "@fortawesome/fontawesome-svg-core": "^1.2.32", - "@fortawesome/free-solid-svg-icons": "^5.15.1", - "@rollup/plugin-commonjs": "^15.1.0", - "@rollup/plugin-node-resolve": "^9.0.0", - "@rollup/plugin-typescript": "^6.0.0", - "@types/node": "^14.14.2", - "obsidian": "https://github.com/obsidianmd/obsidian-api/tarball/master", - "rollup": "^2.32.1", - "rollup-plugin-css-only": "^3.1.0", - "tslib": "^2.0.3", - "typescript": "^4.0.3" - } + "name": "obsidian-admonition", + "version": "0.2.2", + "description": "Admonition block-styled content for Obsidian.md", + "main": "main.js", + "scripts": { + "dev": "rollup --config rollup.config-dev.js -w", + "build": "rollup --config rollup.config.js" + }, + "keywords": [], + "author": "Jeremy Valentine", + "license": "MIT", + "devDependencies": { + "@fortawesome/fontawesome-svg-core": "^1.2.32", + "@fortawesome/free-solid-svg-icons": "^5.15.1", + "@rollup/plugin-commonjs": "^15.1.0", + "@rollup/plugin-node-resolve": "^9.0.0", + "@rollup/plugin-typescript": "^6.0.0", + "@types/node": "^14.14.2", + "@types/object.fromentries": "^2.0.0", + "object.fromentries": "^2.0.4", + "obsidian": "https://github.com/obsidianmd/obsidian-api/tarball/master", + "rollup": "^2.32.1", + "rollup-plugin-css-only": "^3.1.0", + "tslib": "^2.0.3", + "typescript": "^4.0.3" + } } diff --git a/src/main.ts b/src/main.ts index 55bc0c0..e17e284 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,6 +6,14 @@ import { Plugin } from "obsidian"; +import fromEntries from "object.fromentries"; +if (!Object.fromEntries) { + //incorrect @types definition + //I tested that this correctly shims without error + //@ts-expect-error + fromEntries.shim(); +} + import "./main.css"; const ADMONITION_MAP: { @@ -136,7 +144,6 @@ export default class ObsidianAdmonition extends Plugin { MarkdownRenderer.renderMarkdown( content, admonitionContent, - //@ts-expect-error ctx.sourcePath, markdownRenderChild ); @@ -144,9 +151,30 @@ export default class ObsidianAdmonition extends Plugin { /** * Replace the
tag with the new admonition. */ - el.parentElement.replaceChild(admonitionElement, el); + el.replaceWith(admonitionElement); } catch (e) { - new Notice("There was an error rendering the admonition element."); + console.error(e); + const pre = createEl("pre"); + const textError = getComputedStyle(document.body).getPropertyValue( + "--text-error" + ) + ? getComputedStyle(document.body).getPropertyValue( + "--text-error" + ) + : "#ff3333"; + + pre.createEl("code", { + attr: { + style: `color: ${textError.trim()} !important` + } + }).createSpan({ + text: + "There was an error rendering the admonition:" + + "\n\n" + + src + }); + + el.replaceWith(pre); } } getAdmonitionElement( diff --git a/tsconfig.json b/tsconfig.json index 2557965..302dc10 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,22 +1,16 @@ { - "compilerOptions": { - "baseUrl": ".", - "inlineSourceMap": true, - "inlineSources": true, - "module": "ESNext", - "target": "es6", - "allowJs": true, - "noImplicitAny": true, - "moduleResolution": "node", - "importHelpers": true, - "lib": [ - "dom", - "es5", - "scripthost", - "es2019" - ] - }, - "include": [ - "**/*.ts" - ], + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "baseUrl": ".", + "inlineSourceMap": true, + "inlineSources": true, + "module": "ESNext", + "target": "es6", + "allowJs": true, + "noImplicitAny": true, + "moduleResolution": "node", + "importHelpers": true, + "lib": ["dom", "es5", "scripthost", "es2019"] + }, + "include": ["**/*.ts"] } diff --git a/versions.json b/versions.json index 0bd0014..7084156 100644 --- a/versions.json +++ b/versions.json @@ -1,3 +1,3 @@ { - "0.2.0": "0.11.0" + "0.2.2": "0.11.0" }