Skip to content

Commit f9388d6

Browse files
fix: update CustomTinaMarkdown custom components
1 parent ca19ae5 commit f9388d6

File tree

6 files changed

+152
-23
lines changed

6 files changed

+152
-23
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,7 @@ Make sure to deploy the output of `pnpm run build`
8787
## Styling
8888

8989
This template comes with [Mantine](https://mantine.dev/) already configured for a simple default starting experience. You can use whatever css framework you prefer. See the [Vite docs on css](https://vitejs.dev/guide/features.html#css) for more information.
90+
91+
## TODO
92+
93+
- Update `CustomTinaMarkdown` custom components.

app/components/CustomTinaMarkdown.tsx

+99-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1-
import { Blockquote, Code, Text, Title } from "@mantine/core";
1+
import {
2+
Anchor,
3+
Blockquote,
4+
Code,
5+
Divider,
6+
Image,
7+
Kbd,
8+
List,
9+
Mark,
10+
Table,
11+
Text,
12+
ThemeIcon,
13+
Title,
14+
} from "@mantine/core";
15+
import { IconCircleCheck, IconCircleDot } from "@tabler/icons-react";
216
import React from "react";
17+
import { Link } from "react-router";
318
import { TinaMarkdown, type TinaMarkdownContent } from "tinacms/dist/rich-text";
419

520
interface CustomTinaMarkdownProps {
@@ -13,26 +28,92 @@ export const CustomTinaMarkdown: React.FC<CustomTinaMarkdownProps> = ({
1328
};
1429

1530
const components = {
16-
h1: (props: any) => <Title order={1} mb="md" {...props} />,
17-
h2: (props: any) => <Title order={2} mb="md" {...props} />,
18-
h3: (props: any) => <Title order={3} mb="sm" {...props} />,
19-
h4: (props: any) => <Title order={4} mb="sm" {...props} />,
20-
h5: (props: any) => <Title order={5} mb="xs" {...props} />,
21-
h6: (props: any) => <Title order={6} mb="xs" {...props} />,
22-
p: (props: any) => <Text mb="md" {...props} />,
23-
ul: (props: any) => (
24-
<ul style={{ marginBottom: "1rem", paddingLeft: "1.5rem" }} {...props} />
31+
// Headings
32+
h1: (props: any) => <Title order={1} mb="md" mt="xl" {...props} />,
33+
h2: (props: any) => <Title order={2} mb="md" mt="xl" {...props} />,
34+
h3: (props: any) => <Title order={3} mb="sm" mt="lg" {...props} />,
35+
h4: (props: any) => <Title order={4} mb="sm" mt="md" {...props} />,
36+
h5: (props: any) => <Title order={5} mb="xs" mt="sm" {...props} />,
37+
h6: (props: any) => <Title order={6} mb="xs" mt="xs" {...props} />,
38+
39+
// Paragraph and basic text
40+
p: (props: any) => <Text mb="md" size="md" {...props} />,
41+
42+
// Lists
43+
ul: (props: any) => <List mb="md" spacing="xs" {...props} />,
44+
ol: (props: any) => <List mb="md" spacing="xs" type="ordered" {...props} />,
45+
li: (props: any) => <List.Item {...props} />,
46+
47+
// Block elements
48+
blockquote: (props: any) => (
49+
<Blockquote color="blue" mb="md" mt="md" cite={props.cite} {...props} />
2550
),
26-
ol: (props: any) => (
27-
<ol style={{ marginBottom: "1rem", paddingLeft: "1.5rem" }} {...props} />
51+
52+
// Code blocks
53+
code_block: (props: any) => (
54+
<Code block lang={props.language} mb="lg" mt="md">
55+
{props.value}
56+
</Code>
2857
),
29-
li: (props: any) => <li style={{ marginBottom: "0.25rem" }} {...props} />,
30-
blockquote: (props: any) => <Blockquote color="blue" mb="md" {...props} />,
31-
code_block: (props: any) => {
58+
59+
// Inline elements
60+
code: (props: any) => <Code {...props} />,
61+
em: (props: any) => <Text component="em" fs="italic" {...props} />,
62+
strong: (props: any) => <Text component="strong" fw={700} {...props} />,
63+
del: (props: any) => <Text component="del" td="line-through" {...props} />,
64+
hr: () => <Divider my="lg" />,
65+
66+
// Links and media
67+
a: (props: any) => {
68+
const isExternal = props.url.startsWith("http");
69+
70+
return (
71+
<Anchor
72+
component={isExternal ? "a" : Link}
73+
href={props.url}
74+
target={isExternal ? "_blank" : undefined}
75+
rel={isExternal ? "noopener noreferrer" : undefined}
76+
{...props}
77+
>
78+
{props.children}
79+
</Anchor>
80+
);
81+
},
82+
img: (props: any) => (
83+
<Image src={props.url} alt={props.alt || ""} title={props.title} my="md" />
84+
),
85+
86+
// Tables
87+
table: (props: any) => <Table mb="lg" {...props} />,
88+
thead: (props: any) => <Table.Thead {...props} />,
89+
tbody: (props: any) => <Table.Tbody {...props} />,
90+
tr: (props: any) => <Table.Tr {...props} />,
91+
td: (props: any) => <Table.Td {...props} />,
92+
th: (props: any) => <Table.Th {...props} />,
93+
94+
// Special inline elements
95+
mark: (props: any) => <Mark {...props} />,
96+
kbd: (props: any) => <Kbd {...props} />,
97+
98+
// Specific Tina components
99+
rich_text: (props: any) => <div {...props} />,
100+
101+
// Task lists (checkboxes)
102+
task_list_item: (props: any) => {
103+
const { checked } = props;
32104
return (
33-
<Code block lang={props.language} mb="md">
34-
{props.value}
35-
</Code>
105+
<List.Item
106+
icon={
107+
<ThemeIcon color={checked ? "green" : "gray"} size={20} radius="xl">
108+
{checked ? (
109+
<IconCircleCheck size={12} />
110+
) : (
111+
<IconCircleDot size={12} />
112+
)}
113+
</ThemeIcon>
114+
}
115+
{...props}
116+
/>
36117
);
37118
},
38119
};

app/components/Welcome.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ export const Welcome: React.FC = () => {
3636
<List spacing="xs">
3737
{resources.map(({ href, text, icon }) => (
3838
<List.Item key={href} icon={icon}>
39-
<Link to={href}>
40-
<Text c={isDark ? "blue.5" : "blue.7"}>{text}</Text>
41-
</Link>
39+
<Anchor
40+
to={href}
41+
component={Link}
42+
c={isDark ? "blue.5" : "blue.7"}
43+
>
44+
{text}
45+
</Anchor>
4246
</List.Item>
4347
))}
4448
</List>

content/posts/hello-world.md

+23-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut non lorem diam. Quis
88

99
Suspendisse facilisis, mi ac scelerisque interdum, ligula ex imperdiet felis, a posuere eros justo nec sem. Nullam laoreet accumsan metus, sit amet tincidunt orci egestas nec. Pellentesque ut aliquet ante, at tristique nunc. Donec non massa nibh. Ut posuere lacus non aliquam laoreet. Fusce pharetra ligula a felis porttitor, at mollis ipsum maximus. Donec quam tortor, vehicula a magna sit amet, tincidunt dictum enim. In hac habitasse platea dictumst. Mauris sit amet ornare ligula, blandit consequat risus. Duis malesuada pellentesque lectus, non feugiat turpis eleifend a. Nullam tempus ante et diam pretium, ac faucibus ligula interdum.
1010

11-
Link: [google](https://google.com)
11+
External Link: [google](https://google.com)
1212

13-
![](/image.png)
13+
Internal Link: [Blog Posts](/posts)
14+
15+
16+
External Image: ![](https://octodex.github.com/images/minion.png)
17+
18+
Internal Image: ![](/image.png)
1419

1520
> blockqoute
1621
@@ -31,3 +36,19 @@ function sum(a, b) {
3136
return a + b;
3237
}
3338
```
39+
40+
## Tables
41+
42+
| Option | Description |
43+
| ------ | ----------- |
44+
| data | path to data files to supply the data that will be passed into templates. |
45+
| engine | engine to be used for processing templates. Handlebars is the default. |
46+
| ext | extension to be used for dest files. |
47+
48+
Right aligned columns
49+
50+
| Option | Description |
51+
| ------:| -----------:|
52+
| data | path to data files to supply the data that will be passed into templates. |
53+
| engine | engine to be used for processing templates. Handlebars is the default. |
54+
| ext | extension to be used for dest files. |

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@mantine/core": "^7.17.1",
2626
"@mantine/hooks": "^7.17.1",
2727
"@react-router/node": "^7.3.0",
28+
"@tabler/icons-react": "^3.31.0",
2829
"isbot": "^5.1.23",
2930
"react": "^19.0.0",
3031
"react-dom": "^19.0.0",

pnpm-lock.yaml

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)