Skip to content

Commit 495eb4f

Browse files
committed
0.0.7
- Moved `innerText` call to last possible moment
1 parent a96d290 commit 495eb4f

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "markdown-attributes",
33
"name": "Markdown Attributes",
4-
"version": "0.0.6",
4+
"version": "0.0.7",
55
"minAppVersion": "0.12.10",
66
"description": "Add markdown attributes to elements in Obsidian.md",
77
"author": "Jeremy Valentine",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "markdown-attributes",
3-
"version": "0.0.6",
3+
"version": "0.0.7",
44
"description": "Add markdown attributes to elements in Obsidian.md",
55
"main": "main.js",
66
"scripts": {

src/main.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ export default class MarkdownAttributes extends Plugin {
1414
topElement: HTMLElement,
1515
ctx: MarkdownPostProcessorContext
1616
) {
17-
let str = topElement.innerText;
1817
const child = topElement.firstElementChild;
1918
if (!child) return;
19+
let str: string;
2020

2121
/** Code blocks have to be handled separately because Obsidian does not
2222
* include any text past the language.
2323
*
2424
* Unfortunately this also means that changes to the code block attributes
25-
* require reloading the note to take effect.
25+
* require reloading the note to take effect because they do not trigger the postprocessor.
2626
*/
2727
if (child instanceof HTMLPreElement) {
2828
/** If getSectionInfo returns null, stop processing. */
@@ -60,17 +60,16 @@ export default class MarkdownAttributes extends Plugin {
6060

6161
/** Test if the element contains attributes. */
6262
if (
63-
!source ||
64-
!source.length ||
65-
!Processor.ONLY_RE.test(source.trim())
66-
)
67-
return;
68-
69-
/** Pull the matched string and add it to the child so the Processor catches it. */
70-
let [attribute_string] = source.match(Processor.ONLY_RE) ?? [];
71-
child.prepend(new Text(attribute_string));
72-
73-
str = topElement.innerText;
63+
source &&
64+
source.length &&
65+
Processor.ONLY_RE.test(source.trim())
66+
) {
67+
/** Pull the matched string and add it to the child so the Processor catches it. */
68+
let [attribute_string] = source.match(Processor.ONLY_RE) ?? [];
69+
child.prepend(new Text(attribute_string));
70+
71+
str = topElement.innerText;
72+
}
7473
}
7574

7675
/**
@@ -85,7 +84,7 @@ export default class MarkdownAttributes extends Plugin {
8584
}
8685

8786
/** Test if the element contains attributes. */
88-
if (!Processor.BASE_RE.test(str)) return;
87+
if (!Processor.BASE_RE.test(str ?? topElement.innerText)) return;
8988

9089
/** Parse the element using the Processor. */
9190
if (!(child instanceof HTMLElement)) return;

versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"0.0.6": "0.12.0"
2+
"0.0.7": "0.12.0"
33
}

0 commit comments

Comments
 (0)