pub struct DocumentFragment { /* private fields */ }Expand description
A piece of rich text that can be inserted into a TextDocument.
DocumentFragment is the clipboard/interchange type. It carries
blocks, per-character format runs, image anchors, and structural
metadata in a format-agnostic internal representation.
Implementations§
Source§impl DocumentFragment
impl DocumentFragment
Sourcepub fn from_plain_text(text: &str) -> Self
pub fn from_plain_text(text: &str) -> Self
Create a fragment from plain text.
Builds valid fragment data so the fragment can be inserted via
TextCursor::insert_fragment.
Sourcepub fn from_html(html: &str) -> Self
pub fn from_html(html: &str) -> Self
Create a fragment from HTML, as a clipboard carries a passage copied from a web page or another application.
A <pre> goes in as paragraphs, one for each of its lines, each keeping its spaces,
where TextDocument::set_html loads it as a code
block: a preformatted passage pasted into prose is most often a poem or a letter set
line by line, and a code block keeps no emphasis and takes no footnote reference.
Sourcepub fn from_markdown(markdown: &str) -> Self
pub fn from_markdown(markdown: &str) -> Self
Create a fragment from Markdown. The fragment is a whole text: see
from_djot.
Sourcepub fn from_djot(djot: &str) -> Self
pub fn from_djot(djot: &str) -> Self
Create a fragment from djot markup. Paste always uses the lossless
default crate::DjotImportOptions; per-feature selection is exposed on
the document-level import path (TextDocument::set_djot_with_options).
The fragment is a whole text: inserted over a selection holding the whole of a
text, it reads as the same Djot loaded, even as a single plain paragraph (see
TextCursor::insert_fragment).
Sourcepub fn from_document(doc: &TextDocument) -> Result<Self>
pub fn from_document(doc: &TextDocument) -> Result<Self>
Create a fragment from an entire document. The fragment is a whole text: see
from_djot.
Sourcepub fn to_plain_text(&self) -> &str
pub fn to_plain_text(&self) -> &str
Export the fragment as plain text.
Sourcepub fn to_markdown(&self) -> String
pub fn to_markdown(&self) -> String
Export the fragment as Markdown.