-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
-
147
-
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
-
156
-
157
-
158
-
159
-
160
-
161
-
162
-
163
-
164
-
165
-
166
-
167
-
168
-
169
-
170
-
171
-
172
-
173
-
174
-
175
-
176
-
177
-
178
-
179
-
180
-
181
-
182
-
183
// SPDX-FileCopyrightText: 2024 Shota FUJI <pockawoooh@gmail.com>
//
// SPDX-License-Identifier: Apache-2.0
import type * as Hast from "../../../deps/esm.sh/hast/types.ts";
import type * as Mdast from "../../../deps/esm.sh/mdast/types.ts";
import { h } from "../../../deps/esm.sh/hastscript/mod.ts";
import { toHast } from "../../../deps/esm.sh/mdast-util-to-hast/mod.ts";
import {
ofmHtml,
ofmToHastHandlers,
} from "../../../content_parser/obsidian_markdown.ts";
import { buildClasses, css, join as joinCss } from "../css.ts";
import { calloutHandlers, calloutStyles } from "./callout.tsx";
import { listHandlers, listStyles } from "./list.tsx";
import { mathHandlers } from "./math.ts";
import { codeHandlers, codeStyles } from "./code.tsx";
import { linkHandlers, linkStyles } from "./link.tsx";
import { quoteHandlers, quoteStyles } from "./quote.tsx";
const c = buildClasses("fm-0", ["wrapper"]);
const ownStyles = css`
:where(.${c.wrapper}) p {
margin: 0;
margin-top: calc(var(--baseline) * 1rem);
}
:where(.${c.wrapper}) time,
:where(.${c.wrapper}) span,
:where(.${c.wrapper}) code,
:where(.${c.wrapper}) sup,
:where(.${c.wrapper}) small,
:where(.${c.wrapper}) s,
:where(.${c.wrapper}) b,
:where(.${c.wrapper}) i {
line-height: 1;
}
:where(.${c.wrapper}) button {
font-family: inherit;
}
:where(.${c.wrapper}) s,
:where(.${c.wrapper}) del {
color: var(--color-fg-sub);
text-decoration: line-through;
}
:where(.${c.wrapper}) b {
font-weight: bold;
}
:where(.${c.wrapper}) i {
font-style: italic;
}
:where(.${c.wrapper}) ul {
margin: 0;
margin-top: calc(var(--baseline) * 1rem);
padding-left: 1.5em;
}
:where(.${c.wrapper}) ul ul {
margin-top: 0;
}
:where(.${c.wrapper}) h1,
:where(.${c.wrapper}) h2,
:where(.${c.wrapper}) h3 {
font-weight: 700;
color: var(--color-fg-sub);
}
:where(.${c.wrapper}) h1 {
margin: 0;
margin-top: calc(var(--baseline) * 2rem);
line-height: calc(var(--baseline) * 2rem);
}
:where(.${c.wrapper}) h2 {
margin: 0;
margin-top: calc(var(--baseline) * 2rem);
}
:where(.${c.wrapper}) h3,
:where(.${c.wrapper}) h4,
:where(.${c.wrapper}) h5,
:where(.${c.wrapper}) h6 {
margin: 0;
margin-top: calc(var(--baseline) * 1rem);
font-weight: 600;
}
:where(.${c.wrapper}) table {
border-spacing: 0;
margin: 0;
margin-top: calc(var(--baseline) * 0.5rem);
width: 100%;
}
:where(.${c.wrapper}) thead {
background-color: var(--color-bg-accent);
}
:where(.${c.wrapper}) th {
font-weight: 500;
padding: calc(var(--baseline) * 0.25rem) 1em;
}
:where(.${c.wrapper}) td {
padding: calc(var(--baseline) * 0.5rem) 1em;
}
:where(.${c.wrapper}) tbody td {
position: relative;
}
:where(.${c.wrapper}) tbody td::after {
content: "";
position: absolute;
left: 0;
right: 0;
bottom: 0;
border-bottom: 1px solid var(--color-fg-light);
}
:where(.${c.wrapper}) hr {
margin: 0;
margin-top: calc(var(--baseline) * 1rem);
}
:where(.${c.wrapper}) img {
max-width: 100%;
}
:where(.${c.wrapper}) img:not(:first-child) {
margin-top: calc(var(--baseline) * 1rem);
}
:where(.${c.wrapper}) > math {
display: block;
margin-top: calc(var(--baseline) * 1rem);
}
@supports (display: math) {
:where(.${c.wrapper}) > math {
display: math;
width: 100%;
}
}
`;
export const fromMdastStyles = joinCss(
ownStyles,
calloutStyles,
listStyles,
codeStyles,
linkStyles,
quoteStyles,
);
export function fromMdast(mdast: Mdast.Nodes): Hast.Nodes {
return ofmHtml(toHast(mdast, {
handlers: {
...ofmToHastHandlers(),
...calloutHandlers(),
...listHandlers(),
...mathHandlers(),
...codeHandlers(),
...linkHandlers(),
...quoteHandlers(),
},
allowDangerousHtml: true,
}));
}
export function style(node: Hast.Nodes): Hast.Nodes {
return h("div", { class: c.wrapper }, [node]);
}