Skip to content

Commit bd1121b

Browse files
committed
Fixed:
- Extension breaks other elemets in Preview Mode - Some elements in Preview Mode and Edit mode did not support tags
1 parent b8b11b7 commit bd1121b

File tree

7 files changed

+29
-45
lines changed

7 files changed

+29
-45
lines changed

.devcontainer/devcontainer.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@
33
{
44
"name": "Node.js & TypeScript",
55
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6-
"image": "mcr.microsoft.com/devcontainers/typescript-node:1-22-bookworm"
7-
6+
"image": "mcr.microsoft.com/devcontainers/typescript-node:1-22-bookworm",
7+
"mounts": [
8+
"source=${localEnv:HOME}${localEnv:USERPROFILE}/.ssh,target=/home/node/.ssh,type=bind,consistency=cached"
9+
]
810
// Features to add to the dev container. More info: https://containers.dev/features.
911
// "features": {},
10-
1112
// Use 'forwardPorts' to make a list of ports inside the container available locally.
1213
// "forwardPorts": [],
13-
1414
// Use 'postCreateCommand' to run commands after the container is created.
1515
// "postCreateCommand": "yarn install",
16-
1716
// Configure tool-specific properties.
1817
// "customizations": {},
19-
2018
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
2119
// "remoteUser": "root"
22-
}
20+
}

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
- none
1111

12+
## [1.2.2] - 2024-12-13
13+
14+
### Fixed
15+
16+
- Extension breaks other elemets in Preview Mode
17+
- Some elements in Preview Mode and Edit mode did not support tags
18+
19+
1220
## [1.2.1] - 2024-11-28
1321

1422
### Fixed

main.ts

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -96,35 +96,12 @@ export default class tagsPlugin extends Plugin {
9696
return false;
9797
};
9898

99-
// Function to check if a position is inside a callout block
100-
const isInCalloutBlock = (pos: number): boolean => {
101-
let inCalloutBlock = false;
102-
const doc = view.state.doc;
103-
104-
for (let i = 1; i <= doc.lines; i++) {
105-
const currentLine = doc.line(i).text.trim();
106-
107-
// Detect start of callout
108-
if (currentLine.match(/^>\s*\[![^\]]+]/)) {
109-
inCalloutBlock = true;
110-
}
111-
// Detect end of callout (blank line or end of document)
112-
if (inCalloutBlock && (currentLine === "" || i === doc.lines)) {
113-
inCalloutBlock = false;
114-
}
115-
if (pos >= doc.line(i).from && pos <= doc.line(i).to) {
116-
return inCalloutBlock;
117-
}
118-
}
119-
return false;
120-
};
121-
12299
while ((match = tagSyntaxRegex.exec(text)) !== null) {
123100
const start = from + (match.index ?? 0); // Start of the match
124101
const end = start + match[0].length; // End of the match
125102

126103
// Check if the cursor is within the match range or if the match is inside a code block
127-
if (cursorPos >= start && cursorPos <= end || (isInCodeBlock(start) || isInCalloutBlock(start))) {
104+
if (cursorPos >= start && cursorPos <= end || (isInCodeBlock(start))) {
128105
continue; // Skip adding decorations if the cursor is within the range or inside a code or callout block
129106
}
130107

@@ -156,19 +133,17 @@ export default class tagsPlugin extends Plugin {
156133
return (el: HTMLElement, ctx: MarkdownPostProcessorContext) => {
157134
const tags = Array.from(el.querySelectorAll("p, li, span, div"));
158135

159-
// skip if we are in a callout
160-
if (tags?.[0]?.classList?.contains("callout")) return;
161-
162136
tags.forEach(tagElement => {
163137
const originalText = tagElement.textContent; // Use textContent to get plain text
164138
if (!originalText) return; // Skip if there's no text
165139

166140
let match: RegExpExecArray | null;
167-
let updatedHTML = originalText; // Start with escaped text content
141+
let updatedHTML = tagElement.innerHTML; // Start with the existing HTML
142+
let matchFound = false; // Initialize the flag
168143

169144
// Process matches in the text content
170145
while ((match = tagSyntaxRegex.exec(originalText)) !== null) {
171-
146+
matchFound = true;
172147
// Extract named groups with default values
173148
const { label = "", bgcolor = "", fgcolor = "" } = match.groups ?? {};
174149
const escapedLabel = escapeHtml(label);
@@ -181,12 +156,14 @@ export default class tagsPlugin extends Plugin {
181156

182157
// Replace tag syntax with styled span
183158
const replacement = `<span class="${decoration.spec.class}" style="${decoration.spec.attributes.style}">${escapedLabel}</span>`;
184-
updatedHTML = updatedHTML.replace(match[0], replacement);
159+
const escapedMatch = escapeHtml(match[0]); // Escape the match to handle HTML entities
160+
updatedHTML = updatedHTML.replace(escapedMatch, replacement);
185161
}
186162

187-
// Update the element's innerHTML with the processed HTML
188-
tagElement.innerHTML = updatedHTML;
163+
if (matchFound) {
164+
tagElement.innerHTML = updatedHTML; // Process this line only if a match was found
165+
}
189166
});
190-
}
167+
};
191168
}
192169
}

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "markdown-tags",
33
"name": "Markdown Tags",
4-
"version": "1.2.1",
4+
"version": "1.2.2",
55
"minAppVersion": "0.12.0",
66
"description": "Enhance your documents with custom tags. Use predefined or custom labels, customizable colors, and arrow indicators to visually track tasks and statuses.",
77
"author": "John Smith III",

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obsidian-markdown-tags",
3-
"version": "1.2.1",
3+
"version": "1.2.2",
44
"description": "Enhance your documents with custom tags. Use predefined or custom labels, customizable colors, and arrow indicators to visually track tasks and statuses.",
55
"main": "main.js",
66
"repository": {

versions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"1.1.0": "0.12.0",
66
"1.1.1": "0.12.0",
77
"1.2.0": "0.12.0",
8-
"1.2.1": "0.12.0"
8+
"1.2.1": "0.12.0",
9+
"1.2.2": "0.12.0"
910
}

0 commit comments

Comments
 (0)