Y.XmlText
Extends Y.Text to represent a Y.Xml node.
1
import * as Y from 'yjs'
2
​
3
const ydoc = new Y.Doc()
4
​
5
// You can define a Y.XmlText as a top-level type or a nested type
6
​
7
// Method 1: Define a top-level type
8
const yxmlText = ydoc.get('my xmltext type', Y.XmlText)
9
// Method 2: Define Y.XmlText that can be included into the Yjs document
10
const yxmltextNested = new Y.XmlText()
11
​
12
// Nested types can be included as content into any other shared type
13
yxmlText.set('my nested text', ytextNested)
14
​
15
// Common methods (also available in Y.Text)
16
yxmlText.insert(0, 'abc') // insert three elements
17
yxmlText.format(1, 2, { bold: true }) // delete second element
18
yxmlText.toDelta() // => [{ insert: 'a' }, { insert: 'bc', attributes: { bold: true }}]
19
​
20
// Methods specific to Y.XmlText
21
yxmlText.prevSibling
22
yxmlText.nextSibling
23
yxmlText.toString() // => "a<bold>bc</bold>"
Copied!

API

Inherits from Y.Text.
const yxmlText = Y.XmlText()
yxmlText.prevSibling: Y.XmlElement | Y.XmlText | null The previous sibling of this type. Is null if this is the first child of its parent.
yxmlText.nextSibling: Y.XmlElement | Y.XmlText | null The next sibling of this type. Is null if this is the last child of its parent.
yxmlText.toString(): string Returns the XML-String representation of this element. Formatting attributes are transformed to XML-tags. If the formatting attribute contains an object, the key-value pairs will be used as attributes. E.g.
1
ymxlText.insert(0, "my link", { a: { href: 'https://..' } })
2
ymxlText.toString() // => <a href="https://..">my link</a>
Copied!
Copy link
Edit on GitHub
Contents
API