Skip to main content

Module schema

Module schema 

Source
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’s attributes, …) is an IndexMap in a JS object’s key order, and a lookup in one also finds what every JS object inherits from Object.prototype (lookup): upstream finds a schema for a tag named toString, 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 by renders and SchemaSlot::renders).
  • undefined is None (default, variables, partials).
  • A JS function in a config (a schema’s transform and validate, a function’s transform, matches as a function, variables as 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§

pub use regexp::JsMatch;
pub use regexp::JsRegExp;
pub use value::TagValue;
pub use value::Value;

Modules§

json
A Config from JSON, read as JSON.parse makes the JavaScript object the JSON describes, and used as upstream uses such an object.
regexp
A JavaScript RegExp, as a schema attribute’s matches holds one.
value
The JavaScript values upstream’s semantics handle once a document is resolved.

Structs§

Config
Upstream’s Config (types.ts).
ConfigFunction
Upstream’s ConfigFunction.
Schema
Upstream’s Schema.
SchemaAttribute
Upstream’s SchemaAttribute (also a function parameter’s schema).
SchemaSlot
Upstream’s SchemaSlot.
Validation
config.validation (its parents are ValidationContext::parents).
ValidationContext
The config a validate callback sees: upstream passes {...config, validation: {...config.validation, parents}}, the node’s ancestors from the root down.

Enums§

BuiltinType
The constructors upstream’s TypeMappings names.
Found
What a JS property read finds in a map upstream keeps in a plain object.
MarkdocType
Upstream’s own attribute type classes.
Matches
An attribute’s matches.
Partial
A config.partials entry: a parsed document, a list of them, or any other value (what a config read from JSON holds: the partial’s source, which validate only tests for truthiness and transform cannot use).
SchemaKind
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.
TypeSpec
A type: upstream’s ValidationType | ValidationType[].
Variables
config.variables: a value (normally an object), or a function of the path.

Traits§

CustomType
A custom attribute type (upstream’s CustomAttributeType): a class whose instance may have transform and validate. Return None for 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: code with the content as its child.
comment
comment.
conditional_validate
ConditionalAttributeType.validate(value, _config, key): a boolean, null, undefined or 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 its content.
global_attributes
globalAttributes (transformer.ts): class and id, 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.prototype as its prototype) inherits under key: Object.prototype’s property (toString is Object.prototype.toString, constructor is Object, __proto__ the prototype itself), undefined for a name it does not have. This is the value Found::Inherited stands for.
inline
inline.
is_undefined_in
map[key] === undefined for a map upstream keeps in a plain object (an inherited name is a function, not undefined).
item
item.
link
link.
list
list: ol or ul.
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’s render: 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; null and undefined are not. Err where 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 == false hides it; otherwise typeof 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. Err where reading render throws (an attribute’s schema that is null).
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§

AttributeValidateFn
An attribute’s validate(value, config, name).
FunctionTransformFn
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, or true for class=f() .parameters): read it as JavaScript does (value::get for parameters[0], value::own_values_of for Object.values(parameters)).
FunctionValidateFn
A configured function’s validate(fn, config).
MatchesFn
matches given as a function of the config.
TransformFn
A schema’s transform(node, config).
ValidateFn
A schema’s validate(node, config); config.validation.parents is ValidationContext::parents.
VariablesFn
variables given as a function of a variable’s path.