Skip to main content

core.markdownview

local markdownview = require "core.markdownview"

_layout_generation

(field) _layout_generation: integer

_layout_thread_key

(field) _layout_thread_key: table

_parse_generation

(field) _parse_generation: integer

_parse_thread_key

(field) _parse_thread_key: table

_ready_callbacks

(field) _ready_callbacks: table

_text_chunks

(field) _text_chunks: table

_text_length

(field) _text_length: integer

_text_suffix

(field) _text_suffix: string

append_stale_frame

(field) append_stale_frame: unknown

async_layout_threshold

(field) async_layout_threshold: integer

async_parse_threshold

(field) async_parse_threshold: integer

blocks

(field) blocks: table[]

context

(field) context: string

current_scale

(field) current_scale: number

cursor

(field) cursor: string

estimated_block_height

(field) estimated_block_height: number?

font

(field) font: (renderer.font)?

font_cache

(field) font_cache: table?

footnotes

(field) footnotes: table

h_scrollbar

(field) h_scrollbar: core.scrollbar

Scrollable viewport indicator with draggable thumb. Supports both vertical and horizontal orientation with configurable alignment. Uses a "normal" coordinate system internally that treats all scrollbars as vertical-end-aligned, then transforms to the actual orientation/alignment.


(field) hovered_link_url: string?

hovered_scrollbar

(field) hovered_scrollbar: boolean

image_cache

(field) image_cache: table<string, table>

last_doc_change_id

(field) last_doc_change_id: integer?

layout

(field) layout: table?

layouting

(field) layouting: boolean

linked_doc

(field) linked_doc: (core.doc)?

parsing

(field) parsing: boolean

partial_commit_stale_frame

(field) partial_commit_stale_frame: unknown

partial_layout

(field) partial_layout: table|nil

partial_text

(field) partial_text: string

path

(field) path: string?

pending_h_scrollable_size

(field) pending_h_scrollable_size: unknown

pending_layout

(field) pending_layout: table

pending_scrollable_size

(field) pending_scrollable_size: unknown

position

(field) position: core.view.position

preserved_scroll

(field) preserved_scroll: unknown

references

(field) references: table<string, string>

scroll

(field) scroll: core.view.scroll

scrollable

(field) scrollable: boolean

selecting

(field) selecting: boolean?

selection_anchor

(field) selection_anchor: integer?

selection_cursor

(field) selection_cursor: integer?

size

(field) size: core.view.position

stale_layout

(field) stale_layout: unknown

super

(field) super: core.view

Base view.


text

(field) text: string

title

(field) title: string?

v_scrollbar

(field) v_scrollbar: core.scrollbar

Scrollable viewport indicator with draggable thumb. Supports both vertical and horizontal orientation with configurable alignment. Uses a "normal" coordinate system internally that treats all scrollbars as vertical-end-aligned, then transforms to the actual orientation/alignment.


virtual_block_cache

(field) virtual_block_cache: table

virtual_layout_cache

(field) virtual_layout_cache: unknown

virtual_metrics

(field) virtual_metrics: unknown

virtual_overscan_px

(field) virtual_overscan_px: number?

virtualized

(field) virtualized: boolean

core.markdownview.source

doc

(field) doc: (core.doc)?

estimated_block_height

(field) estimated_block_height: number?

font

(field) font: (renderer.font)?

linked_doc

(field) linked_doc: (core.doc)?

name

(field) name: string?

path

(field) path: string?

text

(field) text: string?

title

(field) title: string?

virtual_overscan_px

(field) virtual_overscan_px: number?

virtualized

(field) virtualized: boolean?

core.markdownview.state

path

(field) path: string

scroll

(field) scroll: { x: number, y: number }

__index

function core.markdownview.__index(self: core.markdownview, key: any)
-> string|unknown

append_markdown

function

from_state

function core.markdownview.from_state(state: core.markdownview.state)
-> (core.markdownview)?

Restores a file-backed markdown preview from saved state.


is_supported

function core.markdownview.is_supported(path: string)
-> boolean

Checks whether a file path should be opened by the markdown preview.


