Skip to content

Commit d7e9d6a

Browse files
sciyoshiclaude
andcommitted
fix: sync prosemirror-schema-basic to 1.2.4
- Add clearMark parse rules for em and strong marks (1.2.1) - Add getAttrs on strong <b> tag rule for Google Docs workaround (1.2.1) - Add getAttrs regex filter on strong font-weight style rule (1.2.1) - Add code: true to code mark spec (1.2.4) - Fix image parseDOM: use img[src] selector, extract alt attribute - Fix link parseDOM: use a[href] selector, extract title attribute Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 46cdbd3 commit d7e9d6a

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This package provides Python implementations of the following
1212
- [`prosemirror-model`](https://github.com/ProseMirror/prosemirror-model) version 1.25.4
1313
- [`prosemirror-transform`](https://github.com/ProseMirror/prosemirror-transform) version 1.8.0
1414
- [`prosemirror-test-builder`](https://github.com/ProseMirror/prosemirror-test-builder)
15-
- [`prosemirror-schema-basic`](https://github.com/ProseMirror/prosemirror-schema-basic) version 1.1.2
15+
- [`prosemirror-schema-basic`](https://github.com/ProseMirror/prosemirror-schema-basic) version 1.2.4
1616
- [`prosemirror-schema-list`](https://github.com/ProseMirror/prosemirror-schema-list) version 1.5.1 (node specs and `wrapRangeInList` only; command functions that depend on `prosemirror-state` are excluded)
1717

1818
The original implementation has been followed as closely as possible during

prosemirror/schema/basic/schema_basic.py

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
from typing import Any
23

34
from prosemirror.model import Schema
@@ -65,10 +66,11 @@
6566
"draggable": True,
6667
"parseDOM": [
6768
{
68-
"tag": "img",
69+
"tag": "img[src]",
6970
"getAttrs": lambda dom_: {
7071
"src": dom_.get("src"),
7172
"title": dom_.get("title"),
73+
"alt": dom_.get("alt"),
7274
},
7375
},
7476
],
@@ -101,22 +103,66 @@
101103
"title": {"default": None, "validate": "string|null"},
102104
},
103105
"inclusive": False,
104-
"parseDOM": [{"tag": "a", "getAttrs": lambda d: {"href": d.get("href")}}],
106+
"parseDOM": [
107+
{
108+
"tag": "a[href]",
109+
"getAttrs": lambda d: {
110+
"href": d.get("href"),
111+
"title": d.get("title"),
112+
},
113+
},
114+
],
105115
"toDOM": lambda node, _: [
106116
"a",
107117
{"href": node.attrs["href"], "title": node.attrs["title"]},
108118
0,
109119
],
110120
},
111121
"em": {
112-
"parseDOM": [{"tag": "i"}, {"tag": "em"}, {"style": "font-style=italic"}],
122+
"parseDOM": [
123+
{"tag": "i"},
124+
{"tag": "em"},
125+
{"style": "font-style=italic"},
126+
{
127+
"style": "font-style=normal",
128+
"clearMark": lambda m: m.type.name == "em",
129+
},
130+
],
113131
"toDOM": lambda _, __: em_dom,
114132
},
115133
"strong": {
116-
"parseDOM": [{"tag": "strong"}, {"tag": "b"}, {"style": "font-weight"}],
134+
"parseDOM": [
135+
{"tag": "strong"},
136+
# This works around a Google Docs misbehavior where
137+
# pasted content will be inexplicably wrapped in <b>
138+
# tags with a font-weight normal.
139+
{
140+
"tag": "b",
141+
"getAttrs": lambda node: (
142+
None
143+
if "font-weight:normal"
144+
not in (node.get("style") or "").replace(" ", "")
145+
else False
146+
),
147+
},
148+
{
149+
"style": "font-weight=400",
150+
"clearMark": lambda m: m.type.name == "strong",
151+
},
152+
{
153+
"style": "font-weight",
154+
"getAttrs": lambda value: (
155+
None if re.match(r"^(bold(er)?|[5-9]\d{2,})$", value) else False
156+
),
157+
},
158+
],
117159
"toDOM": lambda _, __: strong_dom,
118160
},
119-
"code": {"parseDOM": [{"tag": "code"}], "toDOM": lambda _, __: code_dom},
161+
"code": {
162+
"code": True,
163+
"parseDOM": [{"tag": "code"}],
164+
"toDOM": lambda _, __: code_dom,
165+
},
120166
}
121167

122168

0 commit comments

Comments
 (0)