Note: this is an internal repository, and issues and pull requests will not be accepted.
Converts XML from BlockNote's YJS format to the standard BlockNote JSON format. Uses roxmltree to parse the XML.
let xml_string = // ...
let json = atuin_ydoc_convert::convert_to_json(xml_string).unwrap();
println!("{}", json);
get_fragment_xml(doc: yrs::Doc, fragment_name: String) -> String
Returns well-formatted XML for the fragment with the given name in the given document. Note that this is different than what you would get if you calledget_string()
on theXmlFragmentRef
; the XML returned by this function is not identical to the XML that BlockNote uses to store documents. It is crafted to be suitable to be parsed by this library.convert_to_json(xml: String) -> Result<String, Error>
Converts the XML to a JSON string.convert_to_json_pretty(xml: String) -> Result<String, Error>
Converts the XML to a pretty-printed JSON string.convert_to_value(xml: String) -> Result<serde_json::Value, Error>
Converts the XML to aserde_json::Value
.
Error
- Error enumParseError(roxmltree::Error)
Wraps errors fromroxmltree
when parsing the XML document.MalformedDocument(String, roxmltree::TextPos)
Emitted when the XML document has unexpected structure (e.g. not a valid BlockNote document).
- There are some properties that exist on the XML tags that aren't found in BlockNote objects. Since the BlockNote schema is needed to determine which properties are valid for custom block types, this library applies all attributes found on XML tags to custom BlockNote block objects. Some examples:
<blockcontainer>
nodes always have abackgroundColor
attribute, but many blocks do not use it as a prop.- An empty
content
array is added to all blocks, including ones that don't support content.
- Since XML encodes all attributes as strings, this library parses them as strings as well. Properties for built-in block types are converted to numerics or booleans as appropriate; for custom blocks, consumers should handle the conversion.