@willwang-io/react-djot 0.1.4 → 0.1.6

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.
package/README.md CHANGED
@@ -41,7 +41,7 @@ export function Example() {
41
41
  ### `<Djot />`
42
42
 
43
43
  ```tsx
44
- import { Djot } from "react-djot";
44
+ import { Djot, compileDjot } from "react-djot";
45
45
 
46
46
  <Djot
47
47
  children={"# Title"}
@@ -51,15 +51,22 @@ import { Djot } from "react-djot";
51
51
  }
52
52
  }
53
53
  />;
54
+
55
+ const ast = compileDjot("# Precompiled");
56
+ <Djot ast={ast} />;
54
57
  ```
55
58
 
56
59
  Props:
57
60
 
58
61
  - `children?: string | null | undefined`
59
62
  - Djot source text to parse and render.
63
+ - `ast?: DjotNode`
64
+ - Precompiled Djot AST to render directly (bypasses parsing).
60
65
  - `components?: DjotComponents`
61
66
  - Optional map of node-tag keys to React components.
62
67
 
68
+ `children` and `ast` are mutually exclusive. Use one or the other.
69
+
63
70
  ### `components` overrides
64
71
 
65
72
  The override pattern mirrors `react-markdown`: provide a component per node
@@ -99,6 +106,11 @@ export function Example() {
99
106
 
100
107
  - `doc`
101
108
  - `section`
109
+ - `div`
110
+ - `table`
111
+ - `caption`
112
+ - `row`
113
+ - `cell`
102
114
  - `para`
103
115
  - `heading`
104
116
  - `emph`
@@ -106,17 +118,40 @@ export function Example() {
106
118
  - `mark` and `highlighted`
107
119
  - `superscript` and `supe`
108
120
  - `subscript`
121
+ - `insert`
122
+ - `delete`
123
+ - `span`
124
+ - `footnote_reference`
125
+ - `footnote`
126
+ - `endnotes`
127
+ - `double_quoted`
128
+ - `single_quoted`
129
+ - `smart_punctuation`
130
+ - `symb`
131
+ - `inline_math`
132
+ - `display_math`
109
133
  - `code`
110
134
  - `verbatim`
111
135
  - `code_block`
136
+ - `raw_block`
137
+ - `raw_inline`
138
+ - `url`
139
+ - `email`
112
140
  - `link`
113
141
  - `image`
114
142
  - `bullet_list`
115
143
  - `ordered_list`
116
144
  - `list_item`
145
+ - `definition_list`
146
+ - `definition_list_item`
147
+ - `term`
148
+ - `definition`
149
+ - `task_list`
150
+ - `task_list_item`
117
151
  - `blockquote` and `block_quote`
118
152
  - `thematic_break`
119
153
  - `str`
154
+ - `non_breaking_space`
120
155
  - `soft_break` and `softbreak`
121
156
  - `hard_break` and `hardbreak`
122
157
 
@@ -126,6 +161,110 @@ export function Example() {
126
161
  - Walks the AST recursively and creates React elements directly
127
162
  - Does not use `dangerouslySetInnerHTML`
128
163
 
164
+ ## Raw HTML
165
+
166
+ Djot raw blocks and raw inlines are supported:
167
+
168
+ - Block: `~~~=html ... ~~~`
169
+ - Inline: `` `...`{=html} ``
170
+
171
+ Only `html` format is rendered by default. Other formats are ignored unless you
172
+ provide a `components.raw_block` or `components.raw_inline` override.
173
+
174
+ ## Autolinks
175
+
176
+ Autolink nodes are supported:
177
+
178
+ - `<https://pandoc.org/lua-filters>` -> `<a href="https://pandoc.org/lua-filters">...`
179
+ - `<me@example.com>` -> `<a href="mailto:me@example.com">...`
180
+
181
+ ## Reference Links and Images
182
+
183
+ Reference-style links and images resolve against document references:
184
+
185
+ ```djot
186
+ [foo][bar]
187
+ ![logo][img]
188
+
189
+ [bar]: https://example.com
190
+ [img]: /logo.png
191
+ ```
192
+
193
+ ## Attributes
194
+
195
+ Inline and block attributes are propagated to default rendered elements.
196
+ Parser-generated `autoAttributes` are also applied, and explicit attributes
197
+ take precedence on conflicts.
198
+
199
+ For nodes with built-in classes (for example `task_list`, `inline_math`,
200
+ `display_math`), user classes are merged with default classes.
201
+
202
+ ## Symbols
203
+
204
+ Djot symbols (`:alias:`) render literally by default. You can provide a
205
+ `components.symb` override to map aliases to emojis or any custom output.
206
+
207
+ ## Task Lists
208
+
209
+ A bullet list item starting with `[ ]` (unchecked) or `[x]`/`[X]` (checked)
210
+ is a task list item:
211
+
212
+ ```djot
213
+ - [ ] unchecked item
214
+ - [x] checked item
215
+ ```
216
+
217
+ By default, task list items render as `<li>` elements with a disabled
218
+ `<input type="checkbox">` prepended to the content. Use the `task_list` and
219
+ `task_list_item` override keys to customise this rendering:
220
+
221
+ ```tsx
222
+ const components: DjotComponents = {
223
+ task_list_item: ({ checkbox, children }) => (
224
+ <li data-checked={checkbox === "checked"}>{children}</li>
225
+ )
226
+ };
227
+ ```
228
+
229
+ Tight task lists (no blank lines between items) render item text inline with
230
+ the checkbox. Loose task lists preserve paragraph wrappers (`<p>...</p>`)
231
+ inside each item.
232
+
233
+ Styling note: browsers apply default list markers to `<ul>/<li>`. To match
234
+ Djot playground output (checkboxes without bullet dots), reset task-list
235
+ styles in your app CSS:
236
+
237
+ ```css
238
+ .task-list {
239
+ list-style: none;
240
+ padding-left: 0;
241
+ }
242
+
243
+ .task-list li {
244
+ list-style: none;
245
+ }
246
+
247
+ .task-list input[type="checkbox"] {
248
+ margin-right: 0.45rem;
249
+ }
250
+ ```
251
+
252
+ ## Definition Lists
253
+
254
+ Definition list items are supported and render to semantic `<dl>/<dt>/<dd>`
255
+ elements:
256
+
257
+ ```djot
258
+ : orange
259
+
260
+ A citrus fruit.
261
+ ```
262
+
263
+ ## Non-breaking Spaces
264
+
265
+ An escaped space (`\ `) is parsed as `non_breaking_space` and renders as a
266
+ non-breaking space character.
267
+
129
268
  ## React Server Components
130
269
 
131
270
  `<Djot />` has no hooks in the main render path, so it can be used in Server
@@ -140,6 +279,17 @@ npm run lint
140
279
  npm test
141
280
  ```
142
281
 
282
+ ## Demo App
283
+
284
+ A React + Vite demo app lives in `examples/react-djot-demo`.
285
+
286
+ ```bash
287
+ npm run build
288
+ cd examples/react-djot-demo
289
+ npm install
290
+ npm run dev
291
+ ```
292
+
143
293
  ## License
144
294
 
145
295
  MIT