parse_blocks

function core.markdownview.parse_blocks(text: string)
-> table[]

Parses markdown text into the intermediate block structure used by the view.


resolve_color

function

__call

(method) core.object:__call(...any)
-> obj: core.object

Metamethod allowing class to be called like a constructor. Enables syntax: local obj = MyClass(args) instead of MyClass:new(args) Automatically creates instance and calls new() with provided arguments.

@return obj — The new instance of the class


__tostring

(method) core.markdownview:__tostring()
-> string

append_text

(method) core.markdownview:append_text(text?: string)
-> incremental: boolean

Appends markdown to the preview, reparsing only the appended blocks when safe.

Markdown can continue the previous block across a line boundary. When the existing text and appended text do not meet at a blank block boundary, this falls back to set_text so the rendered document remains equivalent.

@return incremental — True when only appended blocks were parsed.


clamp_scroll_position

(method) core.view:clamp_scroll_position()

Clamp scroll position to valid range (0 to max scrollable size). Called automatically by update(). Override get_scrollable_size() to customize.


clear_partial_text

(method) core.markdownview:clear_partial_text()

Clears temporary plain text rendered after the parsed markdown document.


clear_selection

(method) core.markdownview:clear_selection()

Clears the active text selection.


commit_partial_text

(method) core.markdownview:commit_partial_text(markdown_text?: string)
-> incremental: boolean

Commits the partial text by appending final markdown to the document.

@return incremental — True when only appended blocks were parsed.


copy_selection

(method) core.markdownview:copy_selection()
-> copied: boolean

Copies the selected rendered text to the system clipboard.


draw

(method) core.markdownview:draw()

Draws the markdown preview contents and scrollbars.


draw_at

(method) core.markdownview:draw_at(x: number, y: number, width: number, height: number, background?: renderer.color, show_scrollbars?: boolean)

Draws the markdown contents at an arbitrary rectangle.


draw_background

(method) core.view:draw_background(color: renderer.color)

Draw a solid background color for the entire view. Commonly called at the start of draw() methods.


draw_scrollbar

(method) core.view:draw_scrollbar()

Draw the view's scrollbars. Commonly called at the end of draw() methods.


ensure_image_entry

(method) core.markdownview:ensure_image_entry(block: table)
-> table

Returns an image cache entry for the given markdown image block.


ensure_layout

(method) core.markdownview:ensure_layout()
-> table

Builds the render command list for the current view width.


ensure_partial_layout

(method) core.markdownview:ensure_partial_layout()
-> table?

Builds the render command list for temporary partial text.


extend

(method) core.object:extend()
-> cls: core.object

Create a new class that inherits from this one. Returns a new class with this class as its parent. Example: local MyClass = Object:extend()

@return cls — The new class table


extends

(method) core.object:extends(T: any)
-> extends: boolean

Check if object inherits from the given type (inheritance-aware). Use this to check class hierarchy. Example: view:extends(View) returns true for View and all subclasses

@param T — Class to check inheritance from

@return extends — True if object is T or inherits from T


get_content_bounds

(method) core.view:get_content_bounds()
-> x1: number
2. y1: number
3. x2: number
4. y2: number

Get the content bounds in content coordinates (accounting for scroll).

@return x1 — Left edge

@return y1 — Top edge

@return x2 — Right edge

@return y2 — Bottom edge


get_content_offset

(method) core.view:get_content_offset()
-> x: number
2. y: number

Get the top-left corner of content area in screen coordinates. Accounts for scroll offset. Use for drawing content at correct position.

@return x — Screen x coordinate

@return y — Screen y coordinate


get_context_target_at

(method) core.markdownview:get_context_target_at(x: number, y: number)
-> { link_url: string?, image_url: string? }?

Returns a context-copy target under the given mouse position, if any.


get_font_cache

(method) core.markdownview:get_font_cache()
-> table

Builds and caches the fonts used by the markdown renderer.


get_h_scrollable_size

(method) core.markdownview:get_h_scrollable_size()
-> number

(method) core.markdownview:get_link_at(x: number, y: number)
-> string?

