Skip to content

Commit 074a5f8

Browse files
committed
add formatting to markdown
1 parent 936d49e commit 074a5f8

File tree

6 files changed

+119
-64
lines changed

6 files changed

+119
-64
lines changed

app/routes/MdxRoute.res

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,49 @@ module Category = Sidebar.Category
88

99
type loaderData = {...Mdx.t}
1010

11+
/**
12+
This configures the MDX component to use our custom markdown components
13+
*/
14+
let components = {
15+
// Replacing HTML defaults
16+
"a": Markdown.A.make,
17+
"blockquote": Markdown.Blockquote.make,
18+
"code": Markdown.Code.make,
19+
"h1": Markdown.H1.make,
20+
"h2": Markdown.H2.make,
21+
"h3": Markdown.H3.make,
22+
"h4": Markdown.H4.make,
23+
"h5": Markdown.H5.make,
24+
"hr": Markdown.Hr.make,
25+
"intro": Markdown.Intro.make,
26+
"li": Markdown.Li.make,
27+
"ol": Markdown.Ol.make,
28+
"p": Markdown.P.make,
29+
"pre": Markdown.Pre.make,
30+
"strong": Markdown.Strong.make,
31+
"table": Markdown.Table.make,
32+
"th": Markdown.Th.make,
33+
"thead": Markdown.Thead.make,
34+
"ul": Markdown.Ul.make,
35+
// These are custom components we provide
36+
"Cite": Markdown.Cite.make,
37+
"CodeTab": Markdown.CodeTab.make,
38+
"Image": Markdown.Image.make,
39+
"Info": Markdown.Info.make,
40+
"Intro": Markdown.Intro.make,
41+
"UrlBox": Markdown.UrlBox.make,
42+
"Video": Markdown.Video.make,
43+
"Warn": Markdown.Warn.make,
44+
}
45+
1146
let loader: Loader.t<loaderData> = async ({request}) => {
1247
let mdx = await loadMdx(request)
1348
let res: loaderData = {__raw: mdx.__raw, attributes: mdx.attributes}
1449
res
1550
}
1651

