Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .sampo/changesets/set-field-and-set-attribute.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
cargo/satteri-plugin-api: minor
npm/satteri: minor
---

Added `ctx.setField` for a node's own fields and `ctx.setAttribute` for `attributes` entries, so plugins can now rename elements, MDX JSX elements and directives, and set directive attributes. `ctx.setProperty` keeps setting HAST element properties; using it for fields or MDX JSX attributes is deprecated, and it is deprecated outright on MDAST.
32 changes: 29 additions & 3 deletions crates/satteri-layout-codegen/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ const LIST_ITEM_SLOTS: &[SetSlot] = &[
const DESCRIPTION_DETAILS_SLOTS: &[SetSlot] = &[sl("spread", 0, Slot::Bool)];
/// `MdxJsxElementData`: name `StringRef` @0.
const MDX_JSX_SLOTS: &[SetSlot] = &[sl("name", 0, Slot::Str)];
const DIRECTIVE_SLOTS: &[SetSlot] = &[sl("name", 0, Slot::Str)];
/// `ReferenceData.reference_kind` stays settable on footnoteReference even
/// though the walk wire skips it there (the mdast spec hides it).
const FOOTNOTE_REF_SLOTS: &[SetSlot] = &[sl("referenceType", 16, Slot::Enum8(REF_KINDS))];
Expand Down Expand Up @@ -590,15 +591,30 @@ pub const MDAST_NODES: &[Node] = &[
// InlineMath shares Math's stored `MathData` (meta@0, value@8) but the mdast
// spec gives it no `meta`, so only `value` is surfaced.
n(Mdast, 28, "InlineMath", "inlineMath", &[s32("value", 8)]),
xt(
xts(
Mdast,
30,
"ContainerDirective",
"containerDirective",
DIRECTIVE_TAIL,
DIRECTIVE_SLOTS,
),
xts(
Mdast,
31,
"LeafDirective",
"leafDirective",
DIRECTIVE_TAIL,
DIRECTIVE_SLOTS,
),
xts(
Mdast,
32,
"TextDirective",
"textDirective",
DIRECTIVE_TAIL,
DIRECTIVE_SLOTS,
),
xt(Mdast, 31, "LeafDirective", "leafDirective", DIRECTIVE_TAIL),
xt(Mdast, 32, "TextDirective", "textDirective", DIRECTIVE_TAIL),
c(Mdast, 33, "Superscript", "superscript"),
c(Mdast, 34, "Subscript", "subscript"),
c(Mdast, 35, "DescriptionList", "descriptionList"),
Expand Down Expand Up @@ -1223,6 +1239,16 @@ pub const COMMANDS: WireTable = WireTable {
0x0d,
"payload is a Root-wrapped child list",
),
wc(
"CMD_SET_FIELD",
0x0e,
"[valueType: u8][name str][value str], PROP_* value kinds; name is a node field",
),
wc(
"CMD_SET_ATTRIBUTE",
0x0f,
"[valueType: u8][name str][value str], PROP_* value kinds; name is an `attributes` entry",
),
],
};

Expand Down
2 changes: 1 addition & 1 deletion crates/satteri-plugin-api/src/generated/prop_slots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ pub(crate) fn mdast_prop_slot(node_type: u8, name: &str) -> Option<MdastPropSlot
(27, "meta") => MdastPropSlot::Str { offset: 0 },
(27, "value") => MdastPropSlot::Str { offset: 8 },
(28, "value") => MdastPropSlot::Str { offset: 8 },
(30 | 31 | 32 | 100 | 101, "name") => MdastPropSlot::Str { offset: 0 },
(37, "spread") => MdastPropSlot::Bool { offset: 0 },
(38, "name") => MdastPropSlot::Str { offset: 0 },
(38, "value") => MdastPropSlot::Str { offset: 8 },
(100 | 101, "name") => MdastPropSlot::Str { offset: 0 },
_ => return None,
})
}
2 changes: 2 additions & 0 deletions crates/satteri-plugin-api/src/generated/wire_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ pub const CMD_WRAP: u8 = 0x09;
pub const CMD_REPLACE: u8 = 0x0b;
pub const CMD_SET_PROPERTY: u8 = 0x0c; // [valueType: u8][name str][value str], PROP_* value kinds
pub const CMD_SET_CHILDREN: u8 = 0x0d; // payload is a Root-wrapped child list
pub const CMD_SET_FIELD: u8 = 0x0e; // [valueType: u8][name str][value str], PROP_* value kinds; name is a node field
pub const CMD_SET_ATTRIBUTE: u8 = 0x0f; // [valueType: u8][name str][value str], PROP_* value kinds; name is an `attributes` entry

// Structural-command payload types (0x10+, a range distinct from commands).
pub const PAYLOAD_RAW: u8 = 0x10; // [flags: u8][len: u32 LE][utf8] — re-parsed as markdown; see RAW_* flags
Expand Down
Loading