Returns the URL under the given mouse position, if any.


get_module

(method) core.view:get_module()
-> path: string?

Returns the module path of this view.

This method resolves the Lua module name that loaded the concrete view class (for example "core.view").

If the view class cannot be associated with any loaded module, nil is returned.


get_name

(method) core.markdownview:get_name()
-> string

get_rendered_size

(method) core.markdownview:get_rendered_size(width: number)
-> width: number
2. height: number

Returns the rendered size for the given outer width.


get_scaled_image

(method) core.markdownview:get_scaled_image(entry: table, max_width: number)
-> image: canvas?
2. width: number?
3. height: number?

Returns a scaled canvas for an image entry constrained to the given width.


get_scrollable_size

(method) core.markdownview:get_scrollable_size()
-> number

get_selected_text

(method) core.markdownview:get_selected_text()
-> string

Returns the selected rendered text.


get_state

(method) core.markdownview:get_state()
-> (core.markdownview.state)?

Returns the persisted view state for file-backed previews.


get_text

(method) core.markdownview:get_text()
-> text: string

Returns the full markdown source text, materializing appended chunks lazily.


get_text_position_at

(method) core.markdownview:get_text_position_at(x: number, y: number)
-> integer

Returns the selectable text position nearest to the given mouse position.


has_selection

(method) core.markdownview:has_selection()
-> boolean

Returns whether the preview has selected text.


invalidate_layout

(method) core.markdownview:invalidate_layout()

Invalidates the cached layout so it will be rebuilt on the next draw.


is

(method) core.object:is(T: any)
-> is_exact: boolean

Check if object is exactly of the given type (no inheritance check). Use this for strict type matching. Example: view:is(DocView) returns true only if view is a DocView, not a subclass

@param T — Class to check against

@return is_exact — True if object is exactly type T


is_class_of

(method) core.object:is_class_of(T: any)
-> is_instance: boolean

Check if the given object is exactly an instance of this class. Inverse of is() - checks if T is an instance of self. Example: DocView:is_class_of(obj) checks if obj is exactly a DocView

@param T — Object to check

@return is_instance — True if T is exactly an instance of this class


is_extended_by

(method) core.object:is_extended_by(T: any)
-> is_extended: boolean

Check if the given object/class inherits from this class. Inverse of extends() - checks if T is a subclass of self. Example: View:is_extended_by(DocView) checks if DocView inherits from View

@param T — Object or class to check

@return is_extended — True if T inherits from this class


is_ready

(method) core.markdownview:is_ready()
-> boolean

Returns whether markdown parsing and layout work is currently settled.


load

(method) core.markdownview:load(path: string)
-> loaded: boolean
2. errmsg: string?

Loads markdown contents from disk into the view.


load_image_from_path

(method) core.markdownview:load_image_from_path(entry: table, path: string)

Loads an image entry from a local file path.


move_towards

(method) core.view:move_towards(t: table, k: string|number, dest: number, rate?: number, name?: string)

Smoothly animate a value towards a destination. Use this for animations instead of direct assignment.

@param t — Table containing the value

@param k — Key in table

@param dest — Target value

@param rate — Animation speed (0-1, default 0.5, higher = faster)

@param name — Transition name (for config.disabled_transitions)


new

(method) core.markdownview:new(source?: string|core.markdownview.source, title?: string)

Constructor.


on_file_dropped

(method) core.view:on_file_dropped(filename: string, x: number, y: number)
-> consumed: boolean

Handle file drop events (drag and drop from OS). Override to handle dropped files. Return true to consume event.

@param filename — Absolute path to dropped file

@param x — Screen x where file was dropped

@param y — Screen y where file was dropped

@return consumed — True to consume event, false to propagate


on_ime_text_editing

(method) core.view:on_ime_text_editing(text: string, start: number, length: number)

Handle IME (Input Method Editor) text composition events. Override for IME support in text editors. Called during composition.

@param text — Composition text being edited

@param start — Start position of selection within composition

@param length — Length of selection within composition


on_mouse_left

(method) core.markdownview:on_mouse_left()

