typst_shim/stable/
syntax.rs

1//! Typst Syntax
2use typst::syntax::LinkedNode;
3use typst::syntax::Side;
4
5/// The `LinkedNodeExt` trait is designed for compatibility between new and old
6/// versions of `typst`.
7pub trait LinkedNodeExt: Sized {
8    /// Get the leaf at the specified byte offset.
9    fn leaf_at_compat(&self, cursor: usize) -> Option<Self>;
10}
11
12impl LinkedNodeExt for LinkedNode<'_> {
13    fn leaf_at_compat(&self, cursor: usize) -> Option<Self> {
14        self.leaf_at(cursor, Side::Before)
15    }
16}