Skip to content

Commit

Permalink
0.2.2
Browse files Browse the repository at this point in the history
- Removes Notice from error catch and instead renders error message inside code block element
- Added Object.fromEntries es-shim
- Updated Obsidian type definitions
  • Loading branch information
valentine195 committed Mar 29, 2021
1 parent b948857 commit 0fbaffc
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 49 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
50 changes: 26 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
34 changes: 31 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -136,17 +144,37 @@ export default class ObsidianAdmonition extends Plugin {
MarkdownRenderer.renderMarkdown(
content,
admonitionContent,
//@ts-expect-error
ctx.sourcePath,
markdownRenderChild
);

/**
* Replace the <pre> 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(
Expand Down
34 changes: 14 additions & 20 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"]
}
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"0.2.0": "0.11.0"
"0.2.2": "0.11.0"
}

0 comments on commit 0fbaffc

Please sign in to comment.