myst-to-react 0.1.18 → 0.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (242) hide show
  1. package/dist/cjs/admonitions.d.ts +32 -0
  2. package/dist/cjs/admonitions.d.ts.map +1 -0
  3. package/dist/cjs/admonitions.js +126 -0
  4. package/dist/cjs/basic.d.ts +62 -0
  5. package/dist/cjs/basic.d.ts.map +1 -0
  6. package/dist/cjs/basic.js +125 -0
  7. package/dist/cjs/card.d.ts +27 -0
  8. package/dist/cjs/card.d.ts.map +1 -0
  9. package/dist/cjs/card.js +64 -0
  10. package/dist/cjs/cite.d.ts +6 -0
  11. package/dist/cjs/cite.d.ts.map +1 -0
  12. package/dist/cjs/cite.js +36 -0
  13. package/dist/cjs/code.d.ts +20 -0
  14. package/dist/cjs/code.d.ts.map +1 -0
  15. package/dist/cjs/code.js +63 -0
  16. package/dist/cjs/components/ClickPopover.d.ts +11 -0
  17. package/dist/cjs/components/ClickPopover.d.ts.map +1 -0
  18. package/dist/cjs/components/ClickPopover.js +18 -0
  19. package/dist/cjs/components/CopyIcon.d.ts +5 -0
  20. package/dist/cjs/components/CopyIcon.d.ts.map +1 -0
  21. package/dist/cjs/components/CopyIcon.js +28 -0
  22. package/dist/cjs/components/HoverPopover.d.ts +9 -0
  23. package/dist/cjs/components/HoverPopover.d.ts.map +1 -0
  24. package/dist/cjs/components/HoverPopover.js +32 -0
  25. package/dist/cjs/components/LinkCard.d.ts +11 -0
  26. package/dist/cjs/components/LinkCard.d.ts.map +1 -0
  27. package/dist/cjs/components/LinkCard.js +15 -0
  28. package/dist/cjs/convertToReact.d.ts +6 -0
  29. package/dist/cjs/convertToReact.d.ts.map +1 -0
  30. package/dist/cjs/convertToReact.js +30 -0
  31. package/dist/cjs/crossReference.d.ts +13 -0
  32. package/dist/cjs/crossReference.d.ts.map +1 -0
  33. package/dist/cjs/crossReference.js +91 -0
  34. package/dist/cjs/dropdown.d.ts +16 -0
  35. package/dist/cjs/dropdown.d.ts.map +1 -0
  36. package/dist/cjs/dropdown.js +27 -0
  37. package/dist/cjs/extensions/chemicalFormula.d.ts +7 -0
  38. package/dist/cjs/extensions/chemicalFormula.d.ts.map +1 -0
  39. package/dist/cjs/extensions/chemicalFormula.js +39 -0
  40. package/dist/cjs/extensions/index.d.ts +4 -0
  41. package/dist/cjs/extensions/index.d.ts.map +1 -0
  42. package/dist/cjs/extensions/index.js +9 -0
  43. package/dist/cjs/extensions/siunits.d.ts +7 -0
  44. package/dist/cjs/extensions/siunits.d.ts.map +1 -0
  45. package/dist/cjs/extensions/siunits.js +12 -0
  46. package/dist/cjs/footnotes.d.ts +11 -0
  47. package/dist/cjs/footnotes.d.ts.map +1 -0
  48. package/dist/cjs/footnotes.js +24 -0
  49. package/dist/cjs/grid.d.ts +11 -0
  50. package/dist/cjs/grid.d.ts.map +1 -0
  51. package/dist/cjs/grid.js +117 -0
  52. package/dist/cjs/heading.d.ts +14 -0
  53. package/dist/cjs/heading.d.ts.map +1 -0
  54. package/dist/cjs/heading.js +40 -0
  55. package/dist/cjs/iframe.d.ts +7 -0
  56. package/dist/cjs/iframe.d.ts.map +1 -0
  57. package/dist/cjs/iframe.js +24 -0
  58. package/dist/cjs/image.d.ts +11 -0
  59. package/dist/cjs/image.d.ts.map +1 -0
  60. package/dist/cjs/image.js +52 -0
  61. package/dist/cjs/index.d.ts +10 -0
  62. package/dist/cjs/index.d.ts.map +1 -0
  63. package/dist/cjs/index.js +46 -0
  64. package/dist/cjs/inlineError.d.ts +8 -0
  65. package/dist/cjs/inlineError.d.ts.map +1 -0
  66. package/dist/cjs/inlineError.js +9 -0
  67. package/dist/cjs/links/github.d.ts +12 -0
  68. package/dist/cjs/links/github.d.ts.map +1 -0
  69. package/dist/cjs/links/github.js +63 -0
  70. package/dist/cjs/links/index.d.ts +14 -0
  71. package/dist/cjs/links/index.d.ts.map +1 -0
  72. package/dist/cjs/links/index.js +68 -0
  73. package/dist/cjs/links/rrid.d.ts +5 -0
  74. package/dist/cjs/links/rrid.d.ts.map +1 -0
  75. package/dist/cjs/links/rrid.js +35 -0
  76. package/dist/cjs/links/wiki.d.ts +8 -0
  77. package/dist/cjs/links/wiki.d.ts.map +1 -0
  78. package/dist/cjs/links/wiki.js +39 -0
  79. package/dist/cjs/math.d.ts +13 -0
  80. package/dist/cjs/math.d.ts.map +1 -0
  81. package/dist/cjs/math.js +29 -0
  82. package/dist/cjs/output/components.d.ts +10 -0
  83. package/dist/cjs/output/components.d.ts.map +1 -0
  84. package/dist/cjs/output/components.js +41 -0
  85. package/dist/cjs/output/error.d.ts +6 -0
  86. package/dist/cjs/output/error.d.ts.map +1 -0
  87. package/dist/cjs/output/error.js +15 -0
  88. package/dist/cjs/output/hooks.d.ts +67 -0
  89. package/dist/cjs/output/hooks.d.ts.map +1 -0
  90. package/dist/cjs/output/hooks.js +85 -0
  91. package/dist/cjs/output/index.d.ts +6 -0
  92. package/dist/cjs/output/index.d.ts.map +1 -0
  93. package/dist/cjs/output/index.js +7 -0
  94. package/dist/cjs/output/jupyter.d.ts +7 -0
  95. package/dist/cjs/output/jupyter.d.ts.map +1 -0
  96. package/dist/cjs/output/jupyter.js +75 -0
  97. package/dist/cjs/output/output.d.ts +7 -0
  98. package/dist/cjs/output/output.d.ts.map +1 -0
  99. package/dist/cjs/output/output.js +66 -0
  100. package/dist/cjs/output/outputBlock.d.ts +10 -0
  101. package/dist/cjs/output/outputBlock.d.ts.map +1 -0
  102. package/dist/cjs/output/outputBlock.js +13 -0
  103. package/dist/cjs/output/safe.d.ts +7 -0
  104. package/dist/cjs/output/safe.d.ts.map +1 -0
  105. package/dist/cjs/output/safe.js +77 -0
  106. package/dist/cjs/output/selectors.d.ts +10 -0
  107. package/dist/cjs/output/selectors.d.ts.map +1 -0
  108. package/dist/cjs/output/selectors.js +10 -0
  109. package/dist/cjs/output/stream.d.ts +6 -0
  110. package/dist/cjs/output/stream.d.ts.map +1 -0
  111. package/dist/cjs/output/stream.js +13 -0
  112. package/dist/cjs/reactive.d.ts +88 -0
  113. package/dist/cjs/reactive.d.ts.map +1 -0
  114. package/dist/cjs/reactive.js +64 -0
  115. package/dist/cjs/tabs.d.ts +12 -0
  116. package/dist/cjs/tabs.d.ts.map +1 -0
  117. package/dist/cjs/tabs.js +38 -0
  118. package/dist/cjs/types.d.ts +7 -0
  119. package/dist/cjs/types.d.ts.map +1 -0
  120. package/dist/cjs/types.js +2 -0
  121. package/dist/types/admonitions.d.ts +32 -0
  122. package/dist/types/admonitions.d.ts.map +1 -0
  123. package/dist/types/basic.d.ts +62 -0
  124. package/dist/types/basic.d.ts.map +1 -0
  125. package/dist/types/card.d.ts +27 -0
  126. package/dist/types/card.d.ts.map +1 -0
  127. package/dist/types/cite.d.ts +6 -0
  128. package/dist/types/cite.d.ts.map +1 -0
  129. package/dist/types/code.d.ts +20 -0
  130. package/dist/types/code.d.ts.map +1 -0
  131. package/dist/types/components/ClickPopover.d.ts +11 -0
  132. package/dist/types/components/ClickPopover.d.ts.map +1 -0
  133. package/dist/types/components/CopyIcon.d.ts +5 -0
  134. package/dist/types/components/CopyIcon.d.ts.map +1 -0
  135. package/dist/types/components/HoverPopover.d.ts +9 -0
  136. package/dist/types/components/HoverPopover.d.ts.map +1 -0
  137. package/dist/types/components/LinkCard.d.ts +11 -0
  138. package/dist/types/components/LinkCard.d.ts.map +1 -0
  139. package/dist/types/convertToReact.d.ts +6 -0
  140. package/dist/types/convertToReact.d.ts.map +1 -0
  141. package/dist/types/crossReference.d.ts +13 -0
  142. package/dist/types/crossReference.d.ts.map +1 -0
  143. package/dist/types/dropdown.d.ts +16 -0
  144. package/dist/types/dropdown.d.ts.map +1 -0
  145. package/dist/types/extensions/chemicalFormula.d.ts +7 -0
  146. package/dist/types/extensions/chemicalFormula.d.ts.map +1 -0
  147. package/dist/types/extensions/index.d.ts +4 -0
  148. package/dist/types/extensions/index.d.ts.map +1 -0
  149. package/dist/types/extensions/siunits.d.ts +7 -0
  150. package/dist/types/extensions/siunits.d.ts.map +1 -0
  151. package/dist/types/footnotes.d.ts +11 -0
  152. package/dist/types/footnotes.d.ts.map +1 -0
  153. package/dist/types/grid.d.ts +11 -0
  154. package/dist/types/grid.d.ts.map +1 -0
  155. package/dist/types/heading.d.ts +14 -0
  156. package/dist/types/heading.d.ts.map +1 -0
  157. package/dist/types/iframe.d.ts +7 -0
  158. package/dist/types/iframe.d.ts.map +1 -0
  159. package/dist/types/image.d.ts +11 -0
  160. package/dist/types/image.d.ts.map +1 -0
  161. package/dist/types/index.d.ts +10 -0
  162. package/dist/types/index.d.ts.map +1 -0
  163. package/dist/types/inlineError.d.ts +8 -0
  164. package/dist/types/inlineError.d.ts.map +1 -0
  165. package/dist/types/links/github.d.ts +12 -0
  166. package/dist/types/links/github.d.ts.map +1 -0
  167. package/dist/types/links/index.d.ts +14 -0
  168. package/dist/types/links/index.d.ts.map +1 -0
  169. package/dist/types/links/rrid.d.ts +5 -0
  170. package/dist/types/links/rrid.d.ts.map +1 -0
  171. package/dist/types/links/wiki.d.ts +8 -0
  172. package/dist/types/links/wiki.d.ts.map +1 -0
  173. package/dist/types/math.d.ts +13 -0
  174. package/dist/types/math.d.ts.map +1 -0
  175. package/dist/types/output/components.d.ts +10 -0
  176. package/dist/types/output/components.d.ts.map +1 -0
  177. package/dist/types/output/error.d.ts +6 -0
  178. package/dist/types/output/error.d.ts.map +1 -0
  179. package/dist/types/output/hooks.d.ts +67 -0
  180. package/dist/types/output/hooks.d.ts.map +1 -0
  181. package/dist/types/output/index.d.ts +6 -0
  182. package/dist/types/output/index.d.ts.map +1 -0
  183. package/dist/types/output/jupyter.d.ts +7 -0
  184. package/dist/types/output/jupyter.d.ts.map +1 -0
  185. package/dist/types/output/output.d.ts +7 -0
  186. package/dist/types/output/output.d.ts.map +1 -0
  187. package/dist/types/output/outputBlock.d.ts +10 -0
  188. package/dist/types/output/outputBlock.d.ts.map +1 -0
  189. package/dist/types/output/safe.d.ts +7 -0
  190. package/dist/types/output/safe.d.ts.map +1 -0
  191. package/dist/types/output/selectors.d.ts +10 -0
  192. package/dist/types/output/selectors.d.ts.map +1 -0
  193. package/dist/types/output/stream.d.ts +6 -0
  194. package/dist/types/output/stream.d.ts.map +1 -0
  195. package/dist/types/reactive.d.ts +88 -0
  196. package/dist/types/reactive.d.ts.map +1 -0
  197. package/dist/types/tabs.d.ts +12 -0
  198. package/dist/types/tabs.d.ts.map +1 -0
  199. package/dist/types/types.d.ts +7 -0
  200. package/dist/types/types.d.ts.map +1 -0
  201. package/package.json +20 -19
  202. package/src/admonitions.tsx +0 -183
  203. package/src/basic.tsx +0 -229
  204. package/src/card.tsx +0 -153
  205. package/src/cite.tsx +0 -43
  206. package/src/code.tsx +0 -119
  207. package/src/components/ClickPopover.tsx +0 -56
  208. package/src/components/CopyIcon.tsx +0 -40
  209. package/src/components/HoverPopover.tsx +0 -60
  210. package/src/components/LinkCard.tsx +0 -42
  211. package/src/convertToReact.ts +0 -33
  212. package/src/crossReference.tsx +0 -139
  213. package/src/dropdown.tsx +0 -69
  214. package/src/extensions/chemicalFormula.tsx +0 -42
  215. package/src/extensions/index.tsx +0 -10
  216. package/src/extensions/siunits.tsx +0 -15
  217. package/src/footnotes.tsx +0 -30
  218. package/src/grid.tsx +0 -127
  219. package/src/heading.tsx +0 -68
  220. package/src/iframe.tsx +0 -42
  221. package/src/image.tsx +0 -97
  222. package/src/index.tsx +0 -65
  223. package/src/inlineError.tsx +0 -15
  224. package/src/links/index.tsx +0 -132
  225. package/src/links/rrid.tsx +0 -81
  226. package/src/links/wiki.tsx +0 -119
  227. package/src/math.tsx +0 -81
  228. package/src/mermaid.tsx +0 -49
  229. package/src/myst.tsx +0 -226
  230. package/src/output/components.tsx +0 -34
  231. package/src/output/error.tsx +0 -20
  232. package/src/output/hooks.ts +0 -127
  233. package/src/output/index.tsx +0 -7
  234. package/src/output/jupyter.tsx +0 -86
  235. package/src/output/output.tsx +0 -79
  236. package/src/output/outputBlock.tsx +0 -21
  237. package/src/output/safe.tsx +0 -84
  238. package/src/output/selectors.ts +0 -15
  239. package/src/output/stream.tsx +0 -18
  240. package/src/reactive.tsx +0 -64
  241. package/src/tabs.tsx +0 -63
  242. package/src/types.ts +0 -6
