Skip to content

Latest commit

 

History

History
947 lines (612 loc) · 31.4 KB

File metadata and controls

947 lines (612 loc) · 31.4 KB

src/ui/markdown.ml

Home · Files

Provides ui markdown facilities for this project.

Package: ui.markdown

Reachable from entry: yes

Imports

Declarations

_active_cached_markdown_doc

function _active_cached_markdown_doc(st)

Return the cached Markdown document for the active tab when valid.

Parameter Type Default Description
st dynamic st value consumed by this operation.

View source

_active_is_markdown

function _active_is_markdown(st)

Return true when the active tab displays Markdown content.

Parameter Type Default Description
st dynamic st value consumed by this operation.

View source

_apply_rendered_markdown_line_styles

function _apply_rendered_markdown_line_styles(st, doc)

Apply paragraph-level styles to rendered Markdown lines.

Parameter Type Default Description
st dynamic st value consumed by this operation.
doc dynamic doc value consumed by this operation.

View source

_apply_rendered_markdown_styles

function _apply_rendered_markdown_styles(st, doc)

Apply all rendered Markdown styles to the RichEdit control.

Parameter Type Default Description
st dynamic st value consumed by this operation.
doc dynamic doc value consumed by this operation.

View source

_clear_markdown_cache

function _clear_markdown_cache(st, idx)

Clear the cached Markdown render for a tab.

Parameter Type Default Description
st dynamic st value consumed by this operation.
idx dynamic idx value consumed by this operation.

View source

_editor_display_text

function _editor_display_text(text)

Convert internal editor text to the display form expected by RichEdit.

Parameter Type Default Description
text dynamic Text consumed by the operation.

View source

_empty_markdown_doc

function _empty_markdown_doc()

Return an empty Markdown document used as a non-void cache sentinel.

View source

_ensure_markdown_cache_slots

function _ensure_markdown_cache_slots(st)

Ensure the Markdown render cache matches the open tab list.

Parameter Type Default Description
st dynamic st value consumed by this operation.

View source

_is_markdown_path

function _is_markdown_path(path)

Return true when a path names a Markdown document.

Parameter Type Default Description
path dynamic Path of the file or directory used by the operation.

View source

_jump_to_markdown_anchor

function _jump_to_markdown_anchor(st, link_target)

Scroll the editor so a Markdown anchor is aligned near the top.

Parameter Type Default Description
st dynamic st value consumed by this operation.
link_target dynamic link_target value consumed by this operation.

View source

_markdown_anchor_from_target

function _markdown_anchor_from_target(link_target)

Extract an anchor name from a Markdown link target.

Parameter Type Default Description
link_target dynamic link_target value consumed by this operation.

View source

_markdown_doc_for_active_tab

function _markdown_doc_for_active_tab(st, markdown)

Return the rendered Markdown document for the active tab.

Parameter Type Default Description
st dynamic st value consumed by this operation.
markdown dynamic markdown value consumed by this operation.

View source

_markdown_fence_language

function _markdown_fence_language(line)

Extract the language name from a Markdown fenced code block.

Parameter Type Default Description
line dynamic line value consumed by this operation.

View source

_markdown_fence_line

function _markdown_fence_line(line)

Return true when a Markdown line starts or ends a fenced code block.

Parameter Type Default Description
line dynamic line value consumed by this operation.

View source

_markdown_link_at_doc

function _markdown_link_at_doc(doc, char_pos)

Return the Markdown link covering a document offset.

Parameter Type Default Description
doc dynamic doc value consumed by this operation.
char_pos dynamic char_pos value consumed by this operation.

View source

_markdown_link_at_editor

function _markdown_link_at_editor(st, x, y)

Return the Markdown link under an editor mouse position.

Parameter Type Default Description
st dynamic st value consumed by this operation.
x dynamic Horizontal coordinate used by the operation.
y dynamic Vertical coordinate used by the operation.

View source

_markdown_span_color

function _markdown_span_color(st, kind)

Return the RichEdit color for a rendered Markdown span kind.

Parameter Type Default Description
st dynamic st value consumed by this operation.
kind dynamic kind value consumed by this operation.

View source

_markdown_span_size

function _markdown_span_size(kind)

Return the font size for a rendered Markdown span kind.

Parameter Type Default Description
kind dynamic kind value consumed by this operation.

View source

_md_add_anchor

function _md_add_anchor(anchors, name, start_pos)

Record a heading anchor and its rendered line location.

