Skip to content

Commit

Permalink
0.0.4
Browse files Browse the repository at this point in the history
- Fixed issue where undefined code blocks were sneaking through
  • Loading branch information
valentine195 committed Mar 17, 2021
1 parent 8008717 commit 275096a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 28 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.0.3",
"version": "0.0.4",
"minAppVersion": "0.11.0",
"description": "Admonition block-styled content for Obsidian.md",
"author": "Jeremy Valentine",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-admonition",
"version": "0.0.3",
"version": "0.0.4",
"description": "Admonition block-styled content for Obsidian.md",
"main": "main.js",
"scripts": {
Expand Down
56 changes: 31 additions & 25 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,40 @@ export default class Admonition extends Plugin {
(k) => `language-${k}`
);

codeBlocks = Array.prototype.map.call(
codeBlocks,
(element: HTMLElement): HTMLElement => {
const classList = Array.prototype.filter.call(
element.classList,
(cls: string) => classMap.includes(cls)
);
if (classList.length) return element;
}
);
codeBlocks = Array.prototype.map
.call(
codeBlocks,
(element: HTMLElement): HTMLElement => {
if (element) {
const classList = Array.prototype.filter.call(
element.classList,
(cls: string) => classMap.includes(cls)
);
if (classList.length) return element;
}
}
)
.filter((b: HTMLElement) => b);
if (!codeBlocks.length) return;

codeBlocks.forEach((block) => {
let classType = Array.prototype.find.call(
block.classList,
(cls: string) => classMap.includes(cls)
);
if (!classType) return;
let type =
ADMONITION_MAP[classType.split("language-").pop().trim()];
if (!type) return;
const {
title = type[0].toUpperCase() + type.slice(1).toLowerCase(),
content = block.innerText
} = Object.fromEntries(
block.innerText.split("\n").map((l) => l.split(": "))
);
this.buildAdmonition(block.parentElement, type, title, content);
if (block) {
let classType = Array.prototype.find.call(
block.classList,
(cls: string) => classMap.includes(cls)
);
if (!classType) return;
let type =
ADMONITION_MAP[classType.split("language-").pop().trim()];
if (!type) return;
const {
title = type[0].toUpperCase() + type.slice(1).toLowerCase(),
content = block.innerText
} = Object.fromEntries(
block.innerText.split("\n").map((l) => l.split(": "))
);
this.buildAdmonition(block.parentElement, type, title, content);
}
});
}
buildAdmonition(
Expand Down
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"0.0.3": "0.11.0"
"0.0.4": "0.11.0"
}

0 comments on commit 275096a

Please sign in to comment.