class TUI::MarkdownEdit

Overview

A TextEdit that highlights Markdown syntax as you type — headings, list markers, and blockquote prefixes (line-prefix syntax, detected from one line alone), plus bold/italic/strikethrough/inline-code spans within each line. Deliberately does NOT track multi-line constructs like fenced code blocks — that would require re-parsing surrounding lines on every keystroke, a much heavier cost for a live editor than a read-only viewer pays once per render. Reuses Markdown::Layout::Config's existing heading/list/quote style choices so a highlighted line looks consistent with how MarkdownView would eventually render the same content, rather than inventing a second, unrelated palette.

Inline spans are found with a small local scanner rather than reusing Markdown::Inline.parse — that scanner strips delimiters (**bold** becomes the 4-character-shorter "bold") for MarkdownView, a read-only renderer where the raw source never needs to stay editable. TextEdit's #highlighter contract requires every character of the input line back, unchanged, just re-styled (see TextEdit's #highlighter doc comment) — an editor needs **/` to stay visible and at their original column so the cursor and edits still land in the right place. #inline_cells below styles delimiters (dimmed) and their contents (bold/italic/code) separately without ever removing a character.

This is TextEdit's syntax-agnostic #highlighter hook wired to one particular syntax, not a special case TextEdit itself knows about — any other syntax could plug in the same way via its own subclass.

Defined in:

tui/widgets/markdown_edit.cr

Constant Summary

BLOCKQUOTE_PREFIX = /^(>\s?)/
HEADING_PREFIX = /^(\#{1,6})(\s+)/
LIST_PREFIX = /^(\s*)([-*+]|\d+\.)(\s+)/

Constructors

Instance Method Summary

Instance methods inherited from class TUI::TextEdit

content_size : Int32 content_size, handle_click(local_row : Int32, local_col : Int32, scroll : ScrollControl) : Bool handle_click, handle_key(ev : KeyEvent, scroll : ScrollControl) : Bool handle_key, highlighter : String -> Array(Cell) | Nil highlighter, highlighter=(highlighter : String -> Array(Cell) | Nil) highlighter=, render_content(buffer : Buffer, scroll : ScrollControl) : Nil render_content, status_hint : String status_hint, title : String title, title=(title : String) title=, value : String value, wrap_marker_style : Style wrap_marker_style, wrap_marker_style=(wrap_marker_style : Style) wrap_marker_style=

Constructor methods inherited from class TUI::TextEdit

new(text : String = "") new

Instance methods inherited from module TUI::Scrollable

content_size : Int32 content_size, focus_if(condition : Bool) : Nil focus_if, focused=(focused : Bool) focused=, focused? : Bool focused?, handle_click(local_row : Int32, local_col : Int32, scroll : ScrollControl) : Bool handle_click, handle_key(ev : KeyEvent, scroll : ScrollControl) : Bool handle_key, header_rows : Int32 header_rows, render_content(buffer : Buffer, scroll : ScrollControl) : Nil render_content, status_hint : String status_hint, title : String title

Constructor Detail

def self.new(text : String = "", config : Markdown::Layout::Config = Markdown::Layout::Config.new) #

[View source]

Instance Method Detail

def bold_style : Style #

[View source]
def bold_style=(bold_style : Style) #

[View source]
def code_style : Style #

[View source]
def code_style=(code_style : Style) #

[View source]
def delimiter_style : Style #

[View source]
def delimiter_style=(delimiter_style : Style) #

[View source]
def italic_style : Style #

[View source]
def italic_style=(italic_style : Style) #

[View source]
def strikethrough_style : Style #

[View source]
def strikethrough_style=(strikethrough_style : Style) #

[View source]