Expand description
Port of upstream Markdoc v0.5.11’s src/schema.ts and src/schema-types/*.
Owner: the semantics agent.
The default node schemas (default_nodes), the Class, Id and
ConditionalAttributeType types, and the new layer’s Config/Schema/SchemaAttribute
types (upstream’s types.ts).
The types hold what upstream’s JavaScript objects can hold, with JavaScript’s semantics where upstream’s code relies on them:
- An object upstream keeps a map in (
config.tags, a schema’sattributes, …) is anIndexMapin a JS object’s key order, and a lookup in one also finds what every JS object inherits fromObject.prototype(lookup): upstream finds a schema for a tag namedtoString, so this does too. - A value upstream reads only for its truthiness is a
bool(required,selfClosing); one it compares loosely or strictly keeps its value (render: Option<Value>, read byrendersandSchemaSlot::renders). undefinedisNone(default,variables,partials).- A JS function in a config (a schema’s
transformandvalidate, a function’stransform,matchesas a function,variablesas a function, a custom attribute type) is a Rust closure or trait object.
Config::from_json reads a config written as JSON (types as names, {"$regex", "flags"}
for a RegExp, {"$type": name} for a constructor or one of upstream’s classes).
Re-exports§
Modules§
- json
- A
Configfrom JSON, read asJSON.parsemakes the JavaScript object the JSON describes, and used as upstream uses such an object. - regexp
- A JavaScript
RegExp, as a schema attribute’smatchesholds one. - value
- The JavaScript values upstream’s semantics handle once a document is resolved.
Structs§
- Config
- Upstream’s
Config(types.ts). - Config
Function - Upstream’s
ConfigFunction. - Schema
- Upstream’s
Schema. - Schema
Attribute - Upstream’s
SchemaAttribute(also a function parameter’s schema). - Schema
Slot - Upstream’s
SchemaSlot. - Validation
config.validation(itsparentsareValidationContext::parents).- Validation
Context - The config a validate callback sees: upstream passes
{...config, validation: {...config.validation, parents}}, the node’s ancestors from the root down.
Enums§
- Builtin
Type - The constructors upstream’s
TypeMappingsnames. - Found
- What a JS property read finds in a map upstream keeps in a plain object.
- Markdoc
Type - Upstream’s own attribute type classes.
- Matches
- An attribute’s
matches. - Partial
- A
config.partialsentry: a parsed document, a list of them, or any other value (what a config read from JSON holds: the partial’s source, whichvalidateonly tests for truthiness andtransformcannot use). - Schema
Kind - What a schema value that upstream reads fields of is, when a config read from JSON gives something other than an object there (an attribute’s, a slot’s or a function parameter’s schema): upstream reads its fields all the same.
- Type
Spec - A
type: upstream’sValidationType | ValidationType[]. - Variables
config.variables: a value (normally an object), or a function of the path.
Traits§
- Custom
Type - A custom attribute type (upstream’s
CustomAttributeType): a class whose instance may havetransformandvalidate. ReturnNonefor a method the class does not have.
Functions§
- blockquote
blockquote.- class_
transform Class.transform(value): a falsy value or a string as it is, anything else as the keys of its truthy entries joined with spaces.- class_
validate Class.validate(value, _config, key).- code
code:codewith the content as its child.- comment
comment.- conditional_
validate ConditionalAttributeType.validate(value, _config, key): a boolean,null,undefinedor an object.- default_
nodes - Upstream’s
nodes(import * as nodes from './src/schema'). - document
document.- em
em.- error_
schema error.- fence
fence:pre, its children or else itscontent.- global_
attributes globalAttributes(transformer.ts):classandid, on every node and tag.- hardbreak
hardbreak.- heading
heading:h${level}.- hr
hr.- id_
validate Id.validate(value): a string starting with an ASCII letter (/^[a-zA-Z]/).- image
image.- inherited
- What a plain object (with
Object.prototypeas its prototype) inherits underkey:Object.prototype’s property (toStringisObject.prototype.toString,constructorisObject,__proto__the prototype itself),undefinedfor a name it does not have. This is the valueFound::Inheritedstands for. - inline
inline.- is_
undefined_ in map[key] === undefinedfor a map upstream keeps in a plain object (an inherited name is a function, notundefined).- item
item.- link
link.- list
list:olorul.- lookup
map[key]for a map upstream keeps in a plain object.- loose_
equals_ false value == false(loose equality), which is how upstream reads an attribute’srender:false,0,'', a string that reads as the number 0 ('0',' ','0x0'), and an array whose items join to one of those ([],[0]) are all== false;nullandundefinedare not.Errwhere converting the value throws.- merged_
attributes {...globalAttributes, ...schema.attributes}: the attributes a node of this schema may have, in a JS object’s order.- node
node.- paragraph
paragraph.- renders
- How an attribute renders (transformer.ts):
attr.render == falsehides it; otherwisetypeof attr.render === 'string' ? attr.render : key. The name is a key, a Rust string: a lone surrogate in it (only a config built in Rust can hold one) is U+FFFD.Errwhere readingrenderthrows (an attribute’s schema that isnull). - s
s.- softbreak
softbreak: a space.- strong
strong.- table
table.- tbody
tbody.- td
td.- text
text: its content.- th
th.- thead
thead.- tr
tr.
Type Aliases§
- Attribute
Validate Fn - An attribute’s
validate(value, config, name). - Function
Transform Fn - A configured function’s
transform(parameters, config): the parameters as upstream passes them,resolve(fn.parameters, config), which is normally a plain object of the call’s arguments (keyed by name or position) but any value a document can make (an object with a prototype, ortrueforclass=f() .parameters): read it as JavaScript does (value::getforparameters[0],value::own_values_offorObject.values(parameters)). - Function
Validate Fn - A configured function’s
validate(fn, config). - Matches
Fn matchesgiven as a function of the config.- Transform
Fn - A schema’s
transform(node, config). - Validate
Fn - A schema’s
validate(node, config);config.validation.parentsisValidationContext::parents. - Variables
Fn variablesgiven as a function of a variable’s path.