pub struct Schema {
pub nodes: HashMap<String, NodeSpec>,
pub marks: HashMap<String, MarkSpec>,
}Expand description
An allow-list schema: which node/mark types, attributes, and children are
permitted. Build with Schema::new or load with Schema::from_json_str.
Fields§
§nodes: HashMap<String, NodeSpec>Node type -> its spec. Types absent here are reported as unknown.
marks: HashMap<String, MarkSpec>Mark type -> its spec. Marks absent here are reported as unknown.
Implementations§
Source§impl Schema
impl Schema
Sourcepub fn node(self, node_type: impl Into<String>, spec: NodeSpec) -> Self
pub fn node(self, node_type: impl Into<String>, spec: NodeSpec) -> Self
Register (or replace) a node type’s spec.
Sourcepub fn mark(self, mark_type: impl Into<String>, spec: MarkSpec) -> Self
pub fn mark(self, mark_type: impl Into<String>, spec: MarkSpec) -> Self
Register (or replace) a mark type’s spec.
Sourcepub fn from_json_str(s: &str) -> Result<Self>
pub fn from_json_str(s: &str) -> Result<Self>
Load a schema from its JSON definition.
use tiptap_rusty_parser::Schema;
let schema = Schema::from_json_str(r#"{
"nodes": { "doc": { "content": ["paragraph"] }, "paragraph": { "content": ["text"] }, "text": {} },
"marks": { "link": { "attrs": ["href"], "required_attrs": ["href"] } }
}"#).unwrap();
assert!(schema.nodes.contains_key("doc"));Trait Implementations§
Source§impl<'de> Deserialize<'de> for Schema
impl<'de> Deserialize<'de> for Schema
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Schema
Auto Trait Implementations§
impl Freeze for Schema
impl RefUnwindSafe for Schema
impl Send for Schema
impl Sync for Schema
impl Unpin for Schema
impl UnsafeUnpin for Schema
impl UnwindSafe for Schema
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more