Skip to content

Commit

Permalink
1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasper-1024 committed Jul 14, 2024
1 parent f99a125 commit 08b719b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
22 changes: 21 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => ({
Expand Down
25 changes: 24 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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) => ({
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 08b719b

Please sign in to comment.