moui_markdown

    Reusable Markdown editing chrome components for MoUI (outline, find/replace, format palette, document info, HTML export)

    moui
    markdown
    editor
    addon
    Download zip
    Author
    Version
    0.9.1
    License
    Apache-2.0
    Last updated
    3 days ago
    Downloads
    644

    wzzc-dev/moui_markdown does not have a README file

    MarkdownDocumentInfo

    pub(all) struct MarkdownDocumentInfo {
    character_count : Int
    heading_count : Int
    paragraph_count : Int
    list_item_count : Int
    task_count : Int
    checked_task_count : Int
    quote_count : Int
    code_block_count : Int
    table_count : Int
    link_count : Int
    image_count : Int
    footnote_reference_count : Int
    footnote_definition_count : Int
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Block and inline statistics for a Markdown document.

    MarkdownDocumentInfo::equal

    automatically derived

    MarkdownDocumentInfo::not_equal

    automatically derived

    MarkdownDocumentInfo::to_json

    automatically derived

    MarkdownDocumentInfo::to_repr

    automatically derived

    MarkdownFindOptions

    pub(all) struct MarkdownFindOptions {
    case_sensitive : Bool
    whole_word : Bool
    regex : Bool
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Find/replace options. Defaults are case-insensitive substring matching.

    pub(all): consumers outside this package must be able to build non-default option sets (the find-bar toggles write these fields).

    MarkdownFindOptions::default

    MarkdownFindOptions::equal

    automatically derived

    MarkdownFindOptions::not_equal

    automatically derived

    MarkdownFindOptions::to_json

    automatically derived

    MarkdownFindOptions::to_repr

    automatically derived

    MarkdownFindSeed

    A find query seeded from the caret word: query is the text, range the selection to activate once the find bar opens.

    MarkdownFindSeed::equal

    automatically derived

    MarkdownFindSeed::not_equal

    fn MarkdownFindSeed::not_equal(x : MarkdownFindSeed, y : MarkdownFindSeed) -> Bool
    automatically derived

    MarkdownFindSeed::to_json

    automatically derived

    MarkdownFindSeed::to_repr

    automatically derived

    MarkdownFormatBubbleAction

    pub(all) enum MarkdownFormatBubbleAction {
    Bold
    Italic
    Strikethrough
    Code
    Highlight
    Link
    Heading1
    Heading2
    UnorderedList
    Quote
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    A formatting action offered by the selection bubble.

    MarkdownFormatBubbleAction::equal

    automatically derived

    MarkdownFormatBubbleAction::not_equal

    automatically derived

    MarkdownFormatBubbleAction::to_json

    automatically derived

    MarkdownFormatBubbleAction::to_repr

    automatically derived

    MarkdownMenuItem

    pub(all) struct MarkdownMenuItem {
    action : String
    label : String
    group : String
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    One row of the editor surface's context menu.

    The package owns the catalog — which commands a surface offers, in which separator bucket, under which label — while the app owns the presentation and maps action to its own message. action is one of the canonical command words already used by the format palette and the editor keymap ("bold", "table-row", "move-block-up"), so the two catalogs never disagree about spelling.

    MarkdownMenuItem::equal

    automatically derived

    MarkdownMenuItem::not_equal

    fn MarkdownMenuItem::not_equal(x : MarkdownMenuItem, y : MarkdownMenuItem) -> Bool
    automatically derived

    MarkdownMenuItem::to_json

    automatically derived

    MarkdownMenuItem::to_repr

    automatically derived

    MarkdownPaletteItem

    pub(all) struct MarkdownPaletteItem {
    action : String
    label : String
    group : String
    shortcut : String
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    One quick-format palette entry.

    MarkdownPaletteItem::equal

    automatically derived

    MarkdownPaletteItem::not_equal

    automatically derived

    MarkdownPaletteItem::to_json

    automatically derived

    MarkdownPaletteItem::to_repr

    automatically derived

    markdown_active_outline_index

    fn markdown_active_outline_index(outline : Array[
    MarkdownEditorOutlineItem
    ], caret : Int) -> Int

    The index of the outline item containing caret (the last heading whose source start is at or before the caret), or -1 when no heading precedes it.

    markdown_command_from_palette_action

    fn markdown_command_from_palette_action(action : String) ->
    MarkdownEditorCommand
    ?

    Map a palette action id to its editor command. Actions with no engine command (view toggles, export, files, appearance) return None.

    markdown_document_info_from_parts

    fn markdown_document_info_from_parts(source : String, blocks : Array[
    MarkdownEditorBlock
    ]) -> MarkdownDocumentInfo

    Compute document info from raw source + parsed editor blocks.

    markdown_document_info_from_session

    Compute document info from a live session.

    markdown_document_info_from_snapshot

    Compute document info from a snapshot.

    markdown_document_info_panel

    fn[Msg] markdown_document_info_panel(theme~ :
    Theme
    , info~ : MarkdownDocumentInfo, word_count~ : Int, line_count~ : Int, reading_time_label~ : String, height~ : Double, width? : Double, title? : String, words_label? : String, characters_label? : String, lines_label? : String, reading_label? : String, headings_label? : String, paragraphs_label? : String, list_items_label? : String, tasks_label? : String, quotes_label? : String, code_blocks_label? : String, tables_label? : String, links_label? : String, images_label? : String, footnotes_label? : String) ->
    View
    [Msg]

    The document-info inspector. Counts come from markdown_document_info_from_session/_from_snapshot; word/line/reading values are passed explicitly so snapshot-based hosts work too.

    markdown_editor_surface_menu_items

    fn markdown_editor_surface_menu_items(target~ :
    MarkdownEditorTarget
    , has_selection~ : Bool, in_task_item~ : Bool, has_openable_target~ : Bool) -> Array[MarkdownMenuItem]

    The commands the document surface offers for the current target.

    Membership follows what mature editors gate on rather than disabling rows: table commands appear only inside a table, open target only when something can be opened, inline formatting only with a selection, and the task toggle only inside a task item. App-only rows (save, export, find, panel toggles) are deliberately absent: they belong to the shell, not the markdown surface.

    markdown_find_active_index

    Index of the match exactly equal to the current selection, or -1.

    markdown_find_bar

    fn[Msg] markdown_find_bar(theme~ :
    Theme
    , query~ : String, replace_text~ : String, options~ : MarkdownFindOptions, status_label~ : String, on_query_input~ : (String) -> Msg, on_replace_input~ : (String) -> Msg, on_submit_query~ : Msg, on_submit_replace~ : Msg, on_toggle_case_sensitive~ : Msg, on_toggle_whole_word~ : Msg, on_toggle_regex~ : Msg, on_previous~ : Msg, on_next~ : Msg, on_replace_current~ : Msg, on_replace_all~ : Msg, on_close~ : Msg, width~ : Double, compact? : Bool, find_label? : String, replace_label? : String, search_placeholder? : String, replacement_placeholder? : String, replace_button_label? : String, replace_all_button_label? : String, match_case_tooltip? : String, whole_word_tooltip? : String, regex_tooltip? : String, previous_tooltip? : String, next_tooltip? : String, close_tooltip? : String, key_prefix? : String) ->
    View
    [Msg]

    The find/replace bar. status_label is normally markdown_find_status_label(query, matches, selection, options~), but any caller-composed label (e.g. localized text) works too.

    The bar is width wide and 42pt tall, matching MoMark's chrome slot.

    compact=true drops the inline "Find"/"Replace" captions (the fields keep their placeholders), narrows both fields and the status slot, and halves the row gap. The laid-out content drops from ~1130pt to ~750pt, so the bar fits a narrow window instead of clipping its trailing buttons. Layout only — every control stays present, and the widths stay fixed so the caller can still compute its own slot.

    markdown_find_compile_regex

    fn markdown_find_compile_regex(query : String, case_sensitive : Bool) ->
    Regex
    ?

    Compile query into a regex, wrapping case-insensitively when needed. Returns None for invalid patterns.

    markdown_find_live_update_index

    Index to keep active across a live find refresh: the match starting at the current selection start (stable while the end changes), else the next match.

    markdown_find_matches

    fn markdown_find_matches(source : String, query : String, options? : MarkdownFindOptions) -> Array[
    TextRange
    ]

    All matches of query in source, in document order.

    markdown_find_next_index

    Index of the next match at or after the selection end, wrapping to the first match.

    markdown_find_previous_index

    Index of the previous match ending at or before the selection start, wrapping to the last match.

    markdown_find_query_from_selection

    fn markdown_find_query_from_selection(source : String, selection :
    MarkdownEditorSelection
    ) -> String?

    The query to seed when the find bar opens over a non-empty single-line selection.

    markdown_find_seed_from_caret_word

    fn markdown_find_seed_from_caret_word(source : String, selection :
    MarkdownEditorSelection
    ) -> MarkdownFindSeed?

    The find seed around a collapsed caret: the ASCII word under or directly before the caret. Returns None when the caret is not on a word.

    markdown_find_status_label

    fn markdown_find_status_label(query : String, matches : Array[
    TextRange
    ], selection :
    MarkdownEditorSelection
    , options? : MarkdownFindOptions) -> String

    The find-bar status label: "Ready", "Invalid regex", "No match", or the active match position ("n/m").

    markdown_folded_outline

    Filter outline items to honor folded headings: a folded heading hides all subsequent items until the next heading at the same or higher level.

    markdown_format_bubble

    fn[Msg] markdown_format_bubble(on_action~ : (MarkdownFormatBubbleAction) -> Msg, caret~ :
    Rect
    , viewport_height~ : Double, width? : Double, height? : Double) ->
    View
    [Msg]

    A floating formatting bubble anchored to the caret line.

    The caller owns when it shows (a non-empty selection) and what each action means; this function only builds the row and positions it over the editor. Placement mirrors MoMark's parked overlay: measured at viewport size, the bubble is painted at markdown_format_bubble_rect.

    markdown_format_bubble_actions

    fn markdown_format_bubble_actions() -> Array[MarkdownFormatBubbleAction]

    The bubble's buttons, in display order.

    markdown_format_bubble_glyph

    fn markdown_format_bubble_glyph(action : MarkdownFormatBubbleAction) -> String

    Short button text. The glyphs match the ones the editor chrome has always shown, so the bubble reads the same as the toolbar.

    markdown_format_bubble_label

    fn markdown_format_bubble_label(action : MarkdownFormatBubbleAction) -> String

    Tooltip and accessibility label for a bubble button.

    markdown_format_bubble_rect

    fn markdown_format_bubble_rect(caret :
    Rect
    , width? : Double, height? : Double, viewport_height~ : Double) ->
    Rect

    Place the bubble above the caret line, flip it below when it would leave the viewport, then clamp it inside the viewport.

    caret is the caret line's rect in viewport space. Only the vertical axis is clamped: the caller's contract carries the viewport height, not its width, so a bubble near a side edge is centred on the caret and left to the caller's overlay clip.

    markdown_format_palette

    fn[Msg] markdown_format_palette(theme~ :
    Theme
    , query~ : String, items~ : Array[MarkdownPaletteItem], on_query_input~ : (String) -> Msg, on_submit~ : Msg, on_action~ : (String) -> Msg, on_done~ : Msg, width~ : Double, title? : String, filter_placeholder? : String, done_label? : String, empty_label? : String, key_prefix? : String) ->
    View
    [Msg]

    The quick-format palette overlay. items is normally markdown_format_palette_filtered_items(query); callers may pass a custom catalog. on_action receives the selected action id (see markdown_command_from_palette_action).

    markdown_format_palette_filtered_items

    fn markdown_format_palette_filtered_items(query : String) -> Array[MarkdownPaletteItem]

    Case-insensitive substring filter over label/group/shortcut. A blank query returns the full catalog.

    markdown_format_palette_items

    fn markdown_format_palette_items() -> Array[MarkdownPaletteItem]

    The full quick-format command catalog, in display order.

    markdown_format_palette_matches

    fn markdown_format_palette_matches(item : MarkdownPaletteItem, needle : String) -> Bool

    Whether a (already lowercased) needle matches an entry.

    markdown_html_blocks

    fn markdown_html_blocks(blocks : Array[
    MarkdownEditorBlock
    ]) -> String

    Render block-level HTML for parsed editor blocks.

    markdown_html_document

    fn markdown_html_document(snapshot :
    MarkdownEditorSnapshot
    , title : String) -> String

    Render a full standalone HTML document from a snapshot.

    markdown_html_escape_attribute

    fn markdown_html_escape_attribute(text : String) -> String

    Escape &, <, >, ", ' for HTML attribute values.

    markdown_html_escape_text

    fn markdown_html_escape_text(text : String) -> String

    Escape &, <, > for HTML text content.

    markdown_html_inlines

    fn markdown_html_inlines(inlines : Array[
    MarkdownInline
    ]) -> String

    Render inline-level HTML for parsed inlines.

    markdown_next_match_after_replacement

    fn markdown_next_match_after_replacement(matches : Array[
    TextRange
    ], replaced_start : Int, replacement_end : Int) ->
    TextRange
    ?

    The match to activate after replacing [replaced_start, replacement_end): the first match at/after the replacement, else the first one before it.

    markdown_outline_indent_width

    fn markdown_outline_indent_width(level : Int) -> Double

    The indent width in points for a heading at level (12pt per level below the first).

    markdown_outline_item_is_active

    True when item is the outline entry at active_index in full_outline (identity by source start, so folding keeps the highlight attached).

    markdown_outline_label

    The bounded outline label for an item, e.g. "H2 Install". Titles longer than 24 characters are truncated to 21 + "..."; empty titles become "Untitled".

    markdown_outline_panel

    fn[Msg] markdown_outline_panel(theme~ :
    Theme
    , outline~ : Array[
    MarkdownEditorOutlineItem
    ], folded_starts~ : Array[Int], caret~ : Int, on_jump~ : (Int) -> Msg, on_toggle_fold~ : (Int) -> Msg, height~ : Double, width? : Double, title? : String, empty_label? : String) ->
    View
    [Msg]

    The outline inspector for a live session. folded_starts lists heading source_starts whose children are hidden; rows jump via on_jump and toggle folding via on_toggle_fold.

    markdown_outline_truncate_title

    fn markdown_outline_truncate_title(title : String) -> String

    Truncate a heading title to the outline label budget.

    markdown_replace_all_matches

    fn markdown_replace_all_matches(source : String, matches : Array[
    TextRange
    ], replacement : String) -> String

    Replace all matches in a single pass. Matches must be sorted and non-overlapping; out-of-order/ranges past the end are clamped and skipped.

    markdown_replace_source_range

    fn markdown_replace_source_range(source : String, range :
    TextRange
    , replacement : String) -> String

    Replace one character-index range with replacement.

    markdown_session_reading_label

    fn markdown_session_reading_label(session :
    MarkdownDocumentSession
    ) -> String

    "N words / M lines / T min" reading label from a session.

    markdown_session_reading_time_short_label

    fn markdown_session_reading_time_short_label(session :
    MarkdownDocumentSession
    ) -> String

    The compact reading reference ("<1 min"/"1 min"/"N min") from a session.

    markdown_snapshot_reading_label

    fn markdown_snapshot_reading_label(snapshot :
    MarkdownEditorSnapshot
    ) -> String

    "N words / M lines / T min" reading label from a snapshot.

    markdown_snapshot_reading_time_short_label

    fn markdown_snapshot_reading_time_short_label(snapshot :
    MarkdownEditorSnapshot
    ) -> String

    The compact reading reference from a snapshot.