From 2e6e3953c7c32ac6d458a1286d6328f2f700c013 Mon Sep 17 00:00:00 2001 From: Mathieu Marques Date: Sun, 12 May 2024 19:30:35 +0200 Subject: [PATCH] refactor(mana): deprecate remarkMana.client --- markdown/partials/sandbox.md | 12 ++++++++-- src/components/Mana/Mana.tsx | 7 +++--- src/components/Remark/Remark.tsx | 2 -- .../Remark/renderers/RemarkMana.tsx | 16 +++++++------ src/tools/mana/constants.ts | 8 +++---- src/tools/remark/remarkMana.client.ts | 23 ------------------- src/tools/remark/remarkMana.server.ts | 1 + src/tools/remark/remarkScries.server.ts | 1 + 8 files changed, 29 insertions(+), 41 deletions(-) delete mode 100644 src/tools/remark/remarkMana.client.ts diff --git a/markdown/partials/sandbox.md b/markdown/partials/sandbox.md index a7d9573b..0b22d2f0 100644 --- a/markdown/partials/sandbox.md +++ b/markdown/partials/sandbox.md @@ -54,10 +54,18 @@ faithful as can be. You can inline mana symbols _almost_ everywhere. ```md -{W} {U} {B} {R} {G} +{W} {U} {B} {R} {G} {WP} {UP} {BP} {RP} {GP} {2W} {2U} {2B} {2R} {2G} + +{WU} {UB} {BR} {RG} {GW} {WB} {UR} {BG} {RW} {GU} + +{0} {1} {2} … {20} {S} {C} {X} {Y} {Z} ``` -{W} {U} {B} {R} {G} +{W} {U} {B} {R} {G} {WP} {UP} {BP} {RP} {GP} {2W} {2U} {2B} {2R} {2G} + +{WU} {UB} {BR} {RG} {GW} {WB} {UR} {BG} {RW} {GU} + +{0} {1} {2} … {20} {S} {C} {X} {Y} {Z} When used collectively, for instance to indicate the color identity of an archetype, use the same order as found on the back of a _Magic: the Gathering_ diff --git a/src/components/Mana/Mana.tsx b/src/components/Mana/Mana.tsx index 6507d406..28f8c685 100644 --- a/src/components/Mana/Mana.tsx +++ b/src/components/Mana/Mana.tsx @@ -9,8 +9,9 @@ type Props = { export const Mana: FunctionComponent = ({ pattern }) => ( ); diff --git a/src/components/Remark/Remark.tsx b/src/components/Remark/Remark.tsx index eec4e9b1..50fbb531 100644 --- a/src/components/Remark/Remark.tsx +++ b/src/components/Remark/Remark.tsx @@ -18,7 +18,6 @@ import { remarkAccordion } from '@/tools/remark/remarkAccordion.client'; import { remarkBase } from '@/tools/remark/remarkBase.client'; import { remarkCard } from '@/tools/remark/remarkCard.client'; import { remarkDecklist } from '@/tools/remark/remarkDecklist.client'; -import { remarkMana } from '@/tools/remark/remarkMana.client'; import { remarkRow } from '@/tools/remark/remarkRow.client'; type Props = { @@ -47,7 +46,6 @@ export const Remark: FunctionComponent = ({ [remarkAccordion, { decklists }], remarkCard, [remarkDecklist, { decklists }], - remarkMana, [remarkRow, { scries: markdown.scries }], ], } as const satisfies Record; diff --git a/src/components/Remark/renderers/RemarkMana.tsx b/src/components/Remark/renderers/RemarkMana.tsx index 03f4f198..2c16d224 100644 --- a/src/components/Remark/renderers/RemarkMana.tsx +++ b/src/components/Remark/renderers/RemarkMana.tsx @@ -1,16 +1,18 @@ -import { type FunctionComponent } from 'react'; +import { type FunctionComponent, type PropsWithChildren } from 'react'; import { type ExtraProps } from 'react-markdown'; import { Mana } from '@/components/Mana/Mana'; -type Props = ExtraProps & { - pattern?: string; -}; +type Props = ExtraProps & PropsWithChildren & { pattern?: string }; -export const RemarkMana: FunctionComponent = ({ node, pattern }) => { +export const RemarkMana: FunctionComponent = ({ + children, + node, + pattern, +}) => { if (!pattern) { console.error('Missing pattern in mana', node); - return null; + return children; } - return ; + return ; }; diff --git a/src/tools/mana/constants.ts b/src/tools/mana/constants.ts index 32acf872..658445cb 100644 --- a/src/tools/mana/constants.ts +++ b/src/tools/mana/constants.ts @@ -2,14 +2,14 @@ const MANA = '[WUBRG]'; const PAIRS = [ '(?:WU)', - '(?:WB)', '(?:UB)', - '(?:UR)', '(?:BR)', - '(?:BG)', '(?:RG)', - '(?:RW)', '(?:GW)', + '(?:WB)', + '(?:UR)', + '(?:BG)', + '(?:RW)', '(?:GU)', ].join('|'); diff --git a/src/tools/remark/remarkMana.client.ts b/src/tools/remark/remarkMana.client.ts deleted file mode 100644 index 379d6457..00000000 --- a/src/tools/remark/remarkMana.client.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { hastify } from '@korumite/kiwi/client'; -import { type Text } from 'mdast'; -import { type TextDirective } from 'mdast-util-directive'; -import { type Node } from 'unist'; -import { select } from 'unist-util-select'; -import { Test, visit } from 'unist-util-visit'; - -import { Remarker } from '@/tools/remark/typings'; - -/** Augment mana directives with the pattern query. */ -export const remarkMana: Remarker = () => (tree) => { - const tests = [{ name: 'mana', type: 'textDirective' }]; - visit(tree, tests, (node) => { - const directive = node as Node & TextDirective; - const text = select('text', directive) as Text | undefined; - if (text) { - hastify(directive, { pattern: text.value }); - } else { - console.error(`[remark] Missing text for directive "${directive.name}"`); - } - }); - return tree; -}; diff --git a/src/tools/remark/remarkMana.server.ts b/src/tools/remark/remarkMana.server.ts index ec3ac456..fb46b98f 100644 --- a/src/tools/remark/remarkMana.server.ts +++ b/src/tools/remark/remarkMana.server.ts @@ -10,6 +10,7 @@ export const remarkMana: Plugin = () => async (tree) => { MANA_RE, (_match, value) => ({ + attributes: { pattern: value }, children: [{ type: 'text', value }], name: 'mana', type: 'textDirective', diff --git a/src/tools/remark/remarkScries.server.ts b/src/tools/remark/remarkScries.server.ts index e493519c..0cb16bb1 100644 --- a/src/tools/remark/remarkScries.server.ts +++ b/src/tools/remark/remarkScries.server.ts @@ -21,6 +21,7 @@ export const remarkScries: Plugin = () => async (tree, file) => { const directive = node as ContainerDirective; const text = select('text', directive) as Text | undefined; if (!text) { + // TODO Use file.fail() instead? throw new Error(`Missing content for directive "${directive.name}"`); } text.value.split('\n').forEach((query) => {