@willwang-io/react-djot 0.1.5 → 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
@@ -113,25 +120,38 @@ export function Example() {
113
120
  - `subscript`
114
121
  - `insert`
115
122
  - `delete`
123
+ - `span`
116
124
  - `footnote_reference`
117
125
  - `footnote`
118
126
  - `endnotes`
119
127
  - `double_quoted`
120
128
  - `single_quoted`
121
129
  - `smart_punctuation`
130
+ - `symb`
122
131
  - `inline_math`
123
132
  - `display_math`
124
133
  - `code`
125
134
  - `verbatim`
126
135
  - `code_block`
136
+ - `raw_block`
137
+ - `raw_inline`
138
+ - `url`
139
+ - `email`
127
140
  - `link`
128
141
  - `image`
129
142
  - `bullet_list`
130
143
  - `ordered_list`
131
144
  - `list_item`
145
+ - `definition_list`
146
+ - `definition_list_item`
147
+ - `term`
148
+ - `definition`
149
+ - `task_list`
150
+ - `task_list_item`
132
151
  - `blockquote` and `block_quote`
133
152
  - `thematic_break`
134
153
  - `str`
154
+ - `non_breaking_space`
135
155
  - `soft_break` and `softbreak`
136
156
  - `hard_break` and `hardbreak`
137
157
 
@@ -141,6 +161,110 @@ export function Example() {
141
161
  - Walks the AST recursively and creates React elements directly
142
162
  - Does not use `dangerouslySetInnerHTML`
143
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
+
144
268
  ## React Server Components
145
269
 
146
270
  `<Djot />` has no hooks in the main render path, so it can be used in Server