Skip to content

Commit

Permalink
refactor(mana): deprecate remarkMana.client
Browse files Browse the repository at this point in the history
  • Loading branch information
angrybacon committed May 12, 2024
1 parent 6c53722 commit 2e6e395
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 41 deletions.
12 changes: 10 additions & 2 deletions markdown/partials/sandbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down
7 changes: 4 additions & 3 deletions src/components/Mana/Mana.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ type Props = {

export const Mana: FunctionComponent<Props> = ({ pattern }) => (
<Box
component="i"
className={`ms ms-cost ms-${pattern}`}
sx={{ fontSize: '.8em', mx: 0.125, verticalAlign: 'initial' }}
aria-label={`Mana symbol: "${pattern}"`}
component="span"
className={`ms ms-cost ms-${pattern.toLowerCase()}`}
sx={{ fontSize: '.9em', mx: 0.25, verticalAlign: 'text-bottom' }}
/>
);
2 changes: 0 additions & 2 deletions src/components/Remark/Remark.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -47,7 +46,6 @@ export const Remark: FunctionComponent<Props> = ({
[remarkAccordion, { decklists }],
remarkCard,
[remarkDecklist, { decklists }],
remarkMana,
[remarkRow, { scries: markdown.scries }],
],
} as const satisfies Record<string, PluggableList>;
Expand Down
16 changes: 9 additions & 7 deletions src/components/Remark/renderers/RemarkMana.tsx
Original file line number Diff line number Diff line change
@@ -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<Props> = ({ node, pattern }) => {
export const RemarkMana: FunctionComponent<Props> = ({
children,
node,
pattern,
}) => {
if (!pattern) {
console.error('Missing pattern in mana', node);
return null;
return children;
}
return <Mana pattern={pattern.toLowerCase()} />;
return <Mana pattern={pattern} />;
};
8 changes: 4 additions & 4 deletions src/tools/mana/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ const MANA = '[WUBRG]';

const PAIRS = [
'(?:WU)',
'(?:WB)',
'(?:UB)',
'(?:UR)',
'(?:BR)',
'(?:BG)',
'(?:RG)',
'(?:RW)',
'(?:GW)',
'(?:WB)',
'(?:UR)',
'(?:BG)',
'(?:RW)',
'(?:GU)',
].join('|');

Expand Down
23 changes: 0 additions & 23 deletions src/tools/remark/remarkMana.client.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/tools/remark/remarkMana.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions src/tools/remark/remarkScries.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 2e6e395

Please sign in to comment.