Clears hover state when the mouse leaves the preview.


on_mouse_moved

(method) core.markdownview:on_mouse_moved(x: number, y: number, dx: number, dy: number)
-> boolean?

on_mouse_pressed

(method) core.markdownview:on_mouse_pressed(button: string, x: number, y: number, clicks: integer)
-> boolean?

on_mouse_released

(method) core.markdownview:on_mouse_released(button: string, x: number, y: number)
-> boolean?

on_mouse_wheel

(method) core.view:on_mouse_wheel(y: number, x: number)
-> consumed: boolean?

Handle mouse wheel scroll events. Override for custom scroll behavior. Base implementation does nothing.

@param y — Vertical scroll delta; positive is "up"

@param x — Horizontal scroll delta; positive is "left"

@return consumed — True to consume event


on_scale_change

(method) core.markdownview:on_scale_change()

Clears cached font and layout data after a scale change.


on_text_input

(method) core.view:on_text_input(text: string)

Handle text input events (typing, IME composition). Override for text editing. Called after IME composition completes.

@param text — Input text (may be multiple characters)


on_touch_moved

(method) core.view:on_touch_moved(x: number, y: number, dx: number, dy: number, i: number)

Handle touch move events (touchscreen/trackpad gestures). Override for touch-specific behavior. Base implementation handles scrolling.

@param x — Current touch x coordinate

@param y — Current touch y coordinate

@param dx — Delta x since last position

@param dy — Delta y since last position

@param i — Touch finger/pointer index


(method) core.markdownview:open_link(url: string)

Opens a markdown link target, handling anchors, local files and external URLs.


refresh_from_doc

(method) core.markdownview:refresh_from_doc()

Refreshes preview contents from the bound document.


(method) core.markdownview:resolve_project_link(url: string)
-> string?

Resolves a markdown link to a project-local absolute path when possible.


scrollbar_dragging

(method) core.view:scrollbar_dragging()
-> dragging: boolean

Check if user is currently dragging either scrollbar.

@return dragging — True if scrollbar drag is in progress


scrollbar_hovering

(method) core.view:scrollbar_hovering()
-> hovering: boolean

Check if mouse is hovering over either scrollbar track.

@return hovering — True if mouse is over scrollbar


scrollbar_overlaps_point

(method) core.view:scrollbar_overlaps_point(x: number, y: number)
-> overlaps: boolean

Check if a screen point overlaps either scrollbar. Useful for determining cursor style or handling clicks.

@param x — Screen x coordinate

@param y — Screen y coordinate

@return overlaps — True if point is over vertical or horizontal scrollbar


set_font

(method) core.markdownview:set_font(font?: renderer.font)

Sets a fixed font object for all rendered markdown fonts.


(method) core.markdownview:set_hovered_link(url?: string)

Updates hover state and status-bar tooltip for links.


set_partial_text

(method) core.markdownview:set_partial_text(text?: string)

Sets temporary plain text rendered after the parsed markdown document.

The partial text is intended for streaming output. It is displayed literally and does not mutate the parsed markdown document until committed.


set_text

(method) core.markdownview:set_text(text?: string)

Replaces the preview text and reparses the markdown document.


start_remote_image_download

(method) core.markdownview:start_remote_image_download(entry: table)

Starts downloading a remote image used by the markdown document.


supports_text_input

(method) core.view:supports_text_input()
-> boolean

Whether this view accepts text input (enables IME). Override and return true for text editors and input fields.


try_close

(method) core.view:try_close(do_close: function)

Called when view is requested to close (e.g., tab close button). Override to show confirmation dialogs for unsaved changes. Example: core.command_view:enter("Save?", \{submit = do_close\})

@param do_close — Call this function to actually close the view


update

(method) core.markdownview:update()

Refreshes the preview when the bound document changes.


update_scrollbar

(method) core.view:update_scrollbar()

Update scrollbar positions and sizes. Called automatically by update(). Rarely needs to be called manually.


when_ready

(method) core.markdownview:when_ready(callback: fun(view: core.markdownview))

Runs a callback once current asynchronous parsing/layout work has settled.