Parameter Type Default Description
anchors dynamic anchors value consumed by this operation.
name dynamic Name of the affected item.
start_pos dynamic start_pos value consumed by this operation.

View source

_md_add_code_spans

function _md_add_code_spans(spans, base_pos, raw, lang)

Style code block lines in rendered Markdown output.

Parameter Type Default Description
spans dynamic spans value consumed by this operation.
base_pos dynamic base_pos value consumed by this operation.
raw dynamic raw value consumed by this operation.
lang dynamic lang value consumed by this operation.

View source

_md_add_line_style

function _md_add_line_style(styles, start_pos, end_pos, kind)

Add a style override for a rendered Markdown line.

Parameter Type Default Description
styles dynamic styles value consumed by this operation.
start_pos dynamic start_pos value consumed by this operation.
end_pos dynamic end_pos value consumed by this operation.
kind dynamic kind value consumed by this operation.

View source

_md_add_link

function _md_add_link(links, start_pos, end_pos, link_target)

Record a clickable link range in rendered Markdown output.

Parameter Type Default Description
links dynamic links value consumed by this operation.
start_pos dynamic start_pos value consumed by this operation.
end_pos dynamic end_pos value consumed by this operation.
link_target dynamic link_target value consumed by this operation.

View source

_md_add_span

function _md_add_span(spans, start_pos, end_pos, kind)

Add a styled character span to a rendered Markdown document.

Parameter Type Default Description
spans dynamic spans value consumed by this operation.
start_pos dynamic start_pos value consumed by this operation.
end_pos dynamic end_pos value consumed by this operation.
kind dynamic kind value consumed by this operation.

View source

_md_anchor_slug

function _md_anchor_slug(text)

Convert heading text into a GitHub-style Markdown anchor slug.

Parameter Type Default Description
text dynamic Text consumed by the operation.

View source

_md_append_block_inline

function _md_append_block_inline(text, spans, links, prefix, src, kind)

Append a full logical Markdown line after parsing all inline markup.

Parameter Type Default Description
text dynamic Text consumed by the operation.
spans dynamic spans value consumed by this operation.
links dynamic links value consumed by this operation.
prefix dynamic prefix value consumed by this operation.
src dynamic src value consumed by this operation.
kind dynamic kind value consumed by this operation.

View source

_md_append_inline

function _md_append_inline(text, spans, links, prefix, src, kind)

Append text after applying inline Markdown formatting.

Parameter Type Default Description
text dynamic Text consumed by the operation.
spans dynamic spans value consumed by this operation.
links dynamic links value consumed by this operation.
prefix dynamic prefix value consumed by this operation.
src dynamic src value consumed by this operation.
kind dynamic kind value consumed by this operation.

View source

_md_append_plain

function _md_append_plain(text, line)

Append plain text to the rendered Markdown output.

Parameter Type Default Description
text dynamic Text consumed by the operation.
line dynamic line value consumed by this operation.

View source

_md_blank

function _md_blank(text)

Append a blank rendered line to a Markdown document.

Parameter Type Default Description
text dynamic Text consumed by the operation.

View source

_md_display_pos

function _md_display_pos(doc_text, doc_pos)

Convert a document offset to a RichEdit display offset.

Parameter Type Default Description
doc_text dynamic doc_text value consumed by this operation.
doc_pos dynamic doc_pos value consumed by this operation.

View source

_md_doc_pos_from_display

function _md_doc_pos_from_display(doc_text, display_pos)

Convert a RichEdit display offset back to a document offset.

Parameter Type Default Description
doc_text dynamic doc_text value consumed by this operation.
display_pos dynamic display_pos value consumed by this operation.

View source

_md_find_strong_close

function _md_find_strong_close(src, open_pos)

Find the closing delimiter for a strong emphasis span.

Parameter Type Default Description
src dynamic src value consumed by this operation.
open_pos dynamic open_pos value consumed by this operation.

View source

_md_heading_level

function _md_heading_level(line)

Return the ATX heading level for a Markdown line.

Parameter Type Default Description
line dynamic line value consumed by this operation.

View source

_md_heading_text

function _md_heading_text(line)

Extract the visible text from a Markdown heading line.

Parameter Type Default Description
line dynamic line value consumed by this operation.

View source

_md_hex_string

function _md_hex_string(hex_text)

Build a UTF-8 string from hex bytes while keeping this source file ASCII.

Parameter Type Default Description
hex_text dynamic hex_text value consumed by this operation.

View source

_md_inline

function _md_inline(src, base_pos, spans, links)

