Yjs Docs
  • Introduction
  • Yjs in the Wild
  • License ❤️
  • 🚲Getting Started
    • A Collaborative Editor
    • Awareness & Presence
    • Offline Support
    • Shared Types
  • 🔥Ecosystem
    • Editor Bindings
      • ProseMirror
      • TipTap
      • Monaco
      • Quill
      • CodeMirror
      • Remirror
      • Milkdown
      • Slate
    • Connection Provider
      • y-websocket
      • y-webrtc
      • y-webxdc
      • y-dat
      • y-sweet
      • Liveblocks
      • SuperViz
    • Database Provider
      • y-indexeddb
      • y-leveldb
      • y-redis
    • Other
      • y-protocols
    • Ports to other languages
  • 🔧API
    • Y.Doc
    • Shared Types
      • Y.Map
      • Y.Array
      • Y.Text
      • Y.XmlFragment
      • Y.XmlElement
      • Y.XmlText
    • Y.UndoManager
    • Y.Event
    • Delta Format
    • Document Updates
    • Y.RelativePosition
    • Awareness
    • Subdocuments
    • Internals
    • FAQ
  • 🧪Tutorials
    • Meshing Providers
    • Persisting the Document to a Central Database
    • Indefinite Scaling with y-redis
    • Lessons Learned
    • Custom Provider
  • 🌎External Resources
    • Talks, Podcasts, and Blogs
    • About CRDTs
    • CRDT Benchmarks
    • Yjs Discussion Board
    • Yjs Chat
    • Kevin's Blog
    • Awesome People ⭐
Powered by GitBook
On this page

Was this helpful?

Edit on Git
  1. API
  2. Shared Types

Y.XmlText

Extends Y.Text to represent a Y.Xml node.

import * as Y from 'yjs'

const ydoc = new Y.Doc()

// You can define a Y.XmlText as a top-level type or a nested type

// Method 1: Define a top-level type
const yxmlText = ydoc.get('my xmltext type', Y.XmlText) 
// Method 2: Define Y.XmlText that can be included into the Yjs document
const yxmltextNested = new Y.XmlText()

// Nested types can be included as content into any other shared type
yxmlText.set('my nested text', ytextNested)

// Common methods (also available in Y.Text)
yxmlText.insert(0, 'abc') // insert three elements
yxmlText.format(1, 2, { bold: true }) // delete second element 
yxmlText.toDelta() // => [{ insert: 'a' }, { insert: 'bc', attributes: { bold: true }}]

// Methods specific to Y.XmlText
yxmlText.prevSibling
yxmlText.nextSibling
yxmlText.toString() // => "a<bold>bc</bold>"

API

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.

ymxlText.insert(0, "my link", { a: { href: 'https://..' } })
ymxlText.toString() // => <a href="https://..">my link</a>
PreviousY.XmlElementNextY.UndoManager

Last updated 3 years ago

Was this helpful?

Inherits from .

🔧
Y.Text