Skip to main content

Document

Struct Document 

Source
pub struct Document { /* private fields */ }
Expand description

Public, fallible, editable DOM over an internal Ast.

Implementations§

Source§

impl Document

Source

pub fn new() -> Self

Create an empty document containing only an empty math-mode root.

Source

pub fn with_mode(mode: ContentMode) -> Self

Like Document::new but with an explicit root content mode.

Source

pub fn from_syntax(node: &SyntaxNode) -> Result<Document, FromSyntaxError>

Build a document from a parsed syntax tree.

Source

pub fn id(&self) -> DocumentId

Process-wide unique id of this document.

Source

pub fn root(&self) -> NodeRef<'_>

Root node handle.

Source

pub fn node(&self, id: NodeId) -> Result<NodeRef<'_>, EditError>

Return a read-only handle for a public id.

Source

pub fn has_errors(&self) -> bool

true when the tree contains one or more Error nodes.

Source

pub fn errors(&self) -> impl Iterator<Item = NodeRef<'_>> + '_

Iterate every Error node in the tree.

Source

pub fn is_read_only(&self) -> bool

true when this document is read-only.

Source

pub fn find<'a>( &'a self, start: NodeRef<'a>, pred: impl Fn(NodeRef<'a>) -> bool + 'a, ) -> Option<NodeRef<'a>>

Find the first matching node under start, including start.

Source

pub fn find_all<'a>( &'a self, start: NodeRef<'a>, pred: impl Fn(NodeRef<'a>) -> bool + 'a, ) -> impl Iterator<Item = NodeRef<'a>> + 'a

Collect matching nodes under start, including start.

Source

pub fn find_commands<'a>( &'a self, name: &'a str, ) -> impl Iterator<Item = NodeRef<'a>> + 'a

Find commands by name.

Source

pub fn find_environments<'a>( &'a self, name: &'a str, ) -> impl Iterator<Item = NodeRef<'a>> + 'a

Find environments by name.

Source

pub fn to_syntax(&self) -> SyntaxNode

Convert this document back into a lossless SyntaxNode tree.

Source

pub fn to_latex(&self) -> Result<String, SerializeError>

Serialize to LaTeX using the default canonical style.

Source

pub fn to_latex_with( &self, options: &SerializeOptions, ) -> Result<String, SerializeError>

Serialize to LaTeX with explicit style options.

Source

pub fn create_char(&mut self, c: char) -> Result<NodeId, EditError>

Create a detached character node.

Source

pub fn create_text(&mut self, s: impl Into<String>) -> Result<NodeId, EditError>

Create a detached text node.

Source

pub fn create_active_space(&mut self) -> Result<NodeId, EditError>

Create a detached active ~ space node.

Source

pub fn create_group(&mut self, mode: ContentMode) -> Result<NodeId, EditError>

Create a detached group node.

Source

pub fn create_command( &mut self, name: impl Into<String>, args: Vec<ArgValue>, ) -> Result<NodeId, EditError>

Create a detached command node.

Source

pub fn create_declarative( &mut self, name: impl Into<String>, args: Vec<ArgValue>, ) -> Result<NodeId, EditError>

Create a detached declarative command node.

Source

pub fn create_environment( &mut self, name: impl Into<String>, args: Vec<ArgValue>, body: NodeId, ) -> Result<NodeId, EditError>

Create a detached environment node.

Source

pub fn append_child( &mut self, parent: NodeId, child: NodeId, ) -> Result<(), EditError>

Append a detached node to a root/group container.

Source

pub fn insert_before( &mut self, anchor: NodeId, new: NodeId, ) -> Result<(), EditError>

Insert a detached node before an attached group child.

Source

pub fn insert_after( &mut self, anchor: NodeId, new: NodeId, ) -> Result<(), EditError>

Insert a detached node after an attached group child.

Source

pub fn insert_child( &mut self, parent: NodeId, index: usize, child: NodeId, ) -> Result<(), EditError>

Insert a detached node at index in a root/group container.

Source

pub fn extract(&mut self, id: NodeId) -> Result<NodeId, EditError>

Detach an attached group child and return it as a detached root.

Source

pub fn remove(&mut self, id: NodeId) -> Result<(), EditError>

Remove an attached group child and its subtree.

Source

pub fn replace_with( &mut self, target: NodeId, replacement: NodeId, ) -> Result<(), EditError>

Replace target with a detached replacement.

Source

pub fn clear(&mut self, container: NodeId) -> Result<(), EditError>

Remove all direct children from a root/group container.

Source

pub fn set_command_name( &mut self, id: NodeId, name: impl Into<String>, ) -> Result<(), EditError>

Set the name of a command/infix/declarative/environment node.

Source

pub fn set_text( &mut self, id: NodeId, s: impl Into<String>, ) -> Result<(), EditError>

Set the payload of a text node.

Source

pub fn set_char(&mut self, id: NodeId, c: char) -> Result<(), EditError>

Set the character of a char node.

Source

pub fn set_arg( &mut self, id: NodeId, index: usize, value: ArgValue, ) -> Result<(), EditError>

Replace the value at argument slot index of a command-like node.

Source

pub fn wrap( &mut self, target: NodeId, wrapper: NodeId, ) -> Result<NodeId, EditError>

Wrap a group-child target with a detached root/group wrapper.

Source

pub fn unwrap(&mut self, group: NodeId) -> Result<Vec<NodeId>, EditError>

Remove a group-child group and splice its children into the parent.

Source

pub fn node_spans(&self) -> Vec<(String, Span)>

Export the parse-time span side table as (path, span) pairs.

Paths follow the parser’s tree-path scheme rooted at root: .child.N for container children, .arg.N.content for content-carrying argument slots, .left / .right for infix operands, .body for environment bodies, and .base / .sub / .sup for script slots. Nodes without a recorded span (e.g. created by edits, or any node of a document built without parser spans) are omitted. Spans reflect the original parse and are not updated by document edits.

Trait Implementations§

Source§

impl Clone for Document

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Document

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Document

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Document

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

Source§

type Proj<U: 'src> = U

Source§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

Source§

impl<T> OrderedSeq<'_, T> for T
where T: Clone,

Source§

impl<'p, T> Seq<'p, T> for T
where T: Clone,

Source§

type Item<'a> = &'a T where T: 'a

The item yielded by the iterator.
Source§

type Iter<'a> = Once<&'a T> where T: 'a

An iterator over the items within this container, by reference.
Source§

fn seq_iter(&self) -> <T as Seq<'p, T>>::Iter<'_>

Iterate over the elements of the container.
Source§

fn contains(&self, val: &T) -> bool
where T: PartialEq,

Check whether an item is contained within this sequence.
Source§

fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>
where 'p: 'b,

Convert an item of the sequence into a MaybeRef.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.