-
Notifications
You must be signed in to change notification settings - Fork 0
Content Model
Namespace: ParentElement.RichText.Core.Content
The content model is a read-only, serializable representation of a document's structure returned by DocumentReader. It mirrors the internal TextDocument in a flat, framework-independent form suitable for export, clipboard, and custom rendering.
DocumentReader
└── IEnumerable<ContentBlock>
├── ContentBlockType (Paragraph)
└── IEnumerable<ContentRun>
├── Text run → Text + IStyle
├── Image run → ImageData (PNG) + ImageWidth + ImageHeight
└── Table run → ContentTable
├── ContentTableCell[][]
│ └── IReadOnlyList<ContentBlock> (recursive)
└── layout metadata
Represents a single paragraph (or paragraph-equivalent) in the document.
public class ContentBlock| Property | Type | Description |
|---|---|---|
Type |
ContentBlockType |
Structural type (currently always Paragraph) |
Runs |
IEnumerable<ContentRun> |
Inline runs that make up this block's content |
Alignment |
TextAlignment? |
Horizontal alignment, or null to inherit |
ListType |
ListType? |
Bullet or numbered list marker, or null
|
ListLevel |
int? |
Zero-based nesting depth for list items |
BlockIndent |
float? |
Absolute left indent in pixels, or null
|
LineSpacing |
float? |
Line height multiplier, or null for the default (1.0) |
public enum ContentBlockType { Paragraph }| Value | Description |
|---|---|
Paragraph |
A standard paragraph block |
A single styled span within a ContentBlock. A run contains either text, an inline image, or an inline table — never more than one.
public class ContentRun| Property | Type | Description |
|---|---|---|
Text |
string |
The text content. null for image and table runs |
Style |
IStyle |
Character style applied to this run |
IsImage |
bool |
true when ImageData is non-null |
ImageData |
byte[] |
PNG-encoded image bytes (image runs only) |
ImageWidth |
float |
Display width in pixels (image runs only) |
ImageHeight |
float |
Display height in pixels (image runs only) |
IsTable |
bool |
true when Table is non-null |
Table |
ContentTable |
Table content data (table runs only) |
// Text run
var isText = !run.IsImage && !run.IsTable;
// Image run
if (run.IsImage)
{
var image = SKImage.FromEncodedData(run.ImageData);
// render at run.ImageWidth × run.ImageHeight
}
// Table run
if (run.IsTable)
{
foreach (var row in run.Table.Cells)
foreach (var cell in row)
if (cell != null) ProcessCell(cell);
}A snapshot of an inline table's layout and content, embedded inside a ContentRun.
public class ContentTable| Property | Type | Description |
|---|---|---|
Rows |
int |
Number of rows |
Cols |
int |
Number of columns |
TotalWidth |
float |
Total rendered width in pixels |
ColWidths |
float[] |
Per-column content widths (excluding borders) |
RowHeights |
float[] |
Per-row heights (including cell padding) |
CellPadding |
float |
Padding applied on each side of a cell |
BorderStyle |
string |
CSS-style string: "none", "solid", "dashed", or "dotted"
|
BorderWidth |
float |
Border thickness in pixels |
BorderColor |
string |
CSS hex color string, e.g. "#C0C0C0"
|
Cells |
ContentTableCell[][] |
Row-major grid; null entries indicate spanned slots |
A single cell snapshot within a ContentTable.
public class ContentTableCell| Property | Type | Default | Description |
|---|---|---|---|
RowSpan |
int |
1 |
Number of rows this cell spans |
ColSpan |
int |
1 |
Number of columns this cell spans |
IsHeader |
bool |
false |
Whether this is a header cell |
BackgroundColor |
string |
null |
CSS hex color, or null for no explicit background |
Content |
IReadOnlyList<ContentBlock> |
— | The blocks nested inside this cell |
Provides structured, read-only access to the underlying TextDocument. Obtain an instance via IDocumentController.GetContentReader().
public class DocumentReaderpublic DocumentReader(TextDocument document)| Property | Type | Description |
|---|---|---|
Document |
TextDocument |
The underlying RichTextKit document |
| Method | Returns | Description |
|---|---|---|
GetContent() |
IEnumerable<ContentBlock> |
All content blocks in the document |
GetContent(TextRange?) |
IEnumerable<ContentBlock> |
Content blocks clipped to a selection range |
GetStyles() |
IEnumerable<StyleInfo> |
All distinct styles used, starting with the document default |
var reader = editor.GetContentReader();
// Iterate all document content
foreach (var block in reader.GetContent())
{
foreach (var run in block.Runs)
{
if (run.IsImage)
ExportImage(run.ImageData, run.ImageWidth, run.ImageHeight);
else if (!run.IsTable)
Console.Write(run.Text);
}
Console.WriteLine();
}
// Read only the current selection
var selection = editor.GetContentReader().GetContent(selectionRange);See also: IDocumentController · Tables · IO