Package-level declarations

Everything the writer exposes: the RtfWriter / writeRtf styled-model serializer, the MarkdownToRtf / convertMarkdownToRtf converter, and the rich RtfDocument authoring model with RtfDocumentWriter.

Types

Link copied to clipboard

Converts a small Markdown subset into a StyledDocument, then to RTF via RtfWriter.

Link copied to clipboard

Horizontal paragraph alignment. Left is the RTF default and emits no control word.

Link copied to clipboard
sealed interface RtfBlock

A block-level element in an RtfDocument.

Link copied to clipboard
data class RtfBookmark(val name: String, val content: List<RtfInline>) : RtfInline

A named bookmark wrapping content, the jump target for a RtfHyperlinkKind.Bookmark link.

Link copied to clipboard
data class RtfBorder(val style: RtfBorderStyle = RtfBorderStyle.Single, val widthTwips: Int = 10)

A paragraph border edge.

Link copied to clipboard

A line style for an RtfBorder.

Link copied to clipboard
data class RtfColor(val red: Int, val green: Int, val blue: Int)

An RGB color usable by RtfSpanStyle. Colors are referenced by value; the writer collects every referenced color into the \colortbl (index 0 is reserved for the document default "auto" color) and assigns the \cfN indices.

Link copied to clipboard
data class RtfDocument(val blocks: List<RtfBlock>, val defaultFont: RtfFont, val defaultFontSizeHalfPoints: Int = 24, val info: RtfInfo? = null, val generator: String? = null, val codePage: Int = 1252, val defaultLanguage: Int = 1033)

A rich, strongly-typed RTF document model for authoring arbitrarily complex output, the builder-style counterpart to StyledDocument's minimal round-trip model. Construct one directly and serialize it with RtfDocumentWriter.

Link copied to clipboard

Serializes an RtfDocument to a charset-free RTF string.

Link copied to clipboard
data class RtfFont(val name: String, val family: RtfFontFamily = RtfFontFamily.Nil, val charset: Int = 0)

A font usable by RtfDocument. Fonts are referenced by value from an RtfSpanStyle; the writer collects every referenced font (plus the document default) into the \fonttbl and assigns the \fN indices, so callers never juggle indices themselves.

Link copied to clipboard

The RTF font-family class emitted in the font table (\froman, \fmodern, …).

Link copied to clipboard
data class RtfHyperlink(val target: String, val content: List<RtfInline>, val kind: RtfHyperlinkKind = RtfHyperlinkKind.Url) : RtfInline

A hyperlink field. For RtfHyperlinkKind.Url the target is an external URL; for RtfHyperlinkKind.Bookmark it is the name of an RtfBookmark elsewhere in the document. The visible, clickable text is the styled content (set underline/color on its runs to taste).

Link copied to clipboard

Whether an RtfHyperlink points at an external URL or an in-document RtfBookmark.

Link copied to clipboard
data class RtfInfo(val title: String? = null, val author: String? = null, val subject: String? = null, val company: String? = null)

Document metadata emitted in the {\info ...} group. Blank fields are omitted.

Link copied to clipboard
sealed interface RtfInline

A piece of inline content inside an RtfParagraph.

Link copied to clipboard
data object RtfLineBreak : RtfInline

A forced line break within a paragraph (\line).

Link copied to clipboard
data object RtfPageBreak : RtfBlock

Forces a page break before the following content (\page).

Link copied to clipboard
data class RtfParagraph(val content: List<RtfInline>, val style: RtfParagraphStyle = RtfParagraphStyle.Default) : RtfBlock

A paragraph: styled inline content plus paragraph-level formatting.

Link copied to clipboard
data class RtfParagraphStyle(val alignment: RtfAlignment = RtfAlignment.Left, val spaceBeforeTwips: Int = 0, val spaceAfterTwips: Int = 0, val firstLineIndentTwips: Int = 0, val leftIndentTwips: Int = 0, val keepWithNext: Boolean = false, val bottomBorder: RtfBorder? = null)

Paragraph-level formatting. All measurements are in twips (twentieths of a point; 1440 = 1 inch); firstLineIndentTwips may be negative for a hanging indent.

Link copied to clipboard
data class RtfSpanStyle(val bold: Boolean = false, val italic: Boolean = false, val underline: Boolean = false, val strikethrough: Boolean = false, val superscript: Boolean = false, val subscript: Boolean = false, val font: RtfFont? = null, val fontSizeHalfPoints: Int? = null, val color: RtfColor? = null)

Character-level formatting for an RtfTextRun. A null font, fontSizeHalfPoints or color means "inherit the document/paragraph default" — the writer emits the corresponding control word only when the field is set.

Link copied to clipboard
data object RtfTab : RtfInline

A tab (\tab).

Link copied to clipboard
data class RtfTextRun(val text: String, val style: RtfSpanStyle = RtfSpanStyle.Default) : RtfInline

A contiguous run of text sharing a single style.

Link copied to clipboard
class RtfWriter

Serializes a StyledDocument to a charset-free RTF string.

Functions

Link copied to clipboard

Convenience entry point: parse markdown and serialize the resulting document to RTF.

Link copied to clipboard

Convenience top-level entry point equivalent to RtfWriter().write(document).

Link copied to clipboard

Convenience top-level entry point equivalent to RtfDocumentWriter().write(document).