Skip to content

Commit 7e73b23

Browse files
committed
create node differently with reading mode or editing mode
1 parent 1d9b203 commit 7e73b23

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "obsidian-basetag",
33
"name": "Base Tag Renderer",
4-
"version": "1.1.4",
4+
"version": "1.1.5",
55
"minAppVersion": "0.15.0",
66
"description": "This plugin renders the basename of tags.",
77
"author": "Darren Kuro",

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obsidian-basetag",
3-
"version": "1.1.4",
3+
"version": "1.1.5",
44
"description": "This plugin renders the basename for tags.",
55
"main": "main.js",
66
"scripts": {

src/main.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const BASETAG = "basename-tag";
1818
const getVaultName = () => window.app.vault.getName();
1919

2020
/** Create a custom tag node from text content (can include #). */
21-
const createTagNode = (text: string | null) => {
21+
const createTagNode = (text: string | null, readingMode: boolean) => {
2222
const node = document.createElement("a");
2323
if (!text) return node;
2424

@@ -27,7 +27,7 @@ const createTagNode = (text: string | null) => {
2727
node.target = "_blank";
2828
node.rel = "noopener";
2929
// To comply with colorful-tag css seletor
30-
node.href = `#${text}`;
30+
node.href = readingMode ? `${text}` : `#${text}`;
3131

3232
const vaultStr = encodeURIComponent(getVaultName());
3333
const queryStr = `tag:${encodeURIComponent(text)}`;
@@ -43,12 +43,12 @@ const createTagNode = (text: string | null) => {
4343

4444
/** Create a tag node in the type of widget from text content. */
4545
class TagWidget extends WidgetType {
46-
constructor(private text: string) {
46+
constructor(private text: string, private readingMode: boolean) {
4747
super();
4848
}
4949

5050
toDOM(view: EditorView): HTMLElement {
51-
return createTagNode(this.text);
51+
return createTagNode(this.text, this.readingMode);
5252
}
5353
}
5454

@@ -97,7 +97,7 @@ class editorPlugin implements PluginValue {
9797
node.from - 1,
9898
node.to,
9999
Decoration.replace({
100-
widget: new TagWidget(text),
100+
widget: new TagWidget(text, false),
101101
}),
102102
);
103103
}
@@ -150,7 +150,7 @@ class editorPlugin implements PluginValue {
150150
currentIndex,
151151
currentIndex + tagsArray[i].length,
152152
Decoration.replace({
153-
widget: new TagWidget(tagsArray[i]),
153+
widget: new TagWidget(tagsArray[i], false),
154154
}),
155155
);
156156

@@ -182,7 +182,7 @@ export default class TagRenderer extends Plugin {
182182
node.removeAttribute("class");
183183
// Hide this node and append the custom tag node in its place.
184184
node.style.display = "none";
185-
node.parentNode?.insertBefore(createTagNode(node.textContent), node);
185+
node.parentNode?.insertBefore(createTagNode(node.textContent, true), node);
186186
},
187187
);
188188
});

0 commit comments

Comments
 (0)