diff --git a/main.js b/main.js index 12beebd6..582a71ff 100644 --- a/main.js +++ b/main.js @@ -273,10 +273,30 @@ function markdownPostProcessor(el) { } } } +function ensureStyleOnce(id, css) { + if (!document.getElementById(id)) { + const style = document.createElement("style"); + style.id = id; + style.type = "text/css"; + style.innerText = css; + document.head.appendChild(style); + } +} function createViewPlugin(rule = "(^| )\u02C5[a-zA-Z0-9_]+$") { + ensureStyleOnce( + "unique-style-id", + ` + .small_id { + font-size: 1.5rem; + opacity: 0.8; + vertical-align: top; + font-weight: normal; + } + ` + ); let decorator = new import_view.MatchDecorator({ regexp: new RegExp(rule, "g"), - decoration: import_view.Decoration.mark({ class: "small-font" }) + decoration: import_view.Decoration.mark({ class: "small_id" }) }); return import_view.ViewPlugin.define( (view) => ({ diff --git a/main.ts b/main.ts index c9db46f7..0db4fd15 100644 --- a/main.ts +++ b/main.ts @@ -436,6 +436,16 @@ function markdownPostProcessor(el: HTMLElement) { } } +function ensureStyleOnce(id: string, css: string) { + if (!document.getElementById(id)) { + const style = document.createElement('style'); + style.id = id; + style.type = 'text/css'; + style.innerText = css; + document.head.appendChild(style); + } +} + /** * Creates a BlockLinkPlusViewPlugin with the specified rule. * @@ -445,9 +455,22 @@ function markdownPostProcessor(el: HTMLElement) { function createViewPlugin( rule: string = "(^| )˅[a-zA-Z0-9_]+$" ): BlockLinkPlusViewPlugin { + + ensureStyleOnce( + "unique-style-id", + ` + .small_id { + font-size: 1.5rem; + opacity: 0.8; + vertical-align: top; + font-weight: normal; + } + ` + ); + let decorator = new MatchDecorator({ regexp: new RegExp(rule, "g"), - decoration: Decoration.mark({ class: "small-font" }), + decoration: Decoration.mark({ class: "small_id" }), }); return ViewPlugin.define( (view) => ({ diff --git a/manifest.json b/manifest.json index f05f068b..99dec6a9 100644 --- a/manifest.json +++ b/manifest.json @@ -1,8 +1,8 @@ { "id": "obsidian-block-link-plus", "name": "Block Link Plus", - "version": "1.0.1", - "minAppVersion": "0.21.0", + "version": "1.0.2", + "minAppVersion": "0.22.0", "description": "This is a sample plugin for Obsidian. This plugin demonstrates some of the capabilities of the Obsidian API.", "author": "Jasper", "authorUrl": "obsidian-block-link-plus",