@@ -1,183 +0,0 @@
1
- import type * as spec from 'myst-spec';
2
- import React, { useState } from 'react';
3
- import type { NodeRenderer } from './types';
4
- import {
5
- InformationCircleIcon,
6
- ExclamationIcon as OExclamationIcon,
7
- SpeakerphoneIcon,
8
- PencilAltIcon,
9
- ArrowCircleRightIcon,
10
- } from '@heroicons/react/outline';
11
- import {
12
- ExclamationIcon as SExclamationIcon,
13
- ExclamationCircleIcon as SExclamationCircleIcon,
14
- XCircleIcon,
15
- LightBulbIcon,
16
- LightningBoltIcon,
17
- ChevronRightIcon,
18
- } from '@heroicons/react/solid';
19
- import classNames from 'classnames';
20
- // import { AdmonitionKind } from 'mystjs';
21
-
22
- // TODO: get this from myst-spec?
23
- enum AdmonitionKind {
24
- admonition = 'admonition',
25
- attention = 'attention',
26
- caution = 'caution',
27
- danger = 'danger',
28
- error = 'error',
29
- important = 'important',
30
- hint = 'hint',
31
- note = 'note',
32
- seealso = 'seealso',
33
- tip = 'tip',
34
- warning = 'warning',
35
- }
36
-
37
- type ColorAndKind = {
38
- kind: AdmonitionKind;
39
- color: 'blue' | 'green' | 'yellow' | 'red';
40
- };
41
-
42
- function getClasses(className?: string) {
43
- const classes =
44
- className
45
- ?.split(' ')
46
- .map((s) => s.trim().toLowerCase())
47
- .filter((s) => !!s) ?? [];
48
- return [...new Set(classes)];
49
- }
50
-
51
- function getFirstKind({
52
- kind,
53
- classes = [],
54
- }: {
55
- kind?: AdmonitionKind | string;
56
- classes?: string[];
57
- }): ColorAndKind {
58
- if (kind === AdmonitionKind.note || classes.includes('note')) {
59
- return { kind: AdmonitionKind.note, color: 'blue' };
60
- }
61
- if (kind === AdmonitionKind.important || classes.includes('important')) {
62
- return { kind: AdmonitionKind.important, color: 'blue' };
63
- }
64
- if (kind === AdmonitionKind.hint || classes.includes('hint')) {
65
- return { kind: AdmonitionKind.hint, color: 'green' };
66
- }
67
- if (kind === AdmonitionKind.seealso || classes.includes('seealso')) {
68
- return { kind: AdmonitionKind.seealso, color: 'green' };
69
- }
70
- if (kind === AdmonitionKind.tip || classes.includes('tip')) {
71
- return { kind: AdmonitionKind.tip, color: 'green' };
72
- }
73
- if (kind === AdmonitionKind.attention || classes.includes('attention')) {
74
- return { kind: AdmonitionKind.attention, color: 'yellow' };
75
- }
76
- if (kind === AdmonitionKind.warning || classes.includes('warning')) {
77
- return { kind: AdmonitionKind.warning, color: 'yellow' };
78
- }
79
- if (kind === AdmonitionKind.caution || classes.includes('caution')) {
80
- return { kind: AdmonitionKind.caution, color: 'yellow' };
81
- }
82
- if (kind === AdmonitionKind.danger || classes.includes('danger')) {
83
- return { kind: AdmonitionKind.danger, color: 'red' };
84
- }
85
- if (kind === AdmonitionKind.error || classes.includes('error')) {
86
- return { kind: AdmonitionKind.error, color: 'red' };
87
- }
88
- return { kind: AdmonitionKind.note, color: 'blue' };
89
- }
90
-
91
- const iconClass = 'h-8 w-8 inline-block pl-2 mr-2 -translate-y-[1px]';
92
-
93
- function AdmonitionIcon({ kind }: { kind: AdmonitionKind }) {
94
- if (kind === AdmonitionKind.note) return <InformationCircleIcon className={iconClass} />;
95
- if (kind === AdmonitionKind.caution) return <OExclamationIcon className={iconClass} />;
96
- if (kind === AdmonitionKind.warning) return <SExclamationIcon className={iconClass} />;
97
- if (kind === AdmonitionKind.danger) return <SExclamationCircleIcon className={iconClass} />;
98
- if (kind === AdmonitionKind.error) return <XCircleIcon className={iconClass} />;
99
- if (kind === AdmonitionKind.attention) return <SpeakerphoneIcon className={iconClass} />;
100
- if (kind === AdmonitionKind.tip) return <PencilAltIcon className={iconClass} />;
101
- if (kind === AdmonitionKind.hint) return <LightBulbIcon className={iconClass} />;
102
- if (kind === AdmonitionKind.important) return <LightningBoltIcon className={iconClass} />;
103
- if (kind === AdmonitionKind.seealso) return <ArrowCircleRightIcon className={iconClass} />;
104
- return <InformationCircleIcon className={iconClass} />;
105
- }
106
-
107
- export const AdmonitionTitle: NodeRenderer<spec.AdmonitionTitle> = (node, children) => {
108
- return children;
109
- };
110
-
111
- function Admonition({
112
- title,
113
- kind,
114
- color,
115
- dropdown,
116
- children,
117
- }: ColorAndKind & { title: React.ReactNode; children: React.ReactNode[]; dropdown: boolean }) {
118
- const [open, setOpen] = useState(false);
119
-
120
- return (
121
- <aside
122
- className={classNames(
123
- 'admonition rounded-md my-4 border-l-4 shadow-md dark:shadow-2xl dark:shadow-neutral-900',
124
- {
125
- 'border-blue-500': color === 'blue',
126
- 'border-green-600': color === 'green',
127
- 'border-amber-600': color === 'yellow',
128
- 'border-red-600': color === 'red',
129
- },
130
- )}
131
- >
132
- <p
133
- className={classNames('admonition-header m-0 text-lg font-medium py-1', {
134
- 'text-blue-600 bg-blue-50 dark:bg-slate-900': color === 'blue',
135
- 'text-green-600 bg-green-50 dark:bg-slate-900': color === 'green',
136
- 'text-amber-600 bg-amber-50 dark:bg-slate-900': color === 'yellow',
137
- 'text-red-600 bg-red-50 dark:bg-slate-900': color === 'red',
138
- 'cursor-pointer hover:shadow-[inset_0_0_0px_20px_#00000003] dark:hover:shadow-[inset_0_0_0px_20px_#FFFFFF03]':
139
- dropdown,
140
- })}
141
- onClick={dropdown ? () => setOpen(!open) : undefined}
142
- >
143
- <AdmonitionIcon kind={kind} />
144
- <span className="text-neutral-900 dark:text-white">
145
- {dropdown && (
146
- <span className="block float-right font-thin text-sm text-neutral-700 dark:text-neutral-200">
147
- {!open && 'Click to show'}
148
- <ChevronRightIcon
149
- className={classNames(iconClass, 'transition-transform', {
150
- 'rotate-90 -translate-y-[5px]': open,
151
- })}
152
- />
153
- </span>
154
- )}
155
- {title}
156
- </span>
157
- </p>
158
- {(!dropdown || open) && (
159
- <div className="px-4 py-1 bg-gray-50 dark:bg-stone-800">{children}</div>
160
- )}
161
- </aside>
162
- );
163
- }
164
-
165
- export const AdmonitionRenderer: NodeRenderer<spec.Admonition> = (node, children) => {
166
- const [title, ...rest] = children as any[];
167
- const classes = getClasses(node.class);
168
- const { kind, color } = getFirstKind({ kind: node.kind, classes });
169
- const isDropdown = classes.includes('dropdown');
170
-
171
- return (
172
- <Admonition key={node.key} title={title} kind={kind} color={color} dropdown={isDropdown}>
173
- {rest}
174
- </Admonition>
175
- );
176
- };
177
-
178
- const ADMONITION_RENDERERS = {
179
- admonition: AdmonitionRenderer,
180
- admonitionTitle: AdmonitionTitle,
181
- };
182
-
183
- export default ADMONITION_RENDERERS;
package/src/basic.tsx DELETED
@@ -1,229 +0,0 @@
1
- import type * as spec from 'myst-spec';
2
- import { HashLink } from './heading';
3
- import type { NodeRenderer } from './types';
4
-
5
- type TableExts = {
6
- rowspan?: number;
7
- colspan?: number;
8
- };
9
-
10
- type Delete = {
11
- type: 'delete';
12
- };
13
-
14
- type Underline = {
15
- type: 'underline';
16
- };
17
-
18
- type SmallCaps = {
19
- type: 'smallcaps';
20
- };
21
-
22
- type DefinitionList = {
23
- type: 'definitionList';
24
- };
25
-
26
- type DefinitionTerm = {
27
- type: 'definitionTerm';
28
- };
29
-
30
- type DefinitionDescription = {
31
- type: 'definitionDescription';
32
- };
33
-
34
- type CaptionNumber = {
35
- type: 'captionNumber';
36
- kind: string;
37
- identifier: string;
38
- };
39
-
40
- type BasicNodeRenderers = {
41
- strong: NodeRenderer<spec.Strong>;
42
- emphasis: NodeRenderer<spec.Emphasis>;
43
- link: NodeRenderer<spec.Link>;
44
- paragraph: NodeRenderer<spec.Paragraph>;
45
- break: NodeRenderer<spec.Break>;
46
- inlineMath: NodeRenderer<spec.InlineMath>;
47
- math: NodeRenderer<spec.Math>;
48
- list: NodeRenderer<spec.List>;
49
- listItem: NodeRenderer<spec.ListItem>;
50
- container: NodeRenderer<spec.Container>;
51
- caption: NodeRenderer<spec.Caption>;
52
- blockquote: NodeRenderer<spec.Blockquote>;
53
- thematicBreak: NodeRenderer<spec.ThematicBreak>;
54
- subscript: NodeRenderer<spec.Subscript>;
55
- superscript: NodeRenderer<spec.Superscript>;
56
- abbreviation: NodeRenderer<spec.Abbreviation>;
57
- // Tables
58
- table: NodeRenderer<spec.Table>;
59
- tableRow: NodeRenderer<spec.TableRow>;
60
- tableCell: NodeRenderer<spec.TableCell & TableExts>;
61
- // Comment
62
- comment: NodeRenderer<spec.Comment>;
63
- mystComment: NodeRenderer<spec.Comment>;
64
- // Our additions
65
- captionNumber: NodeRenderer<CaptionNumber>;
66
- delete: NodeRenderer<Delete>;
67
- underline: NodeRenderer<Underline>;
68
- smallcaps: NodeRenderer<SmallCaps>;
69
- // definitions
70
- definitionList: NodeRenderer<DefinitionList>;
71
- definitionTerm: NodeRenderer<DefinitionTerm>;
72
- definitionDescription: NodeRenderer<DefinitionDescription>;
73
- };
74
-
75
- const BASIC_RENDERERS: BasicNodeRenderers = {
76
- delete(node, children) {
77
- return <del key={node.key}>{children}</del>;
78
- },
79
- strong(node, children) {
80
- return <strong key={node.key}>{children}</strong>;
81
- },
82
- emphasis(node, children) {
83
- return <em key={node.key}>{children}</em>;
84
- },
85
- underline(node, children) {
86
- return (
87
- <span key={node.key} style={{ textDecoration: 'underline' }}>
88
- {children}
89
- </span>
90
- );
91
- },
92
- smallcaps(node, children) {
93
- return (
94
- <span key={node.key} style={{ fontVariant: 'small-caps' }}>
95
- {children}
96
- </span>
97
- );
98
- },
99
- link(node, children) {
100
- return (
101
- <a key={node.key} target="_blank" href={node.url} rel="noreferrer">
102
- {children}
103
- </a>
104
- );
105
- },
106
- paragraph(node, children) {
107
- return <p key={node.key}>{children}</p>;
108
- },
109
- break(node) {
110
- return <br key={node.key} />;
111
- },
112
- inlineMath(node) {
113
- return <code key={node.key}>{node.value}</code>;
114
- },
115
- math(node) {
116
- return <code key={node.key}>{node.value}</code>;
117
- },
118
- list(node, children) {
119
- if (node.ordered) {
120
- return (
121
- <ol key={node.key} start={node.start || undefined}>
122
- {children}
123
- </ol>
124
- );
125
- }
126
- return <ul key={node.key}>{children}</ul>;
127
- },
128
- listItem(node, children) {
129
- return <li key={node.key}>{children}</li>;
130
- },
131
- container(node, children) {
132
- return (
133
- <figure key={node.key} id={node.html_id || node.identifier || node.key} className={node.kind}>
134
- {children}
135
- </figure>
136
- );
137
- },
138
- caption(node, children) {
139
- return (
140
- <figcaption key={node.key} className="group">
141
- {children}
142
- </figcaption>
143
- );
144
- },
145
- blockquote(node, children) {
146
- return <blockquote key={node.key}>{children}</blockquote>;
147
- },
148
- thematicBreak(node) {
149
- return <hr key={node.key} />;
150
- },
151
- captionNumber(node, children) {
152
- function backwardsCompatibleLabel(value: string, kind?: string) {
153
- const capital = kind?.slice(0, 1).toUpperCase() ?? 'F';
154
- const body = kind?.slice(1) ?? 'igure';
155
- return `${capital}${body}: ${children}`;
156
- }
157
- const label =
158
- typeof children === 'string' ? backwardsCompatibleLabel(children, node.kind) : children;
159
- const id = node.html_id || node.identifier || node.key;
160
- return (
161
- <span key={node.key} className="font-bold mr-1 select-none relative">
162
- <HashLink id={id} align="left" kind={node.kind} />
163
- {label}
164
- </span>
165
- );
166
- },
167
- table(node, children) {
168
- // TODO: actually render the tbody on the server if it isn't included here.
169
- return (
170
- <table key={node.key}>
171
- <tbody>{children}</tbody>
172
- </table>
173
- );
174
- },
175
- tableRow(node, children) {
176
- return <tr key={node.key}>{children}</tr>;
177
- },
178
- tableCell(node, children) {
179
- const ifGreaterThanOne = (num?: number) => (num === 1 ? undefined : num);
180
- const attrs = {
181
- key: node.key,
182
- rowSpan: ifGreaterThanOne(node.rowspan),
183
- colSpan: ifGreaterThanOne(node.colspan),
184
- };
185
- if (node.header) return <th {...attrs}>{children}</th>;
186
- return <td {...attrs}>{children}</td>;
187
- },
188
- subscript(node, children) {
189
- return <sub key={node.key}>{children}</sub>;
190
- },
191
- superscript(node, children) {
192
- return <sup key={node.key}>{children}</sup>;
193
- },
194
- abbreviation(node, children) {
195
- return (
196
- <abbr key={node.key} title={node.title}>
197
- {children}
198
- </abbr>
199
- );
200
- },
201
- mystComment() {
202
- return null;
203
- },
204
- comment() {
205
- return null;
206
- },
207
- definitionList(node, children) {
208
- return <dl key={node.key}>{children}</dl>;
209
- },
210
- definitionTerm(node, children) {
211
- let strongChildren: React.ReactNode = children;
212
- if (Array.isArray(children)) {
213
- const allowedStrongTypes = new Set(['emphasis']);
214
- strongChildren = children.map((child, i) => {
215
- if (typeof child === 'string') return <strong key={node.key + i}>{child}</strong>;
216
- if (allowedStrongTypes.has(child?.type)) return <strong key={node.key + i}>{child}</strong>;
217
- return child;
218
- });
219
- } else if (typeof children === 'string') {
220
- strongChildren = <strong key={node.key + '0'}>{children}</strong>;
221
- }
222
- return <dt key={node.key}>{strongChildren}</dt>;
223
- },
224
- definitionDescription(node, children) {
225
- return <dd key={node.key}>{children}</dd>;
226
- },
227
- };
228
-
229
- export default BASIC_RENDERERS;
package/src/card.tsx DELETED
@@ -1,153 +0,0 @@
1
- import React from 'react';
2
- import type { NodeRenderer } from './types';
3
- import classNames from 'classnames';
4
- import { Link } from '@remix-run/react';
5
- // import { AdmonitionKind } from 'mystjs';
6
-
7
- type CardSpec = {
8
- type: 'card';
9
- url?: string;
10
- static?: boolean;
11
- };
12
- type CardTitleSpec = {
13
- type: 'cardTitle';
14
- };
15
- type HeaderSpec = {
16
- type: 'header';
17
- };
18
- type FooterSpec = {
19
- type: 'footer';
20
- };
21
-
22
- export const Header: NodeRenderer<HeaderSpec> = (node, children) => {
23
- return (
24
- <header
25
- key={node.key}
26
- className="m-0 py-1 pl-3 bg-gray-50 dark:bg-slate-900 border-b border-gray-100 dark:border-gray-800"
27
- >
28
- {children}
29
- </header>
30
- );
31
- };
32
-
33
- export const Footer: NodeRenderer<FooterSpec> = (node, children) => {
34
- return (
35
- <footer
36
- key={node.key}
37
- className="m-0 py-1 pl-3 bg-gray-50 dark:bg-slate-900 border-t border-gray-100 dark:border-gray-800"
38
- >
39
- {children}
40
- </footer>
41
- );
42
- };
43
-
44
- export const CardTitle: NodeRenderer<CardTitleSpec> = (node, children) => {
45
- return (
46
- <div key={node.key} className="pt-3 font-bold group-hover:underline">
47
- {children}
48
- </div>
49
- );
50
- };
51
-
52
- type Parts = {
53
- header?: React.ReactNode;
54
- body?: React.ReactNode;
55
- footer?: React.ReactNode;
56
- };
57
-
58
- function getParts(children: React.ReactNode): Parts {
59
- const parts: Parts = {};
60
- if (!Array.isArray(children)) return parts;
61
- const next = [...children];
62
- if (next[0]?.type === 'header') {
63
- parts.header = next.splice(0, 1);
64
- }
65
- if (next[next.length - 1]?.type === 'footer') {
66
- parts.footer = next.splice(-1, 1);
67
- }
68
- parts.body = next;
69
- return parts;
70
- }
71
-
72
- function ExternalOrInternalLink({
73
- to,
74
- className,
75
- isStatic,
76
- prefetch = 'intent',
77
- children,
78
- }: {
79
- to: string;
80
- className?: string;
81
- isStatic?: boolean;
82
- prefetch?: 'intent' | 'render' | 'none';
83
- children: React.ReactNode;
84
- }) {
85
- if (to.startsWith('http') || isStatic) {
86
- return (
87
- <a href={to} className={className} target="_blank" rel="noopener noreferrer">
88
- {children}
89
- </a>
90
- );
91
- }
92
- return (
93
- <Link to={to} className={className} prefetch={prefetch}>
94
- {children}
95
- </Link>
96
- );
97
- }
98
-
99
- function Card({
100
- children,
101
- url,
102
- isStatic,
103
- }: {
104
- children: React.ReactNode;
105
- url?: string;
106
- isStatic?: boolean;
107
- }) {
108
- const parts = getParts(children);
109
- const link = !!url;
110
- const sharedStyle =
111
- 'rounded-md shadow dark:shadow-neutral-800 overflow-hidden border border-gray-100 dark:border-gray-800 flex flex-col';
112
- if (link) {
113
- return (
114
- <ExternalOrInternalLink
115
- to={url}
116
- isStatic={isStatic}
117
- className={classNames(
118
- sharedStyle,
119
- 'block font-normal no-underline cursor-pointer group',
120
- 'hover:border-blue-500 dark:hover:border-blue-400',
121
- )}
122
- >
123
- {parts.header}
124
- <div className="py-2 px-4 flex-grow">{parts.body}</div>
125
- {parts.footer}
126
- </ExternalOrInternalLink>
127
- );
128
- }
129
- return (
130
- <div className={sharedStyle}>
131
- {parts.header}
132
- <div className="py-2 px-4 flex-grow">{parts.body}</div>
133
- {parts.footer}
134
- </div>
135
- );
136
- }
137
-
138
- export const CardRenderer: NodeRenderer<CardSpec> = (node, children) => {
139
- return (
140
- <Card key={node.key} url={node.url} isStatic={node.static || false}>
141
- {children}
142
- </Card>
143
- );
144
- };
145
-
146
- const CARD_RENDERERS = {
147
- card: CardRenderer,
148
- cardTitle: CardTitle,
149
- header: Header,
150
- footer: Footer,
151
- };
152
-
153
- export default CARD_RENDERERS;
package/src/cite.tsx DELETED
@@ -1,43 +0,0 @@
1
- import classNames from 'classnames';
2
- import { useReferences } from '@curvenote/ui-providers';
3
- import type { NodeRenderer } from './types';
4
- import { ClickPopover } from './components/ClickPopover';
5
- import { InlineError } from './inlineError';
6
-
7
- function CiteChild({ label }: { label: string }) {
8
- const references = useReferences();
9
- const { html } = references?.cite?.data[label] ?? {};
10
- return <div dangerouslySetInnerHTML={{ __html: html || '' }} />;
11
- }
12
-
13
- export const CiteGroup: NodeRenderer = (node, children) => {
14
- return (
15
- <span
16
- key={node.key}
17
- className={classNames('cite-group', {
18
- narrative: node.kind === 'narrative',
19
- parenthetical: node.kind === 'parenthetical',
20
- })}
21
- >
22
- {children}
23
- </span>
24
- );
25
- };
26
-
27
- export const Cite: NodeRenderer = (node, children) => {
28
- if (node.error) {
29
- return <InlineError key={node.key} value={node.label} message={'Citation Not Found'} />;
30
- }
31
- return (
32
- <ClickPopover key={node.key} card={<CiteChild label={node.label as string} />}>
33
- {children}
34
- </ClickPopover>
35
- );
36
- };
37
-
38
- const CITE_RENDERERS: Record<string, NodeRenderer> = {
39
- citeGroup: CiteGroup,
40
- cite: Cite,
41
- };
42
-
43
- export default CITE_RENDERERS;