pub struct MapSchemaSource { /* private fields */ }Expand description
The schemas a host registered, as two maps.
What Config used to hold directly, behind the trait instead: schemas for
built-in node types keyed by type, and schemas for tags keyed by name.
builtin starts both at Markdoc’s own, which
is where a host that adds a tag or replaces a node schema starts from;
new starts both empty, for a host that supplies
every schema itself.
The maps are reachable directly, because they are the whole content and
hiding them would only add a method per operation. Fill one, then hand it
to builtins::config_with, which builds
the built-in schemas exactly once:
use std::sync::Arc;
use accent_proust::builtins;
use accent_proust::validate::{MapSchemaSource, Schema, SchemaKey};
let mut schemas = MapSchemaSource::builtin();
schemas.insert_tag("callout", Schema::new().render("aside"));
let config = builtins::config_with(Arc::new(schemas));
assert!(config.schemas.find(SchemaKey::Tag("callout")).is_some());
assert!(config.schemas.find(SchemaKey::Tag("if")).is_some());Implementations§
Source§impl MapSchemaSource
impl MapSchemaSource
Sourcepub fn new() -> MapSchemaSource
pub fn new() -> MapSchemaSource
Nothing registered. Every lookup misses, which is what
Config::new has always meant.
Sourcepub fn builtin() -> MapSchemaSource
pub fn builtin() -> MapSchemaSource
Markdoc’s own nodes and tags: what
builtins::config starts from.
Sourcepub fn insert_tag(
&mut self,
name: impl Into<String>,
schema: Schema,
) -> &mut MapSchemaSource
pub fn insert_tag( &mut self, name: impl Into<String>, schema: Schema, ) -> &mut MapSchemaSource
Register a tag schema, replacing any under the same name.
Sourcepub fn insert_node(
&mut self,
node_type: NodeType,
schema: Schema,
) -> &mut MapSchemaSource
pub fn insert_node( &mut self, node_type: NodeType, schema: Schema, ) -> &mut MapSchemaSource
Register a node schema, replacing any for the same type.
The tag schemas, by name.
The tag schemas, for in-place edit.
Trait Implementations§
Source§impl Clone for MapSchemaSource
impl Clone for MapSchemaSource
Source§fn clone(&self) -> MapSchemaSource
fn clone(&self) -> MapSchemaSource
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MapSchemaSource
impl Debug for MapSchemaSource
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
The names registered, through the same two methods Config’s Debug
reads, so the two renderings of one source cannot drift. A Schema
carries hooks, which have no useful rendering, so the derived form is
unavailable; the keys are what a reader chasing a tag-undefined
wants anyway.