MarkdownExtension

class MarkdownExtension(val editorState: TextEditorState, initialConfiguration: MarkdownConfiguration = MarkdownConfiguration.DEFAULT, var imageProvider: ImageProvider? = null)(source)

An extension to TextEditorState that provides markdown functionality. This separates markdown concerns from the core text editor functionality.

Constructors

Link copied to clipboard
constructor(editorState: TextEditorState, initialConfiguration: MarkdownConfiguration = MarkdownConfiguration.DEFAULT, imageProvider: ImageProvider? = null)

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard

Serializes the document to markdown.

Link copied to clipboard
fun headerLevel(line: Int): Int?

The heading level (1..6) of line, or null when the line is not a heading. Reads the line's HeaderSpanStyle span, so the answer is independent of the display styles in the active configuration.

Link copied to clipboard
fun importMarkdown(markdownText: String)
Link copied to clipboard

Returns whether line is currently rendered as a blockquote.

Link copied to clipboard

Returns whether line is currently rendered as a bullet-list item.

Link copied to clipboard
fun isCodeFence(line: Int): Boolean

Returns whether line is currently rendered as a fenced code line.

Link copied to clipboard

Returns whether line is currently rendered as an ordered-list item.

Link copied to clipboard
fun linkAt(position: CharLineOffset): String?

The destination URL of the link covering position, or null when the position is not inside a link.

Link copied to clipboard
fun setLink(range: TextEditorRange, url: String)

Makes range a hyperlink to url: bakes the configuration's link display style over the text and attaches the LinkSpanStyle that carries the destination through serialization. Both go through the undoable edit pipeline as two recorded operations (the display style and the span), so fully reverting a setLink takes two undo steps.

Link copied to clipboard

Adds blockquote rendering (left bar + indented text) to each line in lines that doesn't already have it; removes it from lines that do. Mixed selections enable on every line for predictable toolbar behavior.

Link copied to clipboard

Adds bullet-list rendering (gutter dot + hanging indent) to each line in lines that doesn't already have it; removes it from lines that do. Mixed selections enable on every line for predictable toolbar behavior.

Link copied to clipboard

Adds fenced-code rendering (monospace text + tinted card with a hairline border) to each line in lines that doesn't already have it; removes it from lines that do. Mixed selections enable on every line for predictable toolbar behavior. Code fences demote any blockquote/list on the same line — the four block styles can't coexist visually.

Link copied to clipboard
fun toggleHeader(lines: IntRange, level: Int)

Makes each line in lines a heading of level (1..6), or removes the heading where every targeted line already carries that exact level. Applying over a different heading level swaps the level. The heading is semantic: it survives configuration changes and exports as # markers regardless of the display style in force. One atomic undo entry covers the whole toggle.

Link copied to clipboard

Adds ordered-list rendering (gutter numeral + hanging indent) to each line in lines that doesn't already have it; removes it from lines that do. Mixed selections enable on every line for predictable toolbar behavior. Numbering is recomputed automatically based on contiguous-run position.