Parse inline Markdown formatting into styled output spans.

Parameter Type Default Description
src dynamic src value consumed by this operation.
base_pos dynamic base_pos value consumed by this operation.
spans dynamic spans value consumed by this operation.
links dynamic links value consumed by this operation.

View source

_md_is_digit

function _md_is_digit(ch)

Return true when a Markdown parser character is an ASCII digit.

Parameter Type Default Description
ch dynamic ch value consumed by this operation.

View source

_md_line_start

function _md_line_start(text)

Return the current output offset at the start of a rendered line.

Parameter Type Default Description
text dynamic Text consumed by the operation.

View source

_md_next_line_no

function _md_next_line_no(text)

Return the next rendered line number for Markdown output.

Parameter Type Default Description
text dynamic Text consumed by the operation.

View source

_md_normalize_display_chars

function _md_normalize_display_chars(text)

Replace mojibake and typographic Unicode with ASCII-safe text.

Parameter Type Default Description
text dynamic Text consumed by the operation.

View source

_md_ordered_prefix

function _md_ordered_prefix(line)

Return the length of a Markdown ordered-list prefix.

Parameter Type Default Description
line dynamic line value consumed by this operation.

View source

_md_table_row

function _md_table_row(line)

Return true when a Markdown line looks like a table row.

Parameter Type Default Description
line dynamic line value consumed by this operation.

View source

_md_table_separator

function _md_table_separator(line)

Return true when a Markdown line is a table separator row.

Parameter Type Default Description
line dynamic line value consumed by this operation.

View source

_normalize_editor_text

function _normalize_editor_text(text)

Normalize editor text so RichEdit and MiniLang use the same line endings.

Parameter Type Default Description
text dynamic Text consumed by the operation.

View source

_open_markdown_link_at

function _open_markdown_link_at(st, x, y)

Open an external Markdown link or jump to an in-document anchor.

Parameter Type Default Description
st dynamic st value consumed by this operation.
x dynamic Horizontal coordinate used by the operation.
y dynamic Vertical coordinate used by the operation.

View source

_render_markdown_document

function _render_markdown_document(markdown)

Render a Markdown document into text, styles, links, and anchors.

Parameter Type Default Description
markdown dynamic markdown value consumed by this operation.

View source

_set_log

function _set_log(st, text)

Replace the result log text and refresh the log control.

Parameter Type Default Description
st dynamic st value consumed by this operation.
text dynamic Text consumed by the operation.

View source

_strip_cr

function _strip_cr(line)

Remove carriage returns from editor or log text.

Parameter Type Default Description
line dynamic line value consumed by this operation.

View source

_strip_utf8_bom

function _strip_utf8_bom(text)

Remove a UTF-8 byte order mark from the start of text.

Parameter Type Default Description
text dynamic Text consumed by the operation.

View source

_write_markdown_editor

function _write_markdown_editor(st, markdown, preserve_view)

Render and write Markdown content into the active editor control.

Parameter Type Default Description
st dynamic st value consumed by this operation.
markdown dynamic markdown value consumed by this operation.
preserve_view dynamic preserve_view value consumed by this operation.

View source

clear_cache

function clear_cache(st, idx)

Clear the cached rendered Markdown document for a tab.

Parameter Type Default Description
st dynamic st value consumed by this operation.
idx dynamic idx value consumed by this operation.

View source

empty_doc

function empty_doc()

Return an empty rendered Markdown document for cache initialization.

View source

link_at_editor

function link_at_editor(st, x, y)

Return the rendered Markdown link under an editor coordinate.

Parameter Type Default Description
st dynamic st value consumed by this operation.
x dynamic Horizontal coordinate used by the operation.
y dynamic Vertical coordinate used by the operation.

View source

open_link_at

function open_link_at(st, x, y)

Open or jump to the rendered Markdown link under an editor coordinate.

Parameter Type Default Description
st dynamic st value consumed by this operation.
x dynamic Horizontal coordinate used by the operation.
y dynamic Vertical coordinate used by the operation.

View source

render

function render(markdown)

Render Markdown source into a styled document model.

Parameter Type Default Description
markdown dynamic markdown value consumed by this operation.

View source

write_editor

function write_editor(st, markdown, preserve_view)

Write rendered Markdown into the RichEdit control.

Parameter Type Default Description
st dynamic st value consumed by this operation.
markdown dynamic markdown value consumed by this operation.
preserve_view dynamic preserve_view value consumed by this operation.

View source