reactive-md 0.5.3 → 0.6.1
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/CHANGELOG-ch.md +195 -165
- package/CHANGELOG.md +195 -165
- package/CONTRIBUTING-ch.md +67 -62
- package/CONTRIBUTING.md +69 -64
- package/README-ch.md +157 -155
- package/README-en.md +184 -181
- package/README.md +184 -181
- package/SECURITY-ch.md +81 -81
- package/SECURITY.md +81 -81
- package/THIRD_PARTY_NOTICES.md +585 -1
- package/bin/reactive-md.mjs +39 -39
- package/cli/args.mjs +181 -181
- package/cli/assets.mjs +390 -390
- package/cli/build.mjs +268 -268
- package/cli/document.mjs +130 -130
- package/cli/errors.mjs +61 -61
- package/cli/fs-utils.mjs +133 -133
- package/cli/glob.mjs +203 -203
- package/cli/help.mjs +138 -138
- package/cli/lint.mjs +177 -177
- package/cli/main.mjs +55 -55
- package/cli/migrate.mjs +368 -368
- package/cli/package.mjs +210 -210
- package/dist-library/{authoring-DJJjKYg9.js → authoring-BEVyth5X.js} +58 -58
- package/dist-library/compiler-Cm3ppMxG.js +46044 -0
- package/dist-library/react-Bh7_oxZp.js +59655 -0
- package/dist-library/reactive-md-authoring.js +2 -2
- package/dist-library/reactive-md-editor.js +13 -0
- package/dist-library/reactive-md-print.css +284 -284
- package/dist-library/reactive-md-react-unstyled.js +1 -1
- package/dist-library/reactive-md-react.js +1 -1
- package/dist-library/reactive-md.css +1 -1
- package/dist-library/reactive-md.js +123 -123
- package/dist-library/{runtime-DXtle_6c.js → runtime-DlFYQ4s_.js} +151 -151
- package/dist-library/types/editor/types.d.ts +2 -0
- package/dist-library/types/local/code-block.d.ts +3 -1
- package/dist-library/types/local/code-languages.d.ts +7 -0
- package/dist-library/types/local/compiled-data.d.ts +6 -0
- package/dist-library/types/local/compiler.d.ts +1 -0
- package/dist-library/types/local/diagnostics.d.ts +31 -0
- package/dist-library/types/local/diagram-layout.d.ts +69 -0
- package/dist-library/types/local/html-names.d.ts +6 -0
- package/dist-library/types/local/html-table.d.ts +25 -0
- package/dist-library/types/local/math-display.d.ts +22 -22
- package/dist-library/types/local/math-view.d.ts +6 -7
- package/dist-library/types/local/table-surface.d.ts +10 -0
- package/dist-library/types/local/types.d.ts +2 -0
- package/dist-library/types/local/visuals.d.ts +9 -0
- package/dist-standalone/reactive-md-standalone.css +1 -1
- package/dist-standalone/reactive-md-standalone.js +331 -51
- package/docs/README.md +84 -0
- package/docs/{compatibility-ch.md → compatibility/compatibility-ch.md} +121 -109
- package/docs/{compatibility-en.md → compatibility/compatibility-en.md} +121 -109
- package/docs/{source-versioning-ch.md → compatibility/source-versioning-ch.md} +159 -159
- package/docs/{source-versioning-en.md → compatibility/source-versioning-en.md} +159 -159
- package/docs/{component-development-ch.md → development/component-development-ch.md} +210 -210
- package/docs/{component-development-en.md → development/component-development-en.md} +210 -210
- package/docs/{component-protocol-ch.md → development/component-protocol-ch.md} +747 -747
- package/docs/{component-protocol-en.md → development/component-protocol-en.md} +747 -747
- package/docs/{performance-ch.md → development/performance-ch.md} +76 -76
- package/docs/{performance-en.md → development/performance-en.md} +76 -76
- package/docs/{releasing-ch.md → development/releasing-ch.md} +108 -108
- package/docs/{releasing-en.md → development/releasing-en.md} +108 -108
- package/docs/guides/local-guide-ch.md +513 -0
- package/docs/guides/local-guide-en.md +513 -0
- package/docs/{author-tools-ch.md → integration/author-tools-ch.md} +57 -57
- package/docs/{author-tools-en.md → integration/author-tools-en.md} +57 -57
- package/docs/{editor-ch.md → integration/editor-ch.md} +7 -6
- package/docs/{editor-en.md → integration/editor-en.md} +7 -6
- package/docs/{local-integration-ch.md → integration/local-integration-ch.md} +33 -15
- package/docs/{local-integration-en.md → integration/local-integration-en.md} +33 -15
- package/docs/{shareable-export-ch.md → integration/shareable-export-ch.md} +221 -209
- package/docs/{shareable-export-en.md → integration/shareable-export-en.md} +223 -211
- package/docs/{computations-formatting-ch.md → reference/computations-formatting-ch.md} +87 -87
- package/docs/{computations-formatting-en.md → reference/computations-formatting-en.md} +87 -87
- package/docs/{constraints-collections-ch.md → reference/constraints-collections-ch.md} +84 -84
- package/docs/{constraints-collections-en.md → reference/constraints-collections-en.md} +84 -84
- package/docs/{diagnostics-counting-ch.md → reference/diagnostics-counting-ch.md} +104 -84
- package/docs/{diagnostics-counting-en.md → reference/diagnostics-counting-en.md} +104 -84
- package/docs/{html-compatibility-ch.md → reference/html-compatibility-ch.md} +42 -4
- package/docs/{html-compatibility-en.md → reference/html-compatibility-en.md} +42 -4
- package/docs/{local-components-v2-ch.md → reference/local-components-v2-ch.md} +138 -138
- package/docs/{local-components-v2-en.md → reference/local-components-v2-en.md} +104 -104
- package/docs/{local-interaction-syntax-ch.md → reference/local-interaction-syntax-ch.md} +515 -492
- package/docs/{local-interaction-syntax-en.md → reference/local-interaction-syntax-en.md} +511 -488
- package/docs/{theme-protocol-ch.md → reference/theme-protocol-ch.md} +107 -107
- package/docs/{theme-protocol-en.md → reference/theme-protocol-en.md} +107 -107
- package/docs/{release-0.4.0-ch.md → releases/release-0.4.0-ch.md} +89 -89
- package/docs/{release-0.4.0-en.md → releases/release-0.4.0-en.md} +89 -89
- package/docs/{release-0.4.1-ch.md → releases/release-0.4.1-ch.md} +23 -23
- package/docs/{release-0.4.1-en.md → releases/release-0.4.1-en.md} +23 -23
- package/docs/{release-0.5.0-ch.md → releases/release-0.5.0-ch.md} +4 -4
- package/docs/{release-0.5.0-en.md → releases/release-0.5.0-en.md} +4 -4
- package/docs/{release-0.5.1-ch.md → releases/release-0.5.1-ch.md} +4 -4
- package/docs/{release-0.5.1-en.md → releases/release-0.5.1-en.md} +4 -4
- package/docs/{release-0.5.2-ch.md → releases/release-0.5.2-ch.md} +3 -3
- package/docs/{release-0.5.2-en.md → releases/release-0.5.2-en.md} +3 -3
- package/docs/{release-0.5.3-ch.md → releases/release-0.5.3-ch.md} +1 -1
- package/docs/{release-0.5.3-en.md → releases/release-0.5.3-en.md} +1 -1
- package/docs/releases/release-0.6.0-ch.md +57 -0
- package/docs/releases/release-0.6.0-en.md +57 -0
- package/docs/releases/release-0.6.1-ch.md +27 -0
- package/docs/releases/release-0.6.1-en.md +27 -0
- package/examples/conformance/README.md +53 -53
- package/examples/conformance/component-protocol-1.json +482 -482
- package/examples/conformance/component-protocol-1.schema.json +76 -76
- package/examples/conformance/local-draft-1.json +50 -50
- package/examples/conformance/local-draft-2.json +212 -212
- package/examples/integration/README.md +47 -45
- package/examples/integration/core/index.mjs +32 -32
- package/examples/integration/worker/index.html +19 -19
- package/examples/integration/worker/main.js +61 -61
- package/examples/integration/worker/package.json +13 -13
- package/examples/integration/worker/worker.js +3 -3
- package/examples/local/README.md +74 -74
- package/examples/local/charts.reactive.md +73 -73
- package/examples/local/html-compat.reactive.md +19 -0
- package/examples/local/recipes/invoice-zh.reactive.md +36 -36
- package/examples/local/recipes/invoice.reactive.md +36 -36
- package/examples/local/recipes/workshop-zh.reactive.md +33 -33
- package/examples/local/recipes/workshop.reactive.md +33 -33
- package/examples/local/showcase/README.md +25 -25
- package/examples/local/showcase/explore.reactive.md +102 -102
- package/examples/local/showcase/flow.reactive.md +86 -86
- package/examples/local/showcase/forms.reactive.md +126 -126
- package/examples/local/showcase/functions.reactive.md +119 -119
- package/examples/local/showcase/layout.reactive.md +100 -100
- package/examples/local/showcase/statistics.reactive.md +108 -108
- package/examples/local/showcase/tasks.reactive.md +89 -89
- package/examples/local/showcase/zh/explore.reactive.md +102 -102
- package/examples/local/showcase/zh/flow.reactive.md +86 -86
- package/examples/local/showcase/zh/forms.reactive.md +126 -126
- package/examples/local/showcase/zh/functions.reactive.md +119 -119
- package/examples/local/showcase/zh/layout.reactive.md +100 -100
- package/examples/local/showcase/zh/statistics.reactive.md +108 -108
- package/examples/local/showcase/zh/tasks.reactive.md +89 -89
- package/package.json +152 -145
- package/dist-library/compiler-UyPwGzJZ.js +0 -22109
- package/dist-library/react-fizgU3i8.js +0 -12764
- package/docs/local-guide-ch.md +0 -967
- package/docs/local-guide-en.md +0 -967
package/docs/local-guide-en.md
DELETED
|
@@ -1,967 +0,0 @@
|
|
|
1
|
-
# Reactive MD beginner guide
|
|
2
|
-
|
|
3
|
-
This guide is for readers who know Markdown and have seen a little HTML but have not used Reactive MD. By the end, you should be able to write local interactive documents with input controls, live calculations, conditional content, charts and diagrams on your own.
|
|
4
|
-
|
|
5
|
-
This document covers the `local-draft-2` local interaction syntax. See the [local interaction syntax specification](local-interaction-syntax-en.md) for complete rules and the [example directory](../examples/local/README.md) for complete documents you can run directly. The specification is the authoritative source for more complete component and expression details. See [Versions and compatibility](compatibility-en.md) for package versions, syntax revisions and migration rules.
|
|
6
|
-
|
|
7
|
-
## Table of contents
|
|
8
|
-
|
|
9
|
-
For reusable intermediate results and formatted output, see [Reusing calculations and formatting values](computations-formatting-en.md), with a complete invoice example.
|
|
10
|
-
|
|
11
|
-
- [1. Build intuition first](#1-build-intuition-first)
|
|
12
|
-
- [2. Five minutes: your first interactive document](#2-five-minutes-your-first-interactive-document)
|
|
13
|
-
- [3. How to write tags](#3-how-to-write-tags)
|
|
14
|
-
- [4. Parameters: name with bind, set initial values with initial](#4-parameters-name-with-bind-set-initial-values-with-initial)
|
|
15
|
-
- [5. Common input controls](#5-common-input-controls)
|
|
16
|
-
- [6. Expressions: make text follow parameters](#6-expressions-make-text-follow-parameters)
|
|
17
|
-
- [7. Conditions and content organization](#7-conditions-and-content-organization)
|
|
18
|
-
- [8. Checklists, progress, timers and timelines](#8-checklists-progress-timers-and-timelines)
|
|
19
|
-
- [9. Tables and charts](#9-tables-and-charts)
|
|
20
|
-
- [10. Diagrams and function curves](#10-diagrams-and-function-curves)
|
|
21
|
-
- [11. Common errors at a glance](#11-common-errors-at-a-glance)
|
|
22
|
-
- [12. Complete exercise: workshop signup page](#12-complete-exercise-workshop-signup-page)
|
|
23
|
-
- [13. Next steps](#13-next-steps)
|
|
24
|
-
- [Appendix A: Component reference](#appendix-a-component-reference)
|
|
25
|
-
|
|
26
|
-
## 1. Build intuition first
|
|
27
|
-
|
|
28
|
-
### 1.1 What problem does it solve
|
|
29
|
-
|
|
30
|
-
Plain Markdown produces fixed content. Reactive MD adds one thing on top: readers can change parameters, and prose, formulas, tables, charts and diagrams update immediately.
|
|
31
|
-
|
|
32
|
-
For example, take a fixed sentence:
|
|
33
|
-
|
|
34
|
-
```markdown
|
|
35
|
-
People: 3. At 100 USD each, the total is 300 USD.
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
Turn it into an adjustable version:
|
|
39
|
-
|
|
40
|
-
```markdown
|
|
41
|
-
<slider bind="people" label="People" initial="3" min="1" max="20">
|
|
42
|
-
|
|
43
|
-
People: **{{ people }}**. At 100 USD each, the total is **{{ people * 100 }} USD**.
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
The reader drags the slider and both numbers update together. The document author wrote no JavaScript and no CSS.
|
|
47
|
-
|
|
48
|
-
### 1.2 How it maps to Markdown and HTML
|
|
49
|
-
|
|
50
|
-
You can think of Reactive MD as Markdown prose plus a small fixed set of HTML-style tags plus template expressions.
|
|
51
|
-
|
|
52
|
-
| What you already know | In Reactive MD |
|
|
53
|
-
| --- | --- |
|
|
54
|
-
| Markdown headings, paragraphs, lists, quotes, links, images | Used as-is |
|
|
55
|
-
| Markdown tables | Used as-is; you can also put them in `<table>` for search and sorting |
|
|
56
|
-
| HTML tags | Use component tags and attribute-free `<b>`, `<i>`, `<u>`, `<s>`, `<mark>` and `<br>` |
|
|
57
|
-
| HTML attributes | Write `label="People"`, lowercase attribute names, quoted values |
|
|
58
|
-
| JavaScript variables | Name controls with `bind="people"` |
|
|
59
|
-
| Template strings `${...}` | Read and compute with `{{ people * 100 }}` |
|
|
60
|
-
| `onclick` events | Not supported; components provide the interactions they need |
|
|
61
|
-
| `class`, `style`, `<script>` | Not supported; components provide styling |
|
|
62
|
-
|
|
63
|
-
### 1.3 Data flow in three steps
|
|
64
|
-
|
|
65
|
-
1. **Declare**: input controls name a parameter with `bind` and give an initial value with `initial`.
|
|
66
|
-
2. **Read**: `{{ expression }}` in prose, tables or attributes reads parameters and computes values.
|
|
67
|
-
3. **Update**: when the reader operates a control, every place that reads that parameter refreshes automatically.
|
|
68
|
-
|
|
69
|
-
Remember the two connection rules, `bind` and `{{ }}`; every other component builds layout, selection, search, timing and similar capabilities on top of them.
|
|
70
|
-
|
|
71
|
-
## 2. Five minutes: your first interactive document
|
|
72
|
-
|
|
73
|
-
### 2.1 Complete example
|
|
74
|
-
|
|
75
|
-
Paste the following into the Playground:
|
|
76
|
-
|
|
77
|
-
```markdown
|
|
78
|
-
# Cost estimate
|
|
79
|
-
|
|
80
|
-
<panel title="Adjust the plan">
|
|
81
|
-
<slider bind="people" label="People" initial="2" min="1" max="20">
|
|
82
|
-
<toggle bind="annual" label="Annual billing">
|
|
83
|
-
</panel>
|
|
84
|
-
|
|
85
|
-
People: **{{ people }}**.
|
|
86
|
-
|
|
87
|
-
Monthly cost: **{{ people * (annual ? 80 : 100) }} USD**.
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
Line by line:
|
|
91
|
-
|
|
92
|
-
- `<panel>` is a paired tag that wraps a group of related controls and includes a restore-defaults button.
|
|
93
|
-
- `<slider>` is a void tag and does not need `</slider>`.
|
|
94
|
-
- `bind="people"` declares a numeric parameter `people`.
|
|
95
|
-
- `initial="2"` is the initial value. `min` and `max` are the slider range.
|
|
96
|
-
- `<toggle>` declares the boolean parameter `annual`; when `initial` is omitted it defaults to off.
|
|
97
|
-
- `{{ people }}` displays the current count, and `{{ people * (annual ? 80 : 100) }}` computes the monthly cost.
|
|
98
|
-
- `annual ? 80 : 100` is a conditional expression: annual billing takes 80, otherwise 100.
|
|
99
|
-
|
|
100
|
-
Click restore-defaults in the panel and both the count and the toggle return to their initial values.
|
|
101
|
-
|
|
102
|
-
### 2.2 Run and modify
|
|
103
|
-
|
|
104
|
-
In the repository root, run:
|
|
105
|
-
|
|
106
|
-
```sh
|
|
107
|
-
npm run dev
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
Open `http://127.0.0.1:5173` in a browser; edit Markdown on the left and see a live preview on the right. You can also open the online demo at [yaozi.raricy.com](https://yaozi.raricy.com/).
|
|
111
|
-
|
|
112
|
-
A good start is to copy a short document from the [example directory](../examples/local/README.md) into the editor, change a number or some text, watch the right side, and then come back to the following sections.
|
|
113
|
-
|
|
114
|
-
### 2.3 Small widgets without shared parameters
|
|
115
|
-
|
|
116
|
-
If a control does not need to be read by the prose, you can omit `bind` entirely:
|
|
117
|
-
|
|
118
|
-
```markdown
|
|
119
|
-
<counter label="People" initial="2" min="1" max="20">
|
|
120
|
-
|
|
121
|
-
<timer label="One-minute focus" duration="60">
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
They remain interactive; they just have no public variable. This suits standalone tools such as a people counter or a focus timer.
|
|
125
|
-
|
|
126
|
-
## 3. How to write tags
|
|
127
|
-
|
|
128
|
-
### 3.1 Two tag shapes
|
|
129
|
-
|
|
130
|
-
| Shape | Form | Rules |
|
|
131
|
-
| --- | --- | --- |
|
|
132
|
-
| Void component | `<slider bind="a" label="Amplitude">` | No end tag; `<slider ... />` is also accepted |
|
|
133
|
-
| Container with content | `<card title="Notes">` and `</card>` | Must be closed explicitly; nesting is allowed |
|
|
134
|
-
|
|
135
|
-
Void components are fixed to:
|
|
136
|
-
|
|
137
|
-
`input`, `textarea`, `number`, `slider`, `range-slider`, `coordinate`, `toggle`, `checkbox`, `date`, `counter`, `timer`, `progress`, `anchor`, `edge`. The declaration tags `computed`, `const` and `validation`, and the structural `column`, also have no body.
|
|
138
|
-
|
|
139
|
-
All other components use paired tags. In particular, `textarea` text is set through `initial`, so it has no body; do not write `<textarea>content</textarea>`.
|
|
140
|
-
|
|
141
|
-
Containers with content can nest Markdown and other components:
|
|
142
|
-
|
|
143
|
-
```markdown
|
|
144
|
-
<card title="Plan notes">
|
|
145
|
-
Price updates with **People**.
|
|
146
|
-
|
|
147
|
-
<slider bind="people" label="People" initial="2" min="1" max="20">
|
|
148
|
-
|
|
149
|
-
Total cost: {{ people * 100 }} USD.
|
|
150
|
-
</card>
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
Tags can span lines, and attributes can be split across lines:
|
|
154
|
-
|
|
155
|
-
```markdown
|
|
156
|
-
<slider
|
|
157
|
-
bind="people"
|
|
158
|
-
label="People"
|
|
159
|
-
initial="2"
|
|
160
|
-
min="1"
|
|
161
|
-
max="20">
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
### 3.2 Attribute rules
|
|
165
|
-
|
|
166
|
-
- Tag and attribute names use lowercase kebab-case, for example `<radio-group>`, `page-size="5"`.
|
|
167
|
-
- Attribute values are enclosed in double or single quotes.
|
|
168
|
-
- Attribute order has no meaning; writing the same attribute twice is an error.
|
|
169
|
-
- Boolean attributes may omit their value, for example `required` means `true`.
|
|
170
|
-
- Boolean values can also be written explicitly as `required="false"`.
|
|
171
|
-
- Attribute values may contain `>`; as long as it is inside quotes, it does not end the tag early.
|
|
172
|
-
- `"`, `'`, `&`, `<` and `>` in attribute values decode to the corresponding characters.
|
|
173
|
-
|
|
174
|
-
Dynamic attributes come in two kinds:
|
|
175
|
-
|
|
176
|
-
```markdown
|
|
177
|
-
<!-- Text attributes can mix plain text and interpolation -->
|
|
178
|
-
<toggle bind="locked" label="Lock people count">
|
|
179
|
-
<slider bind="people" label="Current people: {{ people }}" disabled="{{ locked }}">
|
|
180
|
-
|
|
181
|
-
<!-- Conditions must be a complete boolean interpolation -->
|
|
182
|
-
<if when="{{ people >= 5 }}">
|
|
183
|
-
The group has reached 5 people.
|
|
184
|
-
</if>
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
Structural attributes such as `bind`, `initial`, `id`, `value`, `from`, `to` and `kind` must be static text and cannot contain interpolation.
|
|
188
|
-
|
|
189
|
-
### 3.3 Markdown is still in charge
|
|
190
|
-
|
|
191
|
-
Container contents continue to parse as Markdown; no extra `markdown` attribute is needed. Headings, emphasis, links, images, quotes, lists, plain tables, inline code and code fences all work as usual.
|
|
192
|
-
|
|
193
|
-
```markdown
|
|
194
|
-
<card title="References">
|
|
195
|
-
- [Markdown guide](https://commonmark.org/help/)
|
|
196
|
-
- Image:  (replace the path with your own image)
|
|
197
|
-
|
|
198
|
-
> Quotes can also go inside cards.
|
|
199
|
-
</card>
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
Tags, interpolations and formula markers inside code fences are displayed verbatim and do not create controls:
|
|
203
|
-
|
|
204
|
-
````markdown
|
|
205
|
-
```markdown
|
|
206
|
-
<slider bind="example" label="Example">
|
|
207
|
-
Current value: {{ example }}.
|
|
208
|
-
```
|
|
209
|
-
````
|
|
210
|
-
|
|
211
|
-
HTML comments `<!-- ... -->` are ignored and produce no components or variables. Prose supports attribute-free `<b>bold</b>`, `<i>italic</i>`, `<u>underline</u>`, `<s>strikethrough</s>`, `<mark>highlight</mark>` and `<br>` (also `<br/>`), including nested formatting. Use Markdown or the matching components for other content. Structurally complete unknown tags are kept as source text with a warning, including their inner tags and interpolations. Event and `style` attributes gain no execution capability.
|
|
212
|
-
|
|
213
|
-
Generics such as `Array<T>`, comparisons such as `x<y` and currency such as `$5` and `$10` can appear directly in prose. Formulas still use `$x^2$`, `$5$` or `$$...$$`. A single newline remains a Markdown soft break; use two trailing spaces or `<br>` for a hard break.
|
|
214
|
-
|
|
215
|
-
Use `text[^note]` to reference a footnote and `[^note]: Note text` in a separate paragraph to define it. Definitions support Markdown, the basic HTML above, and indented continuation paragraphs, lists and code blocks. Notes appear at the end in first-reference order. Repeated references share a number, with return links to each occurrence. Definitions may precede references or appear inside containers. Undefined references stay literal, and unused definitions stay hidden. Control tags and `{{ interpolations }}` inside definitions remain text and create no bindings.
|
|
216
|
-
|
|
217
|
-
Tables of contents use ordinary Markdown links: `[Parameter description](#parameter-description)` corresponds to `## Parameter description`. English headings are named in lowercase with hyphens, for example `## Hello World` corresponds to `#hello-world`; duplicate headings get `-1`, `-2` appended. Dynamic text in headings generates anchors from initial parameter values, so the table of contents keeps pointing at the same heading after parameters change. The renderer isolates anchors for different documents on the same page, so no prefix is needed in the source.
|
|
218
|
-
|
|
219
|
-
Indentation only affects readability: container content is dedented by the common indentation before parsing; indentation inside code fences is preserved. Plain prose is best left unindented.
|
|
220
|
-
|
|
221
|
-
Code fences with a language name, such as `js`, `ts`, `python`, `json`, `bash`, `html` or `css`, receive syntax highlighting. The copy button copies the exact code, including whitespace. Unrecognized languages and blocks longer than 20,000 characters stay plain. Static rendering retains highlighting and omits copy controls; printing hides the code toolbar.
|
|
222
|
-
|
|
223
|
-
Images approved by the host's `urlPolicy` open in a modal viewer on click, Enter or Space. Use the close button, Escape or the backdrop to return to the original image. Linked images keep their link destination. See [host integration](local-integration-en.md) for the image allowlist.
|
|
224
|
-
|
|
225
|
-
### 3.4 Key differences from HTML
|
|
226
|
-
|
|
227
|
-
| HTML habit | Reactive MD approach |
|
|
228
|
-
| --- | --- |
|
|
229
|
-
| `<div>` wrapping a block | Use `<card>` or `<panel>` |
|
|
230
|
-
| `<input type="range">` | Use `<slider>` |
|
|
231
|
-
| `<input type="checkbox">` | Use `<checkbox>` or `<toggle>` |
|
|
232
|
-
| `<select>` + `<option>` | Use `<select>`, `<choices>` or `<radio-group>` + `<option>` |
|
|
233
|
-
| `onclick="..."` | Event attributes are not supported; components provide interactions |
|
|
234
|
-
| `class="..."`, `style="..."` | Author styles are not supported |
|
|
235
|
-
| `<script>`, `<style>` | Not supported |
|
|
236
|
-
| JavaScript variables | Declare parameters with `bind` |
|
|
237
|
-
| Template strings | Use `{{ expression }}` |
|
|
238
|
-
| Elements can self-close or tolerate errors | Paired tags must close strictly; mismatches produce diagnostics |
|
|
239
|
-
|
|
240
|
-
In one sentence: tags are only the outward shape of components, not HTML you can freely extend.
|
|
241
|
-
|
|
242
|
-
## 4. Parameters: name with bind, set initial values with initial
|
|
243
|
-
|
|
244
|
-
### 4.1 Naming rules
|
|
245
|
-
|
|
246
|
-
`bind` values must match `[A-Za-z_][A-Za-z0-9_]*` and are case-sensitive. Prefer meaningful English names, for example `people`, `annual`, `budgetLevel`.
|
|
247
|
-
|
|
248
|
-
The following names cannot be used as parameter names:
|
|
249
|
-
|
|
250
|
-
- Plot reserved names: `x`, `y`
|
|
251
|
-
- Constants: `pi`, `e`
|
|
252
|
-
- Literals: `true`, `false`, `null`
|
|
253
|
-
- Expression function names: `abs`, `sqrt`, `round`, `min`, `max`, `len`, `contains` and so on
|
|
254
|
-
|
|
255
|
-
Chinese cannot be used directly as a `bind` name. Put display text in `label` instead.
|
|
256
|
-
|
|
257
|
-
### 4.2 Types and defaults
|
|
258
|
-
|
|
259
|
-
Parameter types are determined by the component, not guessed from input text.
|
|
260
|
-
|
|
261
|
-
| Component | Public value | Initial value when initial is omitted |
|
|
262
|
-
| --- | --- | --- |
|
|
263
|
-
| `input`, `textarea` | String | Empty string |
|
|
264
|
-
| `date` | Date string | Empty string |
|
|
265
|
-
| `number` | Number | The valid step value within range closest to 0 |
|
|
266
|
-
| `slider` | Number | `min`, with a default range of 0 to 100 |
|
|
267
|
-
| `counter` | Number | The valid step value within range closest to 0 |
|
|
268
|
-
| `toggle`, `checkbox` | Boolean | `false` |
|
|
269
|
-
| `select`, `choices`, `radio-group` | Option string | value of the first option |
|
|
270
|
-
| `multi-select` | String array of selected option values | Empty array |
|
|
271
|
-
| `range-slider` | Two numbers, `start` / `end` | start=min; end=the largest valid step within max |
|
|
272
|
-
| `coordinate` | Two numbers, `x` / `y` | The valid step closest to 0 on each axis |
|
|
273
|
-
| `table`, `chart` with `key` | Stable row key string | Empty string (unselected) |
|
|
274
|
-
| `tabs` | Page string | value of the first tab |
|
|
275
|
-
| `steps` | Step string | value of the first step |
|
|
276
|
-
| `diagram` | Node ID string | id of the first node |
|
|
277
|
-
| `checklist` | String array of checked item IDs | Determined by the task list check marks |
|
|
278
|
-
| `timer` | Remaining seconds | `duration`, default 60 |
|
|
279
|
-
|
|
280
|
-
### 4.3 Three rules for initial
|
|
281
|
-
|
|
282
|
-
1. A parameter has at most one explicit `initial`. When several controls share a variable, write it on only one of them.
|
|
283
|
-
2. `initial` must be a static value and cannot contain `{{ }}`.
|
|
284
|
-
3. The initial value must satisfy the component constraints. Numbers must be between `min` and `max` and land on a step; selector initial values must be the value of an existing option; dates must be valid `YYYY-MM-DD`.
|
|
285
|
-
|
|
286
|
-
`timer` uses `duration` for its length, and `checklist` uses the `[x]` marks in its task list for initial state; neither accepts `initial`.
|
|
287
|
-
|
|
288
|
-
### 4.4 One variable, several controls
|
|
289
|
-
|
|
290
|
-
Controls of the same kind can bind the same variable and stay in sync:
|
|
291
|
-
|
|
292
|
-
```markdown
|
|
293
|
-
<slider bind="people" label="People" initial="2" min="1" max="20">
|
|
294
|
-
<number bind="people" label="Exact count" min="1" max="20" step="1">
|
|
295
|
-
|
|
296
|
-
Current people: {{ people }}.
|
|
297
|
-
```
|
|
298
|
-
|
|
299
|
-
Notes:
|
|
300
|
-
|
|
301
|
-
- Do not write `initial` on the second control.
|
|
302
|
-
- The numeric range and step must match on both controls.
|
|
303
|
-
- Different families such as text, number, boolean, date and choice cannot share a variable.
|
|
304
|
-
- When selectors share a variable, option values and order must be identical.
|
|
305
|
-
- The public state of `timer`, `checklist`, `tabs`, `diagram`, `multi-select` and `steps` can be owned by only one component and cannot be shared. Slots of `range-slider` and `coordinate` are exclusive too; a table and chart may share a selection binding only when their ordered `key` values match.
|
|
306
|
-
|
|
307
|
-
### 4.5 Components without bind
|
|
308
|
-
|
|
309
|
-
Without `bind`, a component keeps independent internal state, and the prose cannot read it. The control still needs `label`, because label is also its accessible name.
|
|
310
|
-
|
|
311
|
-
```markdown
|
|
312
|
-
<counter label="Participants" initial="2" min="1" max="20">
|
|
313
|
-
```
|
|
314
|
-
|
|
315
|
-
If you later need to show the count in the prose, add `bind="count"` and read it with `{{ count }}`.
|
|
316
|
-
|
|
317
|
-
## 5. Common input controls
|
|
318
|
-
|
|
319
|
-
All input components support `label`, optional `bind`, optional `initial` and dynamic `disabled`. A control label is required.
|
|
320
|
-
|
|
321
|
-
### 5.1 Text and numbers
|
|
322
|
-
|
|
323
|
-
```markdown
|
|
324
|
-
<input bind="name" label="Name" placeholder="What should we call you?">
|
|
325
|
-
|
|
326
|
-
<textarea bind="message" label="Thoughts" placeholder="For example: a handout with adjustable parameters" rows="4">
|
|
327
|
-
|
|
328
|
-
<number bind="quantity" label="Quantity" initial="3" min="1" max="20" step="1">
|
|
329
|
-
|
|
330
|
-
<slider bind="budget" label="Budget tier" initial="50" min="0" max="100" step="10">
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
- `input` defaults to `type="text"` and also supports `type="email"`.
|
|
334
|
-
- `input` supports `required`, `min-length` and `max-length`.
|
|
335
|
-
- `textarea` initial text goes in `initial`, and the number of rows in `rows`.
|
|
336
|
-
- `number` has `step` default 1; `min` and `max` are optional.
|
|
337
|
-
- `slider` has a default range of 0 to 100 and a default step of 1.
|
|
338
|
-
|
|
339
|
-
### 5.2 Toggles and dates
|
|
340
|
-
|
|
341
|
-
```markdown
|
|
342
|
-
<toggle bind="annual" label="Annual billing">
|
|
343
|
-
|
|
344
|
-
<checkbox bind="express" label="Expedited service">
|
|
345
|
-
|
|
346
|
-
<date bind="appointment" label="Planned date" initial="2026-10-22">
|
|
347
|
-
```
|
|
348
|
-
|
|
349
|
-
`toggle` and `checkbox` both have boolean values; the difference is mainly appearance and use case. An empty date string means not yet selected.
|
|
350
|
-
|
|
351
|
-
### 5.3 Selectors
|
|
352
|
-
|
|
353
|
-
`select`, `choices` and `radio-group` are written the same way and differ only in appearance: dropdown, option cards and radio button group. Their bodies contain one or more `<option>` elements.
|
|
354
|
-
|
|
355
|
-
```markdown
|
|
356
|
-
<choices bind="plan" label="Plan">
|
|
357
|
-
<option value="basic">Basic</option>
|
|
358
|
-
<option value="pro">Pro</option>
|
|
359
|
-
</choices>
|
|
360
|
-
```
|
|
361
|
-
|
|
362
|
-
Rules:
|
|
363
|
-
|
|
364
|
-
- `option` must have a `value`, unique within the group.
|
|
365
|
-
- `value` is a static string and cannot contain interpolation.
|
|
366
|
-
- The option body is regular inline Markdown and can be bold, but cannot contain another interactive component.
|
|
367
|
-
- When `initial` is omitted, the first option is selected by default.
|
|
368
|
-
|
|
369
|
-
The bound value is the selected `value`, so prose usually tests it like this (assuming `plan` above is declared):
|
|
370
|
-
|
|
371
|
-
```markdown
|
|
372
|
-
Current plan: **{{ plan == 'pro' ? 'Pro' : 'Basic' }}**.
|
|
373
|
-
```
|
|
374
|
-
|
|
375
|
-
### 5.4 Compose a small form
|
|
376
|
-
|
|
377
|
-
```markdown
|
|
378
|
-
<panel title="Configure a plan">
|
|
379
|
-
<input bind="name" label="Name">
|
|
380
|
-
<number bind="quantity" label="Quantity" initial="3" min="1" max="20">
|
|
381
|
-
<choices bind="plan" label="Plan">
|
|
382
|
-
<option value="basic">Basic</option>
|
|
383
|
-
<option value="pro">Pro</option>
|
|
384
|
-
</choices>
|
|
385
|
-
<toggle bind="annual" label="Annual billing">
|
|
386
|
-
</panel>
|
|
387
|
-
|
|
388
|
-
Hello, **{{ name == '' ? 'friend' : name }}**.
|
|
389
|
-
|
|
390
|
-
Estimated cost: **{{ round(quantity * 80 * (plan == 'pro' ? 1 : 0.8) * (annual ? 0.8 : 1)) }} USD**.
|
|
391
|
-
```
|
|
392
|
-
|
|
393
|
-
This uses string comparison, a conditional expression and `round`. `name` starts as an empty string, so the first render shows "friend".
|
|
394
|
-
|
|
395
|
-
### 5.5 Input constraints and disabling
|
|
396
|
-
|
|
397
|
-
`required`, `min-length`, `max-length` and email format show hints after the first blur and update with input afterwards. Text with an invalid format stays as an editing draft but does not replace the last valid public value.
|
|
398
|
-
|
|
399
|
-
`disabled` can be controlled dynamically:
|
|
400
|
-
|
|
401
|
-
```markdown
|
|
402
|
-
<toggle bind="locked" label="Lock people count">
|
|
403
|
-
<slider bind="people" label="People" initial="2" min="1" max="20" disabled="{{ locked }}">
|
|
404
|
-
```
|
|
405
|
-
|
|
406
|
-
When `locked` is true, the slider does not accept reader input. A dynamic boolean attribute must be one complete `{{ }}`.
|
|
407
|
-
|
|
408
|
-
## 6. Expressions: make text follow parameters
|
|
409
|
-
|
|
410
|
-
### 6.1 Basic operations
|
|
411
|
-
|
|
412
|
-
Inside `{{ }}` is an expression, not JavaScript. It supports:
|
|
413
|
-
|
|
414
|
-
| Category | Form |
|
|
415
|
-
| --- | --- |
|
|
416
|
-
| Numbers, strings, booleans, null | `2`, `'text'`, `true`, `false`, `null` |
|
|
417
|
-
| Parameters | `people`, `annual` |
|
|
418
|
-
| Arithmetic | `+`, `-`, `*`, `/`, `%`, unary plus/minus, parentheses |
|
|
419
|
-
| Comparison | `==`, `!=`, `<`, `<=`, `>`, `>=` |
|
|
420
|
-
| Logic | `!`, `&&`, `\|\|` |
|
|
421
|
-
| Conditional | `condition ? trueValue : falseValue` |
|
|
422
|
-
| Functions | `round`, `min`, `max`, `sqrt`, `len` and so on |
|
|
423
|
-
| Constants | `pi`, `e` |
|
|
424
|
-
|
|
425
|
-
Examples (assuming `people`, `annual` and `price` are declared in the document):
|
|
426
|
-
|
|
427
|
-
```markdown
|
|
428
|
-
{{ people * 100 }}
|
|
429
|
-
{{ people >= 5 ? 'Team tier' : 'Individual tier' }}
|
|
430
|
-
{{ annual && people >= 3 }}
|
|
431
|
-
{{ round(price * 0.8 * 100) / 100 }}
|
|
432
|
-
```
|
|
433
|
-
|
|
434
|
-
Notes:
|
|
435
|
-
|
|
436
|
-
- Multiplication must be written `*`. `2x` is not multiplication in a prose expression.
|
|
437
|
-
- Use `pow(x, 2)` for exponents; `x^2` is not accepted.
|
|
438
|
-
- String concatenation also uses `+`, but both sides must be strings.
|
|
439
|
-
- Comparison does not do implicit type conversion. `'5' == 5` does not yield `true`.
|
|
440
|
-
- `if` conditions and logical operations need real booleans; numbers cannot stand in for them.
|
|
441
|
-
|
|
442
|
-
### 6.2 Strings and conditions
|
|
443
|
-
|
|
444
|
-
Strings can use single or double quotes; escapes are `\\`, `\'`, `\"`, `\n`, `\t`. Example (assuming `name` and `annual` are declared):
|
|
445
|
-
|
|
446
|
-
```markdown
|
|
447
|
-
Name: {{ name == '' ? 'Not provided' : name }}
|
|
448
|
-
Billing: {{ annual ? 'Annual' : 'Monthly' }}
|
|
449
|
-
```
|
|
450
|
-
|
|
451
|
-
Conditional expressions can nest, but do not go too deep. When readability suffers, split part of the content into an `if` container.
|
|
452
|
-
|
|
453
|
-
### 6.3 Functions
|
|
454
|
-
|
|
455
|
-
For array indexing and numeric aggregates, cross-field hints and generated local tables, see [Constraints and collections](constraints-collections-en.md). Its workshop example shows how to keep related fields consistent while editing.
|
|
456
|
-
|
|
457
|
-
| Function | Purpose |
|
|
458
|
-
| --- | --- |
|
|
459
|
-
| `abs(x)` | Absolute value |
|
|
460
|
-
| `sqrt(x)` | Square root |
|
|
461
|
-
| `floor(x)`, `ceil(x)`, `round(x)` | Round down, round up, round to nearest |
|
|
462
|
-
| `min(a, b, ...)`, `max(a, b, ...)` | Minimum, maximum |
|
|
463
|
-
| `pow(base, exponent)` | Exponentiation |
|
|
464
|
-
| `sin`, `cos`, `tan`, `asin`, `acos`, `atan` | Trigonometric functions, in radians |
|
|
465
|
-
| `exp(x)`, `log(x)` | Exponential and natural logarithm |
|
|
466
|
-
| `len(value)` | Unicode code points in a string or array length |
|
|
467
|
-
| `contains(value, needle)` | Substring or array membership test |
|
|
468
|
-
| `clamp(value, lower, upper)` | Clamp a value to a closed interval |
|
|
469
|
-
|
|
470
|
-
`pi` and `e` are constants. `log` is the natural logarithm; this differs from LaTeX, where `\log` without a subscript is base 10 by default.
|
|
471
|
-
|
|
472
|
-
### 6.4 Common boundaries
|
|
473
|
-
|
|
474
|
-
- Arrays cannot be displayed directly. A `checklist` value is an array; use `len(done)` for the count and `contains(done, ...)` for membership.
|
|
475
|
-
- `null` displays as an empty string.
|
|
476
|
-
- Division by zero, domain errors, non-finite results and type errors show "Unable to compute" near the corresponding content, while other independent content keeps updating.
|
|
477
|
-
- Expressions have no assignment, method calls, property access, custom functions or imports.
|
|
478
|
-
- Expressions cannot read or write the DOM and cannot make network requests.
|
|
479
|
-
|
|
480
|
-
To write logical OR in a GFM table, escape the pipes:
|
|
481
|
-
|
|
482
|
-
```markdown
|
|
483
|
-
<toggle bind="ready" label="Ready">
|
|
484
|
-
<toggle bind="approved" label="Approved">
|
|
485
|
-
|
|
486
|
-
| Status | Notes |
|
|
487
|
-
| --- | --- |
|
|
488
|
-
| {{ ready \|\| approved ? 'Available' : 'Unavailable' }} | `\|\|` in a table means logical OR |
|
|
489
|
-
```
|
|
490
|
-
|
|
491
|
-
### 6.5 A rounding example
|
|
492
|
-
|
|
493
|
-
```markdown
|
|
494
|
-
<number bind="total" label="Bill amount" initial="240" min="0">
|
|
495
|
-
<slider bind="people" label="People splitting" initial="3" min="1" max="12">
|
|
496
|
-
<slider bind="tip" label="Extra charge (%)" initial="10" min="0" max="20">
|
|
497
|
-
|
|
498
|
-
Each person pays **{{ round(total * (1 + tip / 100) / people * 100) / 100 }} USD**.
|
|
499
|
-
```
|
|
500
|
-
|
|
501
|
-
`round` keeps only the integer part; dividing by 100 afterwards gives two decimal places. Trailing zeros are not padded, which is normal display behavior.
|
|
502
|
-
|
|
503
|
-
## 7. Conditions and content organization
|
|
504
|
-
|
|
505
|
-
### 7.1 Use if to control display
|
|
506
|
-
|
|
507
|
-
```markdown
|
|
508
|
-
<slider bind="people" label="People" initial="2" min="1" max="20">
|
|
509
|
-
|
|
510
|
-
<if when="{{ people >= 5 }}">
|
|
511
|
-
<alert tone="success" title="Team plan">
|
|
512
|
-
The group has reached 5 people, so you can compare billing options.
|
|
513
|
-
</alert>
|
|
514
|
-
</if>
|
|
515
|
-
```
|
|
516
|
-
|
|
517
|
-
`when` must be a complete boolean interpolation. Neither of these is correct:
|
|
518
|
-
|
|
519
|
-
```markdown
|
|
520
|
-
<!-- Wrong: a number is not a boolean -->
|
|
521
|
-
<if when="{{ people }}">
|
|
522
|
-
|
|
523
|
-
<!-- Wrong: not a complete interpolation -->
|
|
524
|
-
<if when="People: {{ people }}">
|
|
525
|
-
```
|
|
526
|
-
|
|
527
|
-
When the condition is false, content is hidden, but internal parameters are still initialized; unknown variables or type errors in hidden branches are still compile errors. When the conditional region is shown again, existing input state is preserved.
|
|
528
|
-
|
|
529
|
-
### 7.2 panel, card and grid
|
|
530
|
-
|
|
531
|
-
- `<panel>`: wraps a group of parameters and provides restore-defaults by default. Good for forms.
|
|
532
|
-
- `<card>`: a content card for standalone explanations.
|
|
533
|
-
- `<grid>`: side-by-side layout; direct children must be `<card>`, two columns by default.
|
|
534
|
-
|
|
535
|
-
```markdown
|
|
536
|
-
<grid columns="2">
|
|
537
|
-
<card title="Basic">
|
|
538
|
-
For individuals and small projects.
|
|
539
|
-
</card>
|
|
540
|
-
|
|
541
|
-
<card title="Pro">
|
|
542
|
-
For teams that need collaboration.
|
|
543
|
-
</card>
|
|
544
|
-
</grid>
|
|
545
|
-
```
|
|
546
|
-
|
|
547
|
-
Narrow screens switch to a single column automatically. `columns` accepts 1 to 4.
|
|
548
|
-
|
|
549
|
-
### 7.3 tabs and accordion
|
|
550
|
-
|
|
551
|
-
```markdown
|
|
552
|
-
<tabs label="Plan details">
|
|
553
|
-
<tab label="Feature comparison">
|
|
554
|
-
| Capability | Basic | Pro |
|
|
555
|
-
| --- | --- | --- |
|
|
556
|
-
| Parameter adjustment | Yes | Yes |
|
|
557
|
-
| Charts | No | Yes |
|
|
558
|
-
</tab>
|
|
559
|
-
|
|
560
|
-
<tab label="Buying advice">
|
|
561
|
-
Decide on the use case first, then compare billing periods.
|
|
562
|
-
</tab>
|
|
563
|
-
</tabs>
|
|
564
|
-
|
|
565
|
-
<accordion label="FAQ">
|
|
566
|
-
<disclosure label="How is the cost calculated?">
|
|
567
|
-
Annual billing is calculated at 80%.
|
|
568
|
-
</disclosure>
|
|
569
|
-
|
|
570
|
-
<disclosure label="Can I switch at any time?">
|
|
571
|
-
Yes, just use the toggle above.
|
|
572
|
-
</disclosure>
|
|
573
|
-
</accordion>
|
|
574
|
-
```
|
|
575
|
-
|
|
576
|
-
- `tab` requires `label`; when `value` is omitted, an internal value is generated.
|
|
577
|
-
- `accordion` direct children are `disclosure`, and multiple entries can be expanded at once.
|
|
578
|
-
- `disclosure` accepts `open` to start expanded.
|
|
579
|
-
|
|
580
|
-
Tab switching preserves child content state; timers in hidden regions pause and stay paused when shown again until the reader starts them.
|
|
581
|
-
|
|
582
|
-
### 7.4 alert, badge and tooltip
|
|
583
|
-
|
|
584
|
-
```markdown
|
|
585
|
-
<alert title="Note">
|
|
586
|
-
General information.
|
|
587
|
-
</alert>
|
|
588
|
-
|
|
589
|
-
<alert tone="warning" title="Careful">
|
|
590
|
-
A panel reset restores all parameters inside it.
|
|
591
|
-
</alert>
|
|
592
|
-
|
|
593
|
-
Status: <badge tone="success">Ready</badge>
|
|
594
|
-
|
|
595
|
-
Hover over <tooltip text="When input changes, related content updates automatically.">reactive binding</tooltip> for details.
|
|
596
|
-
```
|
|
597
|
-
|
|
598
|
-
`alert` tone can be `info`, `success` or `warning`. `badge` tone can be `neutral`, `success` or `warning`. `badge` and `tooltip` are inline components and can sit inside sentences.
|
|
599
|
-
|
|
600
|
-
The preview also adds `jump`, `anchor`, `text` and `section` for jumps and bounded prose color, `multi-select`, `range-slider` and `coordinate` for input, `quiz`, `steps` and `step` for practice and guided reading, `computed`/`const` for named values, `validation` for cross-field hints, and `data-table`/`column` for generated rows. The [extension reference](local-components-v2-en.md), [calculation reference](computations-formatting-en.md) and [constraints reference](constraints-collections-en.md) cover their rules.
|
|
601
|
-
|
|
602
|
-
## 8. Checklists, progress, timers and timelines
|
|
603
|
-
|
|
604
|
-
### 8.1 Checklists
|
|
605
|
-
|
|
606
|
-
```markdown
|
|
607
|
-
<checklist bind="done" label="Try it out">
|
|
608
|
-
- [x] Read the example
|
|
609
|
-
- [ ] Adjust parameters
|
|
610
|
-
- [ ] Try it on a narrow screen
|
|
611
|
-
</checklist>
|
|
612
|
-
|
|
613
|
-
Completed **{{ len(done) }} / 3** items.
|
|
614
|
-
|
|
615
|
-
<progress label="Completion" value="{{ len(done) / 3 * 100 }}">
|
|
616
|
-
```
|
|
617
|
-
|
|
618
|
-
- The `checklist` body must be a non-empty, single-level Markdown task list.
|
|
619
|
-
- `[x]` is the initial checked state, which reset restores.
|
|
620
|
-
- The public value is an array of internal IDs of selected items; usually use `len` for the count.
|
|
621
|
-
- `progress` `value` must be between 0 and `max`; out-of-range values produce diagnostics and are not silently clamped.
|
|
622
|
-
|
|
623
|
-
### 8.2 Timers
|
|
624
|
-
|
|
625
|
-
```markdown
|
|
626
|
-
<timer label="One-minute focus" duration="60">
|
|
627
|
-
|
|
628
|
-
<timer bind="remaining" label="Readable countdown" duration="90">
|
|
629
|
-
|
|
630
|
-
Remaining seconds: {{ remaining }}.
|
|
631
|
-
```
|
|
632
|
-
|
|
633
|
-
`duration` is a positive integer number of seconds, default 60. The timer has built-in start, pause and reset and stops at zero. It does not need `initial`.
|
|
634
|
-
|
|
635
|
-
### 8.3 Timelines
|
|
636
|
-
|
|
637
|
-
```markdown
|
|
638
|
-
<timeline title="Half-day plan" unit="minutes">
|
|
639
|
-
| Task | Start | Duration | Notes |
|
|
640
|
-
| --- | ---: | ---: | --- |
|
|
641
|
-
| Prepare | 0 | 10 | List materials |
|
|
642
|
-
| Write | 10 | 25 | Complete the main body |
|
|
643
|
-
| Review | 35 | 10 | Leave time for a second pass |
|
|
644
|
-
</timeline>
|
|
645
|
-
```
|
|
646
|
-
|
|
647
|
-
The header must contain either `Task`, `Start` and `Duration` (optional `Notes`) or `事项`, `开始` and `时长` (optional `说明`). Start times and durations are non-negative numbers, overlapping intervals are allowed, and sorting is stable by start time.
|
|
648
|
-
|
|
649
|
-
## 9. Tables and charts
|
|
650
|
-
|
|
651
|
-
### 9.1 Plain and enhanced tables
|
|
652
|
-
|
|
653
|
-
Plain Markdown tables remain static content:
|
|
654
|
-
|
|
655
|
-
```markdown
|
|
656
|
-
| Plan | Price |
|
|
657
|
-
| --- | ---: |
|
|
658
|
-
| Basic | 100 |
|
|
659
|
-
| Pro | 200 |
|
|
660
|
-
```
|
|
661
|
-
|
|
662
|
-
Put one inside `<table>` to get search, sorting and paging automatically:
|
|
663
|
-
|
|
664
|
-
```markdown
|
|
665
|
-
<table label="Component catalog" page-size="3">
|
|
666
|
-
| Name | Category | Purpose |
|
|
667
|
-
| --- | --- | --- |
|
|
668
|
-
| slider | Parameter | Adjust a number |
|
|
669
|
-
| toggle | Parameter | On/off switch |
|
|
670
|
-
| chart | Visual | Turn a table into a chart |
|
|
671
|
-
| diagram | Visual | Click a node to see notes |
|
|
672
|
-
</table>
|
|
673
|
-
```
|
|
674
|
-
|
|
675
|
-
`table` supports `searchable`, `sortable` and `page-size`. Search and sorting affect only the table; a panel reset also restores the query, sorting and page number.
|
|
676
|
-
|
|
677
|
-
### 9.2 Build charts from tables
|
|
678
|
-
|
|
679
|
-
The `chart` body is a Markdown table:
|
|
680
|
-
|
|
681
|
-
```markdown
|
|
682
|
-
<chart kind="bar" title="Cost comparison" y-label="USD">
|
|
683
|
-
| Item | Actual | Budget |
|
|
684
|
-
| --- | ---: | ---: |
|
|
685
|
-
| Content | 120 | 150 |
|
|
686
|
-
| Visual | 230 | 200 |
|
|
687
|
-
</chart>
|
|
688
|
-
```
|
|
689
|
-
|
|
690
|
-
The first column is usually the horizontal-axis label, and the remaining columns are numeric series. Series names come directly from headers, and the legend is generated automatically.
|
|
691
|
-
|
|
692
|
-
Chart values can follow parameters, but cells must be pure numbers or a complete cell containing only interpolation:
|
|
693
|
-
|
|
694
|
-
```markdown
|
|
695
|
-
<slider bind="people" label="People" initial="2" min="1" max="20">
|
|
696
|
-
|
|
697
|
-
<chart title="Comparison by people">
|
|
698
|
-
| Plan | Monthly cost |
|
|
699
|
-
| --- | ---: |
|
|
700
|
-
| Basic | {{ people * 20 }} |
|
|
701
|
-
| Pro | {{ people * 35 }} |
|
|
702
|
-
</chart>
|
|
703
|
-
```
|
|
704
|
-
|
|
705
|
-
The following is wrong:
|
|
706
|
-
|
|
707
|
-
```markdown
|
|
708
|
-
| Item | 20 USD |
|
|
709
|
-
```
|
|
710
|
-
|
|
711
|
-
`20 USD` is mixed text and cannot be used as a numeric column. Write only `20`, or put the unit in the header or chart label.
|
|
712
|
-
|
|
713
|
-
### 9.3 Choosing a chart type
|
|
714
|
-
|
|
715
|
-
| `kind` | Suitable data |
|
|
716
|
-
| --- | --- |
|
|
717
|
-
| `bar` | Comparisons between categories; the default |
|
|
718
|
-
| `line` | Trends that change in order |
|
|
719
|
-
| `area` | Emphasizing cumulative or range trends |
|
|
720
|
-
| `scatter` | Relationships between two numeric values |
|
|
721
|
-
| `donut` | Proportions of parts in a whole |
|
|
722
|
-
|
|
723
|
-
Rules in brief:
|
|
724
|
-
|
|
725
|
-
- `bar`, `line`, `area`: first column is the horizontal axis, remaining columns are numeric series.
|
|
726
|
-
- `scatter`: first column is the numeric horizontal axis and the rest are numeric vertical axes by default; `x` and `y` can also name headers.
|
|
727
|
-
- `donut`: first column is the label and second is the value; with more than two columns, `y` must name the single numeric column.
|
|
728
|
-
- `donut` values must be non-negative; a zero total shows "No share to display".
|
|
729
|
-
|
|
730
|
-
`x` and `y` are static header names. `y` may be a comma-separated list of column names, so column names themselves cannot contain commas.
|
|
731
|
-
|
|
732
|
-
### 9.4 Data rules
|
|
733
|
-
|
|
734
|
-
- Headers are non-empty and unique, and every row has the same column count.
|
|
735
|
-
- Cells may contain interpolation.
|
|
736
|
-
- Plain decimal or scientific-notation text is read as a number.
|
|
737
|
-
- Errors such as empty rows, non-numeric values or missing columns are located at the corresponding cell.
|
|
738
|
-
- Charts do not accept remote URLs, `data` attributes or API data; data must be written in the document.
|
|
739
|
-
|
|
740
|
-
## 10. Diagrams and function curves
|
|
741
|
-
|
|
742
|
-
### 10.1 Interactive diagrams
|
|
743
|
-
|
|
744
|
-
```markdown
|
|
745
|
-
<diagram bind="selected" initial="input" label="State flow">
|
|
746
|
-
<node id="input" label="Input">
|
|
747
|
-
The reader changes parameters through controls.
|
|
748
|
-
</node>
|
|
749
|
-
|
|
750
|
-
<node id="view" label="Display">
|
|
751
|
-
Prose and charts update with the result.
|
|
752
|
-
</node>
|
|
753
|
-
|
|
754
|
-
<edge from="input" to="view" label="Trigger update">
|
|
755
|
-
</diagram>
|
|
756
|
-
|
|
757
|
-
Current stage: {{ selected == 'input' ? 'Input' : 'Display' }}.
|
|
758
|
-
```
|
|
759
|
-
|
|
760
|
-
- The `diagram` body may contain only `node`, `edge` and whitespace.
|
|
761
|
-
- `node` requires `id` and `label`; its body is static Markdown notes.
|
|
762
|
-
- `edge` takes `from` and `to`; both ends must exist, and `label` is optional.
|
|
763
|
-
- Nodes are laid out automatically, with no coordinates needed; `direction="down"` switches to vertical layout.
|
|
764
|
-
- `initial` must be the id of an existing node; when omitted, the first node is selected.
|
|
765
|
-
- With `bind`, the selected node id is public; without `bind`, selection stays inside the component.
|
|
766
|
-
|
|
767
|
-
### 10.2 Draw function curves with LaTeX
|
|
768
|
-
|
|
769
|
-
```markdown
|
|
770
|
-
<slider bind="a" label="Amplitude" initial="1" min="0" max="3" step="0.5">
|
|
771
|
-
|
|
772
|
-
<plot min="-6" max="6" label="Sine curve" x-label="x" y-label="Displacement">
|
|
773
|
-
$$ y = a \sin x $$
|
|
774
|
-
</plot>
|
|
775
|
-
```
|
|
776
|
-
|
|
777
|
-
- The `plot` body may contain only whitespace and standalone formula blocks.
|
|
778
|
-
- Each `$$ ... $$` block defines one curve.
|
|
779
|
-
- Each block must be written `y = expression`; only explicit real functions y(x) are computed.
|
|
780
|
-
- Use multiple formula blocks for multiple curves; do not treat ordinary line breaks as separators.
|
|
781
|
-
|
|
782
|
-
```markdown
|
|
783
|
-
<plot min="-5" max="5" label="Two curves">
|
|
784
|
-
$$ y = x^2 $$
|
|
785
|
-
$$ y = 2x + 1 $$
|
|
786
|
-
</plot>
|
|
787
|
-
```
|
|
788
|
-
|
|
789
|
-
`min` and `max` may be dynamic, for example `max="{{ t }}"`; `samples` is a static integer from 2 to 2000; the vertical axis is determined automatically from samples in the current range.
|
|
790
|
-
|
|
791
|
-
### 10.3 How parameter names map
|
|
792
|
-
|
|
793
|
-
Parameter names in LaTeX map to `bind` names in the document:
|
|
794
|
-
|
|
795
|
-
| Form | Corresponding parameter |
|
|
796
|
-
| --- | --- |
|
|
797
|
-
| `a`, `f`, `t` | Same-name `bind="a"`, `bind="f"`, `bind="t"` |
|
|
798
|
-
| `abx` | `a × b × x` |
|
|
799
|
-
| `\mathrm{amplitude}` | `bind="amplitude"` |
|
|
800
|
-
| `\alpha`, `\beta`, `\theta` | Same-name English bind |
|
|
801
|
-
| `\pi` | Fixed circle constant, not a parameter |
|
|
802
|
-
| `x` | Plot variable |
|
|
803
|
-
| `y` | Output marker |
|
|
804
|
-
|
|
805
|
-
`x` and `y` cannot be bound to controls. Multi-letter parameters must use `\mathrm{name}`, and the command cannot contain spaces or interpolation.
|
|
806
|
-
|
|
807
|
-
### 10.4 Computable LaTeX and common pitfalls
|
|
808
|
-
|
|
809
|
-
Supported forms include the four operations, implicit multiplication, exponents, fractions, roots, grouping, trigonometric and inverse trigonometric functions, exponential and logarithm, absolute value, `min`/`max`, constants and piecewise functions.
|
|
810
|
-
|
|
811
|
-
```markdown
|
|
812
|
-
<plot min="0" max="10" label="Piecewise function">
|
|
813
|
-
$$
|
|
814
|
-
y = \begin{cases}
|
|
815
|
-
x, & x < 5 \\
|
|
816
|
-
10 - x, & x \ge 5
|
|
817
|
-
\end{cases}
|
|
818
|
-
$$
|
|
819
|
-
</plot>
|
|
820
|
-
```
|
|
821
|
-
|
|
822
|
-
Notes:
|
|
823
|
-
|
|
824
|
-
- LaTeX allows implicit multiplication, for example `2x`, `a\sin x`, `(x+1)(x-1)`.
|
|
825
|
-
- Prose expressions must use `*`; these are two different writing rules.
|
|
826
|
-
- `\sin 2x` means `sin(2x)`; use parentheses for complex arguments.
|
|
827
|
-
- `-x^2` means `-(x^2)`.
|
|
828
|
-
- `1/2x` is interpreted as `(1/2)x`; use `\frac` to make the denominator explicit.
|
|
829
|
-
- `\log x` is base 10 by default, and `\ln x` is the natural logarithm; `log` in prose expressions is the natural logarithm.
|
|
830
|
-
- Integrals, derivatives, sums, matrices, parametric curves, implicit equations and custom macros are not computable in the first version. Being able to display them does not mean they can be evaluated.
|
|
831
|
-
- Do not write `{{ }}` inside `plot`; parameters use the mapped math names directly.
|
|
832
|
-
|
|
833
|
-
## 11. Common errors at a glance
|
|
834
|
-
|
|
835
|
-
| Symptom or diagnostic | Common cause | Fix |
|
|
836
|
-
| --- | --- | --- |
|
|
837
|
-
| Unknown component `slidr` warning, local source display | Misspelled tag | Change to `slider`; other content still works |
|
|
838
|
-
| Missing `</card>` | A paired tag is not closed | Add the end tag and check nesting order |
|
|
839
|
-
| Reference to undeclared `seat` | Inconsistent `bind` spelling | Use `seats` consistently |
|
|
840
|
-
| Duplicate `initial` | Initial value written on two controls for one parameter | Keep only one |
|
|
841
|
-
| Initial value out of range | `initial="12"` but `max="10"` | Adjust the initial value or range |
|
|
842
|
-
| `if` condition type error | `when="{{ seats }}"` yields a number | Change to `when="{{ seats >= 5 }}"` |
|
|
843
|
-
| `on-click` is not part of the component | Attempting an event handler | Remove the event attribute and use component interactions |
|
|
844
|
-
| HTML tags display as source or report structure errors | Unknown tag or missing end tag | Use Markdown or the matching component, and check closing |
|
|
845
|
-
| Footnote reference stays literal | No matching definition | Check the identifiers in `[^note]` and `[^note]: Note text` |
|
|
846
|
-
| Chart shows a "20 USD" error | Text mixed into a numeric column | Write only the number and put the unit in the header |
|
|
847
|
-
| `edge` points to a nonexistent node | Typo in the `to` id | Use consistent node ids |
|
|
848
|
-
| Plot says integrals are unsupported | Formula outside the first version's computable scope | Use a supported function, or display it without plotting |
|
|
849
|
-
| `\|\|` in a table errors | GFM tables treat pipes as column separators | Write `\|\|` |
|
|
850
|
-
| A binding such as `sum` is rejected | The name is a new reserved function | Rename the binding and its references |
|
|
851
|
-
| Two anchors or a jump target conflict | Duplicate explicit ID or a heading collision | Use a unique `anchor.id` and a matching `jump.to` |
|
|
852
|
-
| Generated table reports a missing column | `data-table` needs at least one `column` | Add a `column` with a static label and value expression |
|
|
853
|
-
| Tags display as text | Inside a code fence or after a backslash escape | This is expected verbatim display |
|
|
854
|
-
| `textarea` body has no effect | `textarea` is a void component | Set text with `initial="..."` |
|
|
855
|
-
| Paired component written as `/>` | `<card ... />` does not close automatically | Use a start tag plus an end tag |
|
|
856
|
-
|
|
857
|
-
### 11.1 How to read diagnostics
|
|
858
|
-
|
|
859
|
-
Diagnostics give the source location, severity, category and a short explanation; common categories include tag structure, unknown syntax, bindings, initial values, types, constraints, tables, diagrams and math problems.
|
|
860
|
-
|
|
861
|
-
The Playground's left editor and right diagnostics panel locate problems together. Fallback warnings for unknown tags preserve the source while other content and interactions keep working; controls inside unknown regions do not create bindings. Unclosed component tags, invalid attributes on known components, expression or binding errors and resource limits still block compilation and disable interaction. Runtime local computation errors affect only the corresponding content, and other parts keep updating.
|
|
862
|
-
|
|
863
|
-
When debugging, fix the first error. Later errors are sometimes only knock-on effects of the first one.
|
|
864
|
-
|
|
865
|
-
### 11.2 How to show literals
|
|
866
|
-
|
|
867
|
-
To display `{{` in prose, write `\{{`; to display a tag example, use a backslash or inline code:
|
|
868
|
-
|
|
869
|
-
```markdown
|
|
870
|
-
This shows a literal: \{{ people }}.
|
|
871
|
-
|
|
872
|
-
Inline code is safest: `<slider bind="x" label="Example">`.
|
|
873
|
-
```
|
|
874
|
-
|
|
875
|
-
Everything inside a code fence is displayed verbatim; it creates no controls and is not evaluated.
|
|
876
|
-
|
|
877
|
-
## 12. Complete exercise: workshop signup page
|
|
878
|
-
|
|
879
|
-
Paste the following document into the Playground, try changing the copy and parameters, and then check yourself against the list that follows.
|
|
880
|
-
|
|
881
|
-
```markdown
|
|
882
|
-
# Weekend photography workshop
|
|
883
|
-
|
|
884
|
-
<panel title="Signup plan">
|
|
885
|
-
<slider bind="people" label="People" initial="4" min="1" max="12">
|
|
886
|
-
<toggle bind="annual" label="Member discount">
|
|
887
|
-
<choices bind="track" label="Course track">
|
|
888
|
-
<option value="portrait">Portrait</option>
|
|
889
|
-
<option value="landscape">Landscape</option>
|
|
890
|
-
</choices>
|
|
891
|
-
</panel>
|
|
892
|
-
|
|
893
|
-
Track: **{{ track == 'portrait' ? 'Portrait' : 'Landscape' }}**.
|
|
894
|
-
|
|
895
|
-
Cost per person: **{{ annual ? 240 : 300 }} USD**.
|
|
896
|
-
|
|
897
|
-
Total: **{{ people * (annual ? 240 : 300) }} USD**.
|
|
898
|
-
|
|
899
|
-
<if when="{{ people >= 6 }}">
|
|
900
|
-
<alert tone="success" title="Group arrangements">
|
|
901
|
-
The group has reached 6 people; we will contact you separately to confirm the venue.
|
|
902
|
-
</alert>
|
|
903
|
-
</if>
|
|
904
|
-
|
|
905
|
-
<chart title="Budget comparison for two plans" y-label="USD">
|
|
906
|
-
| Item | Basic | Full |
|
|
907
|
-
| --- | ---: | ---: |
|
|
908
|
-
| Course | {{ people * 300 }} | {{ people * 380 }} |
|
|
909
|
-
</chart>
|
|
910
|
-
|
|
911
|
-
<checklist bind="prepared" label="Before the workshop">
|
|
912
|
-
- [ ] Confirm the date
|
|
913
|
-
- [ ] Prepare equipment
|
|
914
|
-
- [ ] Check the weather
|
|
915
|
-
</checklist>
|
|
916
|
-
|
|
917
|
-
<progress label="Preparation progress" value="{{ len(prepared) / 3 * 100 }}">
|
|
918
|
-
```
|
|
919
|
-
|
|
920
|
-
This document covers:
|
|
921
|
-
|
|
922
|
-
- Three different kinds of parameters inside a panel
|
|
923
|
-
- Conditional expressions and arithmetic in prose
|
|
924
|
-
- An `if` conditional region
|
|
925
|
-
- Chart data driven by parameters
|
|
926
|
-
- Checklists, progress and panel reset
|
|
927
|
-
|
|
928
|
-
### 12.1 Self-check after writing a document
|
|
929
|
-
|
|
930
|
-
1. Every input control has a `label`.
|
|
931
|
-
2. Every parameter referenced in prose has a matching `bind` on some control.
|
|
932
|
-
3. Each parameter has only one explicit `initial`, and the initial value is within the allowed range.
|
|
933
|
-
4. All `if` conditions are boolean expressions.
|
|
934
|
-
5. Chart numeric columns have no units and no mixed text.
|
|
935
|
-
6. All paired tags close correctly, and no container is written as self-closing.
|
|
936
|
-
7. All code examples are inside code fences.
|
|
937
|
-
8. Check the layout at narrow widths, and check buttons, options and hints with the keyboard.
|
|
938
|
-
9. Click restore-defaults in the panel and confirm parameters and component state restore together.
|
|
939
|
-
10. The document does not depend on network requests, external data or event handlers.
|
|
940
|
-
|
|
941
|
-
## 13. Next steps
|
|
942
|
-
|
|
943
|
-
- To see finished documents: open the [example directory](../examples/local/README.md) and start with the counter, the plan calculator and the interactive diagram.
|
|
944
|
-
- To learn all components and boundaries: read the [local interaction syntax specification](local-interaction-syntax-en.md).
|
|
945
|
-
- To embed Reactive MD in your React app: read [local mode integration](local-integration-en.md).
|
|
946
|
-
- To see an error example: open [diagnostics.reactive.md](../examples/local/diagnostics.reactive.md) and use the diagnostics to understand common problems.
|
|
947
|
-
- To start the Playground: run `npm run dev` in the repository root, or visit the online demo at [yaozi.raricy.com](https://yaozi.raricy.com/).
|
|
948
|
-
|
|
949
|
-
## Appendix A: Component reference
|
|
950
|
-
|
|
951
|
-
| Purpose | Components |
|
|
952
|
-
| --- | --- |
|
|
953
|
-
| Parameter input | `input`, `textarea`, `number`, `slider`, `range-slider`, `coordinate`, `toggle`, `checkbox`, `date`, `select`, `choices`, `radio-group`, `multi-select`, `option` |
|
|
954
|
-
| Built-in actions | `counter`, `timer`, `checklist`, `progress` |
|
|
955
|
-
| Content organization | `panel`, `card`, `grid`, `tabs`, `tab`, `accordion`, `disclosure`, `if` |
|
|
956
|
-
| Navigation and prose | `jump`, `anchor`, `text`, `section` |
|
|
957
|
-
| Assessment and reading | `quiz`, `steps`, `step` |
|
|
958
|
-
| Hints | `alert`, `badge`, `tooltip` |
|
|
959
|
-
| Declarations and generated data | `computed`, `const`, `validation`, `data-table`, `column` |
|
|
960
|
-
| Visualization | `table`, `chart`, `plot`, `timeline`, `diagram`, `node`, `edge` |
|
|
961
|
-
|
|
962
|
-
`option`, `tab`, `disclosure`, `node`, `edge`, `step` and `column` are structural children of parent components and cannot be placed anywhere on their own. `computed`, `const` and `validation` are document declarations, not visible controls.
|
|
963
|
-
|
|
964
|
-
Most articles only need Markdown plus two or three input components and one display component. Connect parameters to prose first, then add charts, diagrams and LaTeX curves as needed.
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
See [local-draft-2 components and migration](local-components-v2-en.md) for new tags, colors and slot state, and [0.4.0 release and migration](release-0.4.0-en.md) for the upgrade checklist. `0.4.0` is the preview release on the `next` channel.
|