From 41ba01f3de4d659087b89ed769a0aad2e69e952c Mon Sep 17 00:00:00 2001 From: Samir Boulema Date: Mon, 22 Jun 2026 11:00:51 +0200 Subject: [PATCH] feat: Add per deck settings --- .github/workflows/workflow.yml | 2 +- .gitignore | 7 ------ .vscode/tasks.json | 16 +++++++++++++ README.md | 25 +++++++++++++++++++ main.ts | 26 ++++++++++++++------ manifest.json | 2 +- package.json | 2 +- src/code-block-options.ts | 44 ++++++++++++++++++++++++++++++++++ versions.json | 3 ++- 9 files changed, 109 insertions(+), 18 deletions(-) create mode 100644 .vscode/tasks.json create mode 100644 src/code-block-options.ts diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index f6d4abb..28740b0 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -10,7 +10,7 @@ permissions: contents: read env: - version: '1.12.${{ github.run_number }}' + version: '1.13.${{ github.run_number }}' nodeVersion: '22' jobs: diff --git a/.gitignore b/.gitignore index f386483..31b4834 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,3 @@ -# vscode -.vscode - -# Intellij -*.iml -.idea - # npm node_modules diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..187df0f --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,16 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "npm", + "script": "build", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [], + "label": "npm: build", + "detail": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production" + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md index 2053511..2d35cbc 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,31 @@ Open **Settings → MTG Deck** to configure the plugin: | **Card name column name** | The name of the CSV column used for card names | | **Card count column name** | The name of the CSV column used for card counts/quantity | +## Settings per deck + +````markdown +```mtg-deck-show:prices +... +``` +```` + +````markdown +```mtg-deck-modern-show:prices,manacosts +... +``` +```` + +Supported show values: + +| Value | Description | +|---|---| +| `prices` | Show card prices | +| `manacosts` | Show mana cost symbols | +| `previews` | Show card preview on hover | +| `hyperlinks` | Show card names as hyperlinks | +| `rarities` | Show rarity indicators | +| `buylist` | Show buylist section | + # 📦 Collection Tracking This plugin expects your collection to be stored as CSV files with the extension `.mtg.collection.csv` by default. diff --git a/main.ts b/main.ts index 3313426..8c68dd4 100644 --- a/main.ts +++ b/main.ts @@ -8,7 +8,7 @@ import { import { renderDecklist } from "src/renderer"; import { ObsidianPluginMtgSettings } from "src/settings"; import { CardCounts } from "src/collection"; -import { FORMATS } from "src/validator"; +import { parseCodeBlockOptions, applyShowOverrides } from "src/code-block-options"; const DEFAULT_SETTINGS: ObsidianPluginMtgSettings = { collection: { @@ -56,13 +56,25 @@ export default class ObsidianPluginMtg extends Plugin { this.cardCounts = await syncCounts(vault, this.settings); }); - this.registerMarkdownCodeBlockProcessor("mtg-deck", async (source: string, el: HTMLElement) => { - await this.renderDecklist(vault, source, el, null); - }); + this.registerMarkdownPostProcessor((element) => { + const codeBlocks = element.querySelectorAll("code[class*='language-mtg-deck']"); - FORMATS.forEach(({ name }) => { - this.registerMarkdownCodeBlockProcessor(`mtg-deck-${name}`, async (source: string, el: HTMLElement) => { - await this.renderDecklist(vault, source, el, name); + codeBlocks.forEach(async (codeBlock) => { + const className = Array.from(codeBlock.classList) + .find(cls => cls.startsWith("language-mtg-deck")) ?? ""; + + const infoString = className.replace("language-", ""); + const { format, showOverrides } = parseCodeBlockOptions(infoString); + const effectiveSettings = applyShowOverrides(this.settings, showOverrides); + + const source = codeBlock.textContent ?? ""; + const pre = codeBlock.parentElement; + + if (pre) { + const container = createDiv(); + pre.replaceWith(container); + await renderDecklist(container, source, this.cardCounts, effectiveSettings, format); + } }); }); } diff --git a/manifest.json b/manifest.json index c8c5a49..f23070f 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "mtg-deck", "name": "MTG Deck", - "version": "1.12.88", + "version": "1.13.104", "minAppVersion": "1.1.0", "description": "Display your MTG decks and card lists in your notes.", "author": "Samir Boulema", diff --git a/package.json b/package.json index b58c38f..2a1343b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mtg-deck", - "version": "1.12.88", + "version": "1.13.104", "description": "Display your MTG decks and card lists in your notes.", "main": "main.js", "scripts": { diff --git a/src/code-block-options.ts b/src/code-block-options.ts new file mode 100644 index 0000000..54358f3 --- /dev/null +++ b/src/code-block-options.ts @@ -0,0 +1,44 @@ +import { ObsidianPluginMtgSettings } from "./settings"; + +export interface CodeBlockOptions { + format: string | null; + showOverrides: string[]; +} + +export const parseCodeBlockOptions = (infoString: string): CodeBlockOptions => { + const stripped = infoString + .replace(/^mtg-deck-?/, "") + .trim(); + + const showMatch = stripped.match(/show:([^\s]+)/); + const showOverrides = showMatch + ? showMatch[1].split(",").map(s => s.trim()) + : []; + + const format = stripped + .replace(/show:[^\s]+/, "") + .replace(/-$/, "") + .trim() || null; + + return { format, showOverrides }; +}; + +export const applyShowOverrides = ( + settings: ObsidianPluginMtgSettings, + showOverrides: string[] +): ObsidianPluginMtgSettings => { + if (showOverrides.length === 0) return settings; + + return { + ...settings, + decklist: { + ...settings.decklist, + showCardPrices: showOverrides.includes("prices") || settings.decklist.showCardPrices, + showManaCosts: showOverrides.includes("manacosts") || settings.decklist.showManaCosts, + showCardPreviews: showOverrides.includes("previews") || settings.decklist.showCardPreviews, + showCardNamesAsHyperlinks: showOverrides.includes("hyperlinks") || settings.decklist.showCardNamesAsHyperlinks, + showCardRarities: showOverrides.includes("rarities") || settings.decklist.showCardRarities, + showBuylist: showOverrides.includes("buylist") || settings.decklist.showBuylist, + }, + }; +}; \ No newline at end of file diff --git a/versions.json b/versions.json index 4b98afe..d08bda6 100644 --- a/versions.json +++ b/versions.json @@ -25,5 +25,6 @@ "1.11.78": "0.15.0", "1.11.79": "0.15.0", "1.11.80": "0.15.0", - "1.12.88": "1.1.0" + "1.12.88": "1.1.0", + "1.13.104": "1.1.0" } \ No newline at end of file