marktip 0.6.0__tar.gz → 0.7.0__tar.gz
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.
- {marktip-0.6.0 → marktip-0.7.0}/CMakeLists.txt +1 -1
- {marktip-0.6.0 → marktip-0.7.0}/PKG-INFO +80 -36
- {marktip-0.6.0 → marktip-0.7.0}/README.md +79 -35
- {marktip-0.6.0 → marktip-0.7.0}/pyproject.toml +1 -1
- {marktip-0.6.0 → marktip-0.7.0}/src/ast.cpp +170 -61
- {marktip-0.6.0 → marktip-0.7.0}/src/ast.h +17 -4
- {marktip-0.6.0 → marktip-0.7.0}/src/marktip.cpp +17 -12
- marktip-0.7.0/tests/test_strict.py +628 -0
- {marktip-0.6.0 → marktip-0.7.0}/tests/test_validate.py +1 -1
- marktip-0.6.0/tests/test_strict.py +0 -404
- {marktip-0.6.0 → marktip-0.7.0}/.github/workflows/build-distributions.yml +0 -0
- {marktip-0.6.0 → marktip-0.7.0}/.gitignore +0 -0
- {marktip-0.6.0 → marktip-0.7.0}/LICENSE +0 -0
- {marktip-0.6.0 → marktip-0.7.0}/python/marktip/__init__.py +0 -0
- {marktip-0.6.0 → marktip-0.7.0}/scripts/benchmark.py +0 -0
- {marktip-0.6.0 → marktip-0.7.0}/src/errors.h +0 -0
- {marktip-0.6.0 → marktip-0.7.0}/src/parser.cpp +0 -0
- {marktip-0.6.0 → marktip-0.7.0}/src/parser.h +0 -0
- {marktip-0.6.0 → marktip-0.7.0}/src/serializer.cpp +0 -0
- {marktip-0.6.0 → marktip-0.7.0}/src/serializer.h +0 -0
- {marktip-0.6.0 → marktip-0.7.0}/tests/test_document.py +0 -0
- {marktip-0.6.0 → marktip-0.7.0}/tests/test_errors.py +0 -0
- {marktip-0.6.0 → marktip-0.7.0}/tests/test_parse.py +0 -0
- {marktip-0.6.0 → marktip-0.7.0}/tests/test_roundtrip.py +0 -0
- {marktip-0.6.0 → marktip-0.7.0}/tests/test_serialize.py +0 -0
- {marktip-0.6.0 → marktip-0.7.0}/tests/test_uri_policy.py +0 -0
- {marktip-0.6.0 → marktip-0.7.0}/third_party/md4c/LICENSE.md +0 -0
- {marktip-0.6.0 → marktip-0.7.0}/third_party/md4c/src/entity.c +0 -0
- {marktip-0.6.0 → marktip-0.7.0}/third_party/md4c/src/entity.h +0 -0
- {marktip-0.6.0 → marktip-0.7.0}/third_party/md4c/src/md4c.c +0 -0
- {marktip-0.6.0 → marktip-0.7.0}/third_party/md4c/src/md4c.h +0 -0
- {marktip-0.6.0 → marktip-0.7.0}/third_party/md4c/upstream_metadata/README.md +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: marktip
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0
|
|
4
4
|
Summary: Fast C++/MD4C Markdown parser and canonical Markdown serializer for Tiptap-style JSON
|
|
5
5
|
Keywords: markdown,tiptap,md4c,parser
|
|
6
6
|
Author: Saneaven (Minjae Kyung)
|
|
@@ -111,46 +111,86 @@ An attr the serializer never reads is dropped without a word, so a `colspan: 2`
|
|
|
111
111
|
|
|
112
112
|
```python
|
|
113
113
|
tm.from_dict(ast).to_markdown() # '| x |\n| --- |' — the colspan is gone
|
|
114
|
-
tm.from_dict(ast, strict=
|
|
114
|
+
tm.from_dict(ast, strict="content") # InvalidNodeError: attr 'colspan' cannot be
|
|
115
115
|
# expressed in markdown: GFM tables have no cell spanning
|
|
116
116
|
```
|
|
117
117
|
|
|
118
|
-
`strict
|
|
119
|
-
It is
|
|
118
|
+
`strict` names what the conversion may not lose, from the walk that is already happening, so a consumer does not have to re-traverse the tree in Python to find out whether the document survives intact.
|
|
119
|
+
It is keyword-only and a `from_dict` option only — the parser emits nothing but attrs it understands, with values in range, so there is nothing on the `from_markdown` path for it to catch.
|
|
120
120
|
|
|
121
|
-
|
|
|
121
|
+
| `strict` | Keeps |
|
|
122
122
|
| --- | --- |
|
|
123
|
-
| `
|
|
124
|
-
| `
|
|
125
|
-
| `
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
123
|
+
| `"off"` (default) | nothing is checked |
|
|
124
|
+
| `"content"` | content and structure. Presentation an editor stamped on is type-checked and dropped |
|
|
125
|
+
| `"exact"` | every attr the JSON carries |
|
|
126
|
+
|
|
127
|
+
The two levels differ over one thing, and it is worth being precise about which:
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
# what a stock Tiptap Link extension submits for a link with only href set
|
|
131
|
+
mark = {"type": "link", "attrs": {"href": "https://a", "target": "_blank",
|
|
132
|
+
"rel": "noopener noreferrer nofollow",
|
|
133
|
+
"class": None, "title": None}}
|
|
134
|
+
|
|
135
|
+
tm.from_dict(ast, strict="content") # fine — target and rel are dropped
|
|
136
|
+
tm.from_dict(ast, strict="exact") # InvalidNodeError: attr 'target' cannot be expressed
|
|
137
|
+
# in markdown: a markdown link carries only a
|
|
138
|
+
# destination and a title
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Dropping that `target` costs the *author* nothing — the editor stamped it on and nobody wrote it.
|
|
142
|
+
Dropping a `colspan` moves every cell after it under a different header, so `"content"` refuses that one too.
|
|
143
|
+
Nothing in the JSON tells the two apart: ProseMirror serializes schema defaults onto every node, so a chosen `target` and a stamped one arrive identical.
|
|
144
|
+
That is why the caller picks, rather than the library guessing — store markdown as the record and `"content"` is the promise you want; keep the JSON and it is `"exact"`.
|
|
145
|
+
|
|
146
|
+
| Node | Accepted attrs | Dropped, no markdown form |
|
|
147
|
+
| --- | --- | --- |
|
|
148
|
+
| `heading` | `level`: 1–6 | |
|
|
149
|
+
| `codeBlock` | `language`, `info`: single-line `str` | |
|
|
150
|
+
| `bulletList`, `taskList` | `tight`: `bool` | |
|
|
151
|
+
| `orderedList` | `start`: 0–999999999, `tight`: `bool` | `type`: `str` |
|
|
152
|
+
| `taskItem` | `checked`: `bool` | |
|
|
153
|
+
| `table` | `colCount`: non-negative `int` | |
|
|
154
|
+
| `tableHeader`, `tableCell` | `align`: `"left"`/`"center"`/`"right"`/`None`, `colspan`: `1`, `rowspan`: `1` | `colwidth`: list of `int` |
|
|
155
|
+
| `image` | `src` **(required)**, `alt`, `title`: `str` | `width`, `height`: `str` or `int` |
|
|
156
|
+
| `htmlBlock`, `htmlInline` | `html`: `str` | |
|
|
157
|
+
| `link` mark | `href` **(required)**, `title`: `str` | `target`, `rel`, `class`: `str` |
|
|
133
158
|
|
|
134
159
|
Every other type takes no attrs at all.
|
|
135
|
-
|
|
160
|
+
A name in neither column is an `unknown_attr` at both levels — that is the rule that stops an `onclick` from vanishing silently.
|
|
161
|
+
`bool` and `int` stay distinct: `{"level": True}` is refused rather than read as `1`.
|
|
162
|
+
Most of these also take `None`, meaning the attr was never set; the paragraph below says which do not.
|
|
136
163
|
|
|
137
|
-
> **Changed in 0.
|
|
164
|
+
> **Changed in 0.7.0** — `strict` takes a level name instead of a bool, so `strict=True` now raises `TypeError`; `strict="exact"` is what it used to mean.
|
|
165
|
+
> Three things move with the new `"content"` level: the attrs in the right-hand column above are accepted and dropped rather than refused, `href`/`src` are required, and a refused presentation attr reports `unrepresentable` where it used to report `unknown_attr`.
|
|
166
|
+
|
|
167
|
+
> **Changed in 0.6.0** — `None` on the optional attrs above now means the attr is unset, and the key is dropped on the way in rather than coerced to `""`.
|
|
138
168
|
> Two things move with it: an `image` whose `alt` is `None` *and* which carries content children now renders that child text, and `to_dict()` omits such a key instead of echoing `""`.
|
|
139
169
|
|
|
140
|
-
`None`
|
|
141
|
-
ProseMirror serializes every attr
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
170
|
+
`None` reads as unset wherever Tiptap declares `default: null`, which is most of the schema.
|
|
171
|
+
ProseMirror serializes every attr including defaults, so `None` is what the editor submits for an attr nobody filled in, and an unset attr is accepted already; the markdown is the same either way.
|
|
172
|
+
The exceptions are the settings Tiptap gives a non-null default — `level`, `start`, `tight`, `checked`, `colspan`, `rowspan` — plus `html`, which is marktip's own attr with no Tiptap counterpart.
|
|
173
|
+
Tiptap never emits a `None` for those, so one means the dict was built wrong; the conversion would survive it, and strict reports it because it is a bug rather than a loss.
|
|
174
|
+
`align` is unchanged: `None` was already a *value* there ("no alignment"), not an unset marker.
|
|
175
|
+
|
|
176
|
+
`href` and `src` are the one place a `None` is not "unset" but "missing", and both levels refuse it:
|
|
146
177
|
|
|
147
|
-
|
|
178
|
+
```python
|
|
179
|
+
tm.from_dict(link_without_href).to_markdown() # '[a]()' — reads back as a real link
|
|
180
|
+
tm.from_dict(link_without_href, strict="content") # InvalidNodeError: attr 'href' is required
|
|
181
|
+
# for mark type 'link'
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
A link with no destination is not a link, so writing `[a]()` is not a lossy conversion but an invented one, and the empty destination survives into stored Markdown.
|
|
185
|
+
An `href` of `""` is a different case and is accepted: that is what `from_markdown` itself produces for `[a]()`, and it round-trips exactly.
|
|
186
|
+
Rejecting an empty destination is the URI policy's job (`link_relative="reject"`).
|
|
187
|
+
|
|
188
|
+
`colspan`/`rowspan` are *known* attrs whose only accepted values are the no-ops Tiptap's table extension puts on every cell.
|
|
148
189
|
Refusing the names outright would leave strict unusable for the documents it exists to check.
|
|
149
|
-
Tiptap's Link extension is the other direction: its default `target` and `rel` have no markdown form, so they are refused, which is the same rule that stops an `onclick` from vanishing silently.
|
|
150
190
|
|
|
151
|
-
Two attrs are accepted and then ignored
|
|
191
|
+
Two attrs are accepted and then ignored at every level.
|
|
152
192
|
The serializer derives a table's column count from its rows, so `colCount` is never read, and it takes cell alignment from the header row only, so `align` on a body row is never read either.
|
|
153
|
-
|
|
193
|
+
Neither is a loss — the structure they describe is what survives — and `from_markdown` emits both, so refusing them would break re-parsing stored canonical Markdown on the read path, where a write-time refusal is much harder to notice.
|
|
154
194
|
|
|
155
195
|
## Errors
|
|
156
196
|
|
|
@@ -187,18 +227,23 @@ For `from_markdown` it locates the node in the parsed document, since the input
|
|
|
187
227
|
| `disallowed_scheme` | `InvalidNodeError` | a link `href` / image `src` scheme is outside the allowlist |
|
|
188
228
|
| `disallowed_relative_url` | `InvalidNodeError` | a scheme-less `href`/`src` violates the relative policy |
|
|
189
229
|
| `invalid_uri_char` | `InvalidNodeError` | an `href`/`src` contains an ASCII control character |
|
|
190
|
-
| `unknown_attr` | `InvalidNodeError` | `strict`: the attr
|
|
230
|
+
| `unknown_attr` | `InvalidNodeError` | `strict`: the attr name is in neither dialect for that type |
|
|
191
231
|
| `invalid_attr_value` | `InvalidNodeError` | `strict`: the attr's value has the wrong type or is out of range |
|
|
192
|
-
| `unrepresentable` | `InvalidNodeError` | `strict`: the value is well-formed, but
|
|
232
|
+
| `unrepresentable` | `InvalidNodeError` | `strict`: the value is well-formed, but markdown cannot carry it |
|
|
233
|
+
| `missing_attr` | `InvalidNodeError` | `strict`: a required attr is absent or `None` — a `link` with no `href`, an `image` with no `src` |
|
|
193
234
|
| `markdown_max_depth` | `ParseError` | markdown nesting exceeds 2048 |
|
|
194
235
|
| `parse_failed` | `ParseError` | MD4C could not parse the input |
|
|
195
236
|
|
|
196
237
|
`from_markdown` still raises a plain `TypeError` when the argument is not `str`/`bytes` — that is a caller bug, not a malformed document.
|
|
197
|
-
So is a bad
|
|
238
|
+
So is a bad option value: a non-iterable `link_schemes` raises `TypeError`, and `link_schemes=("https://",)`, `link_relative="nope"` or `strict="strict"` raises `ValueError`.
|
|
239
|
+
`strict` takes a level name, so `strict=True` raises `TypeError` rather than quietly meaning something.
|
|
198
240
|
|
|
199
241
|
> **Changed in 0.4.0** — these were previously `ValueError` (`from_dict`) and `RuntimeError` (`from_markdown`).
|
|
200
242
|
> `MarktipError` derives from `Exception` directly, so `except ValueError` no longer catches them.
|
|
201
243
|
|
|
244
|
+
> **Changed in 0.7.0** — `missing_attr` is new, and an attr with no markdown form now reports `unrepresentable` rather than `unknown_attr`, which is left meaning "no schema declares this name".
|
|
245
|
+
> `attrs` values that are not `str`/`int`/`bool` are dropped instead of stringified, so `to_dict()` no longer echoes a `"[1, 2]"` the caller never wrote.
|
|
246
|
+
|
|
202
247
|
> **Changed in 0.5.0** — an ASCII control character in a link `href` or image `src` is now rejected outright, with or without the URI policy.
|
|
203
248
|
> A URI cannot carry one unencoded (`%09` is the encoded form), and leaving it in would defeat the allowlist itself, because browsers strip tab/LF/CR before reading the scheme.
|
|
204
249
|
> This also rejects `[x](<a\tb>)`, which CommonMark otherwise accepts.
|
|
@@ -226,16 +271,15 @@ It guarantees, for the whole tree:
|
|
|
226
271
|
A document that survives `from_dict` always serializes; callers do not need to re-check any of the above.
|
|
227
272
|
`from_markdown` enforces the same two URI rules on what it parses.
|
|
228
273
|
|
|
229
|
-
It deliberately does **not** validate, unless `strict
|
|
274
|
+
It deliberately does **not** validate, unless `strict` asks it to:
|
|
230
275
|
|
|
231
276
|
- **`attrs` names and value types.**
|
|
232
277
|
Keys are free-form.
|
|
233
|
-
`str`, `int`, and `bool` round-trip unchanged;
|
|
234
|
-
The one exception is the attrs [Refusing lossy conversions](#refusing-lossy-conversions) lists as accepting `None`: there the key is dropped instead of coerced, because a `None` on those means the attr was never set.
|
|
278
|
+
`str`, `int`, and `bool` round-trip unchanged; every other value is dropped, `None` included, so `to_dict()` gives back what you passed in minus the keys markdown could not have carried anyway.
|
|
235
279
|
An attr with no markdown form is dropped at serialization — see [Refusing lossy conversions](#refusing-lossy-conversions).
|
|
236
|
-
- **Per-node required attrs
|
|
237
|
-
A `heading` without `level
|
|
238
|
-
`strict`
|
|
280
|
+
- **Per-node required attrs.**
|
|
281
|
+
A `heading` without `level` or a `codeBlock` without `language` is accepted; the serializer substitutes a default rather than failing.
|
|
282
|
+
`strict` adds exactly two: a `link` needs an `href` and an `image` needs a `src`, because the default there is an empty destination that reads back as a real link.
|
|
239
283
|
`{"src": None}` and no `src` key at all are the same thing to every part of the library, the URI policy included.
|
|
240
284
|
- **Content models.**
|
|
241
285
|
Which node may contain which is not checked — a `text` node directly under `doc` is accepted and serialized.
|
|
@@ -83,46 +83,86 @@ An attr the serializer never reads is dropped without a word, so a `colspan: 2`
|
|
|
83
83
|
|
|
84
84
|
```python
|
|
85
85
|
tm.from_dict(ast).to_markdown() # '| x |\n| --- |' — the colspan is gone
|
|
86
|
-
tm.from_dict(ast, strict=
|
|
86
|
+
tm.from_dict(ast, strict="content") # InvalidNodeError: attr 'colspan' cannot be
|
|
87
87
|
# expressed in markdown: GFM tables have no cell spanning
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
-
`strict
|
|
91
|
-
It is
|
|
90
|
+
`strict` names what the conversion may not lose, from the walk that is already happening, so a consumer does not have to re-traverse the tree in Python to find out whether the document survives intact.
|
|
91
|
+
It is keyword-only and a `from_dict` option only — the parser emits nothing but attrs it understands, with values in range, so there is nothing on the `from_markdown` path for it to catch.
|
|
92
92
|
|
|
93
|
-
|
|
|
93
|
+
| `strict` | Keeps |
|
|
94
94
|
| --- | --- |
|
|
95
|
-
| `
|
|
96
|
-
| `
|
|
97
|
-
| `
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
95
|
+
| `"off"` (default) | nothing is checked |
|
|
96
|
+
| `"content"` | content and structure. Presentation an editor stamped on is type-checked and dropped |
|
|
97
|
+
| `"exact"` | every attr the JSON carries |
|
|
98
|
+
|
|
99
|
+
The two levels differ over one thing, and it is worth being precise about which:
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
# what a stock Tiptap Link extension submits for a link with only href set
|
|
103
|
+
mark = {"type": "link", "attrs": {"href": "https://a", "target": "_blank",
|
|
104
|
+
"rel": "noopener noreferrer nofollow",
|
|
105
|
+
"class": None, "title": None}}
|
|
106
|
+
|
|
107
|
+
tm.from_dict(ast, strict="content") # fine — target and rel are dropped
|
|
108
|
+
tm.from_dict(ast, strict="exact") # InvalidNodeError: attr 'target' cannot be expressed
|
|
109
|
+
# in markdown: a markdown link carries only a
|
|
110
|
+
# destination and a title
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Dropping that `target` costs the *author* nothing — the editor stamped it on and nobody wrote it.
|
|
114
|
+
Dropping a `colspan` moves every cell after it under a different header, so `"content"` refuses that one too.
|
|
115
|
+
Nothing in the JSON tells the two apart: ProseMirror serializes schema defaults onto every node, so a chosen `target` and a stamped one arrive identical.
|
|
116
|
+
That is why the caller picks, rather than the library guessing — store markdown as the record and `"content"` is the promise you want; keep the JSON and it is `"exact"`.
|
|
117
|
+
|
|
118
|
+
| Node | Accepted attrs | Dropped, no markdown form |
|
|
119
|
+
| --- | --- | --- |
|
|
120
|
+
| `heading` | `level`: 1–6 | |
|
|
121
|
+
| `codeBlock` | `language`, `info`: single-line `str` | |
|
|
122
|
+
| `bulletList`, `taskList` | `tight`: `bool` | |
|
|
123
|
+
| `orderedList` | `start`: 0–999999999, `tight`: `bool` | `type`: `str` |
|
|
124
|
+
| `taskItem` | `checked`: `bool` | |
|
|
125
|
+
| `table` | `colCount`: non-negative `int` | |
|
|
126
|
+
| `tableHeader`, `tableCell` | `align`: `"left"`/`"center"`/`"right"`/`None`, `colspan`: `1`, `rowspan`: `1` | `colwidth`: list of `int` |
|
|
127
|
+
| `image` | `src` **(required)**, `alt`, `title`: `str` | `width`, `height`: `str` or `int` |
|
|
128
|
+
| `htmlBlock`, `htmlInline` | `html`: `str` | |
|
|
129
|
+
| `link` mark | `href` **(required)**, `title`: `str` | `target`, `rel`, `class`: `str` |
|
|
105
130
|
|
|
106
131
|
Every other type takes no attrs at all.
|
|
107
|
-
|
|
132
|
+
A name in neither column is an `unknown_attr` at both levels — that is the rule that stops an `onclick` from vanishing silently.
|
|
133
|
+
`bool` and `int` stay distinct: `{"level": True}` is refused rather than read as `1`.
|
|
134
|
+
Most of these also take `None`, meaning the attr was never set; the paragraph below says which do not.
|
|
108
135
|
|
|
109
|
-
> **Changed in 0.
|
|
136
|
+
> **Changed in 0.7.0** — `strict` takes a level name instead of a bool, so `strict=True` now raises `TypeError`; `strict="exact"` is what it used to mean.
|
|
137
|
+
> Three things move with the new `"content"` level: the attrs in the right-hand column above are accepted and dropped rather than refused, `href`/`src` are required, and a refused presentation attr reports `unrepresentable` where it used to report `unknown_attr`.
|
|
138
|
+
|
|
139
|
+
> **Changed in 0.6.0** — `None` on the optional attrs above now means the attr is unset, and the key is dropped on the way in rather than coerced to `""`.
|
|
110
140
|
> Two things move with it: an `image` whose `alt` is `None` *and* which carries content children now renders that child text, and `to_dict()` omits such a key instead of echoing `""`.
|
|
111
141
|
|
|
112
|
-
`None`
|
|
113
|
-
ProseMirror serializes every attr
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
142
|
+
`None` reads as unset wherever Tiptap declares `default: null`, which is most of the schema.
|
|
143
|
+
ProseMirror serializes every attr including defaults, so `None` is what the editor submits for an attr nobody filled in, and an unset attr is accepted already; the markdown is the same either way.
|
|
144
|
+
The exceptions are the settings Tiptap gives a non-null default — `level`, `start`, `tight`, `checked`, `colspan`, `rowspan` — plus `html`, which is marktip's own attr with no Tiptap counterpart.
|
|
145
|
+
Tiptap never emits a `None` for those, so one means the dict was built wrong; the conversion would survive it, and strict reports it because it is a bug rather than a loss.
|
|
146
|
+
`align` is unchanged: `None` was already a *value* there ("no alignment"), not an unset marker.
|
|
147
|
+
|
|
148
|
+
`href` and `src` are the one place a `None` is not "unset" but "missing", and both levels refuse it:
|
|
118
149
|
|
|
119
|
-
|
|
150
|
+
```python
|
|
151
|
+
tm.from_dict(link_without_href).to_markdown() # '[a]()' — reads back as a real link
|
|
152
|
+
tm.from_dict(link_without_href, strict="content") # InvalidNodeError: attr 'href' is required
|
|
153
|
+
# for mark type 'link'
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
A link with no destination is not a link, so writing `[a]()` is not a lossy conversion but an invented one, and the empty destination survives into stored Markdown.
|
|
157
|
+
An `href` of `""` is a different case and is accepted: that is what `from_markdown` itself produces for `[a]()`, and it round-trips exactly.
|
|
158
|
+
Rejecting an empty destination is the URI policy's job (`link_relative="reject"`).
|
|
159
|
+
|
|
160
|
+
`colspan`/`rowspan` are *known* attrs whose only accepted values are the no-ops Tiptap's table extension puts on every cell.
|
|
120
161
|
Refusing the names outright would leave strict unusable for the documents it exists to check.
|
|
121
|
-
Tiptap's Link extension is the other direction: its default `target` and `rel` have no markdown form, so they are refused, which is the same rule that stops an `onclick` from vanishing silently.
|
|
122
162
|
|
|
123
|
-
Two attrs are accepted and then ignored
|
|
163
|
+
Two attrs are accepted and then ignored at every level.
|
|
124
164
|
The serializer derives a table's column count from its rows, so `colCount` is never read, and it takes cell alignment from the header row only, so `align` on a body row is never read either.
|
|
125
|
-
|
|
165
|
+
Neither is a loss — the structure they describe is what survives — and `from_markdown` emits both, so refusing them would break re-parsing stored canonical Markdown on the read path, where a write-time refusal is much harder to notice.
|
|
126
166
|
|
|
127
167
|
## Errors
|
|
128
168
|
|
|
@@ -159,18 +199,23 @@ For `from_markdown` it locates the node in the parsed document, since the input
|
|
|
159
199
|
| `disallowed_scheme` | `InvalidNodeError` | a link `href` / image `src` scheme is outside the allowlist |
|
|
160
200
|
| `disallowed_relative_url` | `InvalidNodeError` | a scheme-less `href`/`src` violates the relative policy |
|
|
161
201
|
| `invalid_uri_char` | `InvalidNodeError` | an `href`/`src` contains an ASCII control character |
|
|
162
|
-
| `unknown_attr` | `InvalidNodeError` | `strict`: the attr
|
|
202
|
+
| `unknown_attr` | `InvalidNodeError` | `strict`: the attr name is in neither dialect for that type |
|
|
163
203
|
| `invalid_attr_value` | `InvalidNodeError` | `strict`: the attr's value has the wrong type or is out of range |
|
|
164
|
-
| `unrepresentable` | `InvalidNodeError` | `strict`: the value is well-formed, but
|
|
204
|
+
| `unrepresentable` | `InvalidNodeError` | `strict`: the value is well-formed, but markdown cannot carry it |
|
|
205
|
+
| `missing_attr` | `InvalidNodeError` | `strict`: a required attr is absent or `None` — a `link` with no `href`, an `image` with no `src` |
|
|
165
206
|
| `markdown_max_depth` | `ParseError` | markdown nesting exceeds 2048 |
|
|
166
207
|
| `parse_failed` | `ParseError` | MD4C could not parse the input |
|
|
167
208
|
|
|
168
209
|
`from_markdown` still raises a plain `TypeError` when the argument is not `str`/`bytes` — that is a caller bug, not a malformed document.
|
|
169
|
-
So is a bad
|
|
210
|
+
So is a bad option value: a non-iterable `link_schemes` raises `TypeError`, and `link_schemes=("https://",)`, `link_relative="nope"` or `strict="strict"` raises `ValueError`.
|
|
211
|
+
`strict` takes a level name, so `strict=True` raises `TypeError` rather than quietly meaning something.
|
|
170
212
|
|
|
171
213
|
> **Changed in 0.4.0** — these were previously `ValueError` (`from_dict`) and `RuntimeError` (`from_markdown`).
|
|
172
214
|
> `MarktipError` derives from `Exception` directly, so `except ValueError` no longer catches them.
|
|
173
215
|
|
|
216
|
+
> **Changed in 0.7.0** — `missing_attr` is new, and an attr with no markdown form now reports `unrepresentable` rather than `unknown_attr`, which is left meaning "no schema declares this name".
|
|
217
|
+
> `attrs` values that are not `str`/`int`/`bool` are dropped instead of stringified, so `to_dict()` no longer echoes a `"[1, 2]"` the caller never wrote.
|
|
218
|
+
|
|
174
219
|
> **Changed in 0.5.0** — an ASCII control character in a link `href` or image `src` is now rejected outright, with or without the URI policy.
|
|
175
220
|
> A URI cannot carry one unencoded (`%09` is the encoded form), and leaving it in would defeat the allowlist itself, because browsers strip tab/LF/CR before reading the scheme.
|
|
176
221
|
> This also rejects `[x](<a\tb>)`, which CommonMark otherwise accepts.
|
|
@@ -198,16 +243,15 @@ It guarantees, for the whole tree:
|
|
|
198
243
|
A document that survives `from_dict` always serializes; callers do not need to re-check any of the above.
|
|
199
244
|
`from_markdown` enforces the same two URI rules on what it parses.
|
|
200
245
|
|
|
201
|
-
It deliberately does **not** validate, unless `strict
|
|
246
|
+
It deliberately does **not** validate, unless `strict` asks it to:
|
|
202
247
|
|
|
203
248
|
- **`attrs` names and value types.**
|
|
204
249
|
Keys are free-form.
|
|
205
|
-
`str`, `int`, and `bool` round-trip unchanged;
|
|
206
|
-
The one exception is the attrs [Refusing lossy conversions](#refusing-lossy-conversions) lists as accepting `None`: there the key is dropped instead of coerced, because a `None` on those means the attr was never set.
|
|
250
|
+
`str`, `int`, and `bool` round-trip unchanged; every other value is dropped, `None` included, so `to_dict()` gives back what you passed in minus the keys markdown could not have carried anyway.
|
|
207
251
|
An attr with no markdown form is dropped at serialization — see [Refusing lossy conversions](#refusing-lossy-conversions).
|
|
208
|
-
- **Per-node required attrs
|
|
209
|
-
A `heading` without `level
|
|
210
|
-
`strict`
|
|
252
|
+
- **Per-node required attrs.**
|
|
253
|
+
A `heading` without `level` or a `codeBlock` without `language` is accepted; the serializer substitutes a default rather than failing.
|
|
254
|
+
`strict` adds exactly two: a `link` needs an `href` and an `image` needs a `src`, because the default there is an empty destination that reads back as a real link.
|
|
211
255
|
`{"src": None}` and no `src` key at all are the same thing to every part of the library, the URI policy included.
|
|
212
256
|
- **Content models.**
|
|
213
257
|
Which node may contain which is not checked — a `text` node directly under `doc` is accepted and serialized.
|
|
@@ -4,7 +4,7 @@ build-backend = "scikit_build_core.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "marktip"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.7.0"
|
|
8
8
|
description = "Fast C++/MD4C Markdown parser and canonical Markdown serializer for Tiptap-style JSON"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|