1752
let default = () => {
18-
let component = useMdxComponent()
53+
let component = useMdxComponent(~components)
1954
let attributes = useMdxAttributes()
2055
let _ = Toc.useToc(~category="manual")
2156

@@ -28,8 +63,10 @@ let default = () => {
2863
// availableVersions=Constants.allManualVersions
2964
// nextVersion=?Constants.nextVersion>
3065
// // {React.string(attributes.title)} </h1>
31-
<div className="markdown-body">
32-
<DocsLayout metaTitleCategory="Foo" categories=[]> {component()} </DocsLayout>
66+
<div>
67+
<DocsLayout metaTitleCategory="Foo" categories=[]>
68+
<div className="markdown-body"> {component()} </div>
69+
</DocsLayout>
3370
</div>
3471
// </ManualDocsLayout.V1200Layout>
3572
}

docs/manual/installation.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ canonical: "/docs/manual/v12.0.0/installation"
88

99
## Prerequisites
1010

11+
<div class="install-list">
1112
- [Node.js](https://nodejs.org/) version >= 20
1213
- One of the following package managers:
1314
- [npm](https://docs.npmjs.com/cli/) (comes with Node.js)
@@ -17,6 +18,7 @@ canonical: "/docs/manual/v12.0.0/installation"
1718
- [bun](https://bun.sh/)
1819
- [deno](http://deno.com/)
1920
- Configure `"nodeModulesDir": "auto"` in `deno.json`
21+
</div>
2022

2123
## New Project
2224

src/bindings/ReactRouter.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ module Mdx = {
105105
external useMdxAttributes: unit => attributes = "useMdxAttributes"
106106

107107
@module("react-router-mdx/client")
108-
external useMdxComponent: unit => Jsx.component<'a> = "useMdxComponent"
108+
external useMdxComponent: (~components: {..}=?) => Jsx.component<'a> = "useMdxComponent"
109109

110110
@module("react-router-mdx/server")
111111
external loadAllMdx: (~filterByPaths: array<string>=?) => promise<array<t>> = "loadAllMdx"

src/components/Markdown.res

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ module Anchor = {
116116
<span className="inline group relative">
117117
<a
118118
className="invisible text-gray-60 opacity-50 hover:opacity-100 hover:text-gray-60 hover:cursor-pointer group-hover:visible"
119-
href={"#" ++ id}>
119+
href={"#" ++ id}
120+
>
120121
<Icon.Hyperlink className="inline-block align-middle text-gray-40" />
121122
</a>
122123
<a className="absolute -top-28" id />
@@ -170,7 +171,8 @@ module H5 = {
170171
let make = (~id, ~children) =>
171172
<h5
172173
id
173-
className="group mt-12 mb-3 text-12 leading-2 font-sans font-semibold uppercase tracking-wide text-gray-80">
174+
className="group mt-12 mb-3 text-12 leading-2 font-sans font-semibold uppercase tracking-wide text-gray-80"
175+
>
174176
children
175177
<span className="ml-2">
176178
<Anchor id />
@@ -187,7 +189,8 @@ module InlineCode = {
187189
@react.component
188190
let make = (~children) =>
189191
<code
190-
className="md-inline-code px-2 py-0.5 text-gray-60 font-mono rounded-sm bg-gray-10-tr border border-gray-90/5">
192+
className="md-inline-code px-2 py-0.5 text-gray-60 font-mono rounded-sm bg-gray-10-tr border border-gray-90/5"
193+
>
191194
children
192195
</code>
193196
}
@@ -209,7 +212,8 @@ module Th = {
209212
@react.component
210213
let make = (~children) =>
211214
<th
212-
className="py-2 pr-8 text-12 text-gray-60 uppercase font-medium tracking-wide text-left border-b-2 border-gray-20">
215+
className="py-2 pr-8 text-12 text-gray-60 uppercase font-medium tracking-wide text-left border-b-2 border-gray-20"
216+
>
213217
children
214218
</th>
215219
}

styles/_markdown.css

Lines changed: 59 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,75 @@
11
/* Markdown related stuff */
22
/* Sometimes we cannot circumvent the cascade, especially for nested lists */
3+
.markdown-body {
34

4-
.md-ul,
5-
.md-ol {
6-
@apply mb-8;
7-
}
5+
ol {
6+
li {
7+
counter-increment: li;
88

9-
.md-ul ul {
10-
@apply mb-0;
11-
}
9+
&::before {
10+
content: counter(li) ".";
11+
@apply absolute font-semibold;
12+
}
13+
}
14+
}
1215

13-
.md-ol > li {
14-
counter-increment: li;
15-
}
16+
ul {
17+
@apply mb-0;
1618

17-
.md-ul .md-li {
18-
@apply relative my-6;
19-
}
19+
ol {
20+
@apply mb-0;
21+
}
2022

21-
.md-ol > .md-li::before {
22-
content: counter(li) ".";
23-
@apply absolute font-semibold;
24-
}
23+
li {
24+
@apply relative my-6;
2525

26-
.md-ul > .md-li::before {
27-
content: "•";
28-
@apply absolute;
29-
}
26+
&::before {
27+
content: "•";
28+
@apply absolute;
29+
}
3030

31-
.md-ul > .md-li > ul > li::before {
32-
content: "—";
33-
@apply absolute;
34-
}
31+
ul {
32+
@apply mb-14 ml-4;
33+
}
3534

36-
.md-ul > .md-li > ul {
37-
@apply mb-14 ml-4;
38-
}
35+
p {
36+
@apply text-gray-80 ml-5;
37+
}
38+
}
39+
}
3940

40-
.md-li > p {
41-
@apply text-gray-80 ml-5;
42-
}
41+
li {
42+
ul {
43+
p {
44+
@apply ml-6;
45+
}
46+
}
47+
}
4348

44-
.md-li > ul > li p {
45-
@apply ml-6;
46-
}
49+
p+p {
50+
@apply mt-6;
51+
}
4752

48-
.md-p + .md-p {
49-
@apply mt-6;
50-
}
53+
/* INFOBOX (Markdown.res) Find a better solution for <p> text inside of Info-Box (Markdown)? */
54+
.infobox {
55+
p {
56+
@apply text-14 mt-0;
5157

52-
/* INFOBOX (Markdown.res) Find a better solution for <p> text inside of Info-Box (Markdown)? */
53-
.infobox > p {
54-
@apply text-14 mt-0;
55-
}
58+
a {
59+
@apply underline text-current;
5660

57-
.infobox > .md-p {
58-
@apply mt-0;
59-
}
61+
&::hover {
62+
@apply no-underline text-current text-gray-70;
63+
}
64+
}
65+
}
66+
}
6067

61-
.infobox > p > a {
62-
@apply underline text-current;
63-
}
64-
.infobox > p > a:hover {
65-
@apply no-underline text-current text-gray-70;
66-
}
68+
.install-list {
69+
li {
70+
ul {
71+
@apply !mb-0;
72+
}
73+
}
74+
}
75+
}

styles/main.css

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
@import "./_fonts.css" layer(base);
33
@import "./_docsearch.css" layer(base);
44

5+
56
@import "tailwindcss";
67

78
@source '../src/**/*.{mjs,js,res}';
@@ -163,6 +164,7 @@
163164
--shadow-sm: 0 0.5px 0.5px 0 rgba(0, 0, 0, 0.05);
164165

165166
@keyframes pulse {
167+
166168
0%,
167169
100% {
168170
opacity: 1;
@@ -183,6 +185,7 @@
183185
color utility to any element that depends on these defaults.
184186
*/
185187
@layer base {
188+
186189
*,
187190
::after,
188191
::before,
@@ -294,7 +297,7 @@
294297
/* Chrome/Safari/Webkit */
295298
}
296299

297-
a > code {
300+
a>code {
298301
@apply text-fire;
299302
}
300303
}
@@ -351,14 +354,14 @@
351354
}
352355

353356
.cm-s-material .CodeMirror-line::selection,
354-
.cm-s-material .CodeMirror-line > span::selection,
355-
.cm-s-material .CodeMirror-line > span > span::selection {
357+
.cm-s-material .CodeMirror-line>span::selection,
358+
.cm-s-material .CodeMirror-line>span>span::selection {
356359
background: rgba(128, 203, 196, 0.2);
357360
}
358361

359362
.cm-s-material .CodeMirror-line::-moz-selection,
360-
.cm-s-material .CodeMirror-line > span::-moz-selection,
361-
.cm-s-material .CodeMirror-line > span > span::-moz-selection {
363+
.cm-s-material .CodeMirror-line>span::-moz-selection,
364+
.cm-s-material .CodeMirror-line>span>span::-moz-selection {
362365
background: rgba(128, 203, 196, 0.2);
363366
}
364367

@@ -548,4 +551,4 @@
548551
.CodeMirror-overlayscroll-vertical div {
549552
right: 0;
550553
width: 100%;
551-
}
554+
}

0 commit comments

Comments
 (0)