Skip to content

Commit

Permalink
0.0.7
Browse files Browse the repository at this point in the history
- Moved `innerText` call to last possible moment
  • Loading branch information
valentine195 committed Aug 5, 2021
1 parent a96d290 commit 495eb4f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "markdown-attributes",
"name": "Markdown Attributes",
"version": "0.0.6",
"version": "0.0.7",
"minAppVersion": "0.12.10",
"description": "Add markdown attributes to elements in 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": "markdown-attributes",
"version": "0.0.6",
"version": "0.0.7",
"description": "Add markdown attributes to elements in Obsidian.md",
"main": "main.js",
"scripts": {
Expand Down
27 changes: 13 additions & 14 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ export default class MarkdownAttributes extends Plugin {
topElement: HTMLElement,
ctx: MarkdownPostProcessorContext
) {
let str = topElement.innerText;
const child = topElement.firstElementChild;
if (!child) return;
let str: string;

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

/** Test if the element contains attributes. */
if (
!source ||
!source.length ||
!Processor.ONLY_RE.test(source.trim())
)
return;

/** Pull the matched string and add it to the child so the Processor catches it. */
let [attribute_string] = source.match(Processor.ONLY_RE) ?? [];
child.prepend(new Text(attribute_string));

str = topElement.innerText;
source &&
source.length &&
Processor.ONLY_RE.test(source.trim())
) {
/** Pull the matched string and add it to the child so the Processor catches it. */
let [attribute_string] = source.match(Processor.ONLY_RE) ?? [];
child.prepend(new Text(attribute_string));

str = topElement.innerText;
}
}

/**
Expand All @@ -85,7 +84,7 @@ export default class MarkdownAttributes extends Plugin {
}

/** Test if the element contains attributes. */
if (!Processor.BASE_RE.test(str)) return;
if (!Processor.BASE_RE.test(str ?? topElement.innerText)) return;

/** Parse the element using the Processor. */
if (!(child instanceof HTMLElement)) return;
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.6": "0.12.0"
"0.0.7": "0.12.0"
}

0 comments on commit 495eb4f

Please sign in to comment.