Index

mmo-markdown-editor

1 symbol · generated 5 Oct 2026

element

mmo-markdown-editor

mmo-markdown-editor.jhs:1

A markdown editor, GitHub flavored: a toolbar, the source, its preview (beside it, or in its own tab), and suggestion lists opened by a key.

<mmo-markdown-editor value mode="split" placeholder rows="12" name readonly required></mmo-markdown-editor>
Extends
CustomShadowElement
A **trigger** is a character (or a few) that opens a list of values when it is typed: `@` for the people, `#` for the tickets, `<` for the elements... The list is filtered by what is typed after the character, picked with the arrows and Enter / Tab (or the mouse), and closed by Escape, by a space or by moving the caret away. Triggers are set in javascript: editor.addTrigger('@', {values: ['marc', {value: 'laura', label: 'Laura', description: 'Design'}]}); editor.addTrigger('#', {values: async (query) => (await fetch('/tickets?q=' + query)).json(), insert: (item) => '#' + item.value + ' '}); editor.addTrigger('<', {values: ['mmo-icon', 'mmo-code'], insert: '<{value}>{caret}</{value}>'}); or in the page, as a `<datalist>` child: <datalist trigger="@" insert="@{value} " label="mention"> <option value="marc" data-description="Developer">Marc Mouret</option> (the closing tags follow) A trigger's options: - `values`: an array, or a function `(query, trigger) => array` that may return a promise. An item is a string, or an object `{value, label, description}` (only `value` is required) - `insert`: what replaces the trigger and the query: a template where `{value}`, `{label}`, `{query}` and `{trigger}` are replaced and `{caret}` is where the caret goes, or a function `(item, query, trigger) => string`. Default: `{trigger}{value} ` (`@marc `) - `spaces`: the query may hold spaces (default false: a space closes the list) - `anywhere`: the trigger opens the list in the middle of a word too (default false: only at the start of a word, so an email address does not open `@`'s list) - `inCode`: the trigger works in a code span or block too (default false) - `limit`: how many items the list shows (default 8) - `filter`: a function `(item, query) => bool` replacing the default one, which keeps the items whose value or label holds the query (case and accents ignored), the ones starting with it first - `label`: what the hint under the editor calls the trigger (`@ mention`) The preview is rendered by `MMO.core.markdown` (GitHub flavored: tables, task lists, strikethrough, fenced code, autolinks), its html never live: markdown source is always text.

Index

valuethe markdown
modewrite, preview or split (the source beside its preview; the preview under the source on a narrow screen)
placeholderthe text shown while the editor is empty
rowsthe height of the source, in lines
namethe name of the value in a form
readonlythe source cannot be changed: no toolbar, no trigger
requiredthe form is invalid while the editor is empty
formAssociated static readonly accessor
value accessorGet the markdown
mode accessorGet the view: write, preview or split
readonly accessorGet whether the source cannot be changed
triggers accessorGet the triggers, by their character
constructor()
init()
addTrigger(trigger, config)Add (or replace) a trigger: typing its character opens a list of values
removeTrigger(trigger)Remove a trigger
focus(options)Give the focus to the source
insertText(text)Insert text at the caret (replacing the selection), as if it was typed: it can be undone
format(action)Apply a toolbar action to the selection
replace(start, end, text, selStart, selEnd)Replace a range of the source, keeping the undo history, then select a part of what was inserted
wrap(before, after, placeholder)Wrap the selection in a marker, or unwrap it when it is already wrapped
prefixLines(has, prefix, cycle)Add a prefix to every line of the selection, or remove it when every line already has it
continueBlock()Enter in a list (or a quote) starts the next item; in an empty item, it ends the list
onInput(event)
onKeyDown(event)
detect(open)Find the trigger the caret is in, and open, filter or close its list
findTrigger()The trigger before the caret, if the caret is in one
show(trigger, index, query)Show the list of a trigger, filtered by the query
close()Close the list
renderList()
activate(i)
pick(i)Insert an item of the open list in place of the trigger and the query
place()Put the list under the caret (or above, when there is no room below)
caretCoordinates(index)Where a character of the source is drawn, relative to the source's box: a hidden copy of the source, styled the same, measures it
schedulePreview()
renderPreview()Render the preview now
updateMode()
updateHint()
updateForm()
formResetCallback()
item(item) staticNormalize an item: a string is its value and its label
fold(text) staticThe text compared by the filter: lower case, no accent
filter(items, query, config) staticKeep the items matching the query, the best first
highlight(node, label, query) staticWrite a label, the part matching the query in bold (text nodes only)
inCode(before, index) staticWhether a position of the markdown is inside a code block or a code span
dedent(text) staticRemove the indentation every line of a text shares (the indentation of the page's html)
(default)<datalist trigger="@"> elements, each a trigger and its values, and a <script type="text/markdown"> holding the initial markdown

Attributes7

mode

mmo-markdown-editor.jhs

write, preview or split (the source beside its preview; the preview under the source on a narrow screen)

mode="split"

Properties5

Methods34

addTrigger(trigger, config)

mmo-markdown-editor.jhs:264

Add (or replace) a trigger: typing its character opens a list of values

addTrigger(trigger, config)
triggerstring- the character(s) opening the list: @, #, <, ::...
configObject | Array | Function- the trigger's options (see the element's description), or only its values
returnsMMO.elements.MarkdownEditorthe editor

removeTrigger(trigger)

mmo-markdown-editor.jhs:281

Remove a trigger

removeTrigger(trigger)
triggerstring- the character(s) opening its list
returnsMMO.elements.MarkdownEditorthe editor

insertText(text)

mmo-markdown-editor.jhs:299

Insert text at the caret (replacing the selection), as if it was typed: it can be undone

insertText(text)
textstring- the text to insert

format(action)

mmo-markdown-editor.jhs:307

Apply a toolbar action to the selection

format(action)
actionstring- heading, bold, italic, strike, code, link, quote, ul, ol, task, table or hr

replace(start, end, text, selStart, selEnd)

mmo-markdown-editor.jhs:362

Replace a range of the source, keeping the undo history, then select a part of what was inserted

replace(start, end, text, selStart = null, selEnd = null)
startint- where the range starts
endint- where it ends
textstring- what replaces it
selStart = null?int- the selection's start, relative to the inserted text (default: its end)
selEnd = null?int- the selection's end, relative to the inserted text (default: selStart)

wrap(before, after, placeholder)

mmo-markdown-editor.jhs:386

Wrap the selection in a marker, or unwrap it when it is already wrapped

wrap(before, after, placeholder)
before
after
placeholder

prefixLines(has, prefix, cycle)

mmo-markdown-editor.jhs:405

Add a prefix to every line of the selection, or remove it when every line already has it

prefixLines(has, prefix, cycle = false)
hasRegExp- matches the prefix at the start of a line
prefixFunction- (line, index, current prefix or null) => the prefix to add
cycle = falseboolean- a line's prefix is replaced by the next one instead of being removed (a heading's level)

continueBlock()

mmo-markdown-editor.jhs:430

Enter in a list (or a quote) starts the next item; in an empty item, it ends the list

continueBlock()
returnsbooleantrue when it did

detect(open)

mmo-markdown-editor.jhs:523

Find the trigger the caret is in, and open, filter or close its list

detect(open)
openboolean- open a list that is not open yet (typing does, moving the caret does not)

findTrigger()

mmo-markdown-editor.jhs:534

The trigger before the caret, if the caret is in one

findTrigger()
returns?Object{trigger, index, query}

show(trigger, index, query)

mmo-markdown-editor.jhs:570

Show the list of a trigger, filtered by the query

show(trigger, index, query)
trigger
index
query

pick(i)

mmo-markdown-editor.jhs:658

Insert an item of the open list in place of the trigger and the query

pick(i)
iint- the item's index in the list

caretCoordinates(index)

mmo-markdown-editor.jhs:721

Where a character of the source is drawn, relative to the source's box: a hidden copy of the source, styled the same, measures it

caretCoordinates(index)
indexint- the character's index
returnsObject{top, left, height}

item(item)

staticmmo-markdown-editor.jhs:826

Normalize an item: a string is its value and its label

static item(item)
itemstring | Object
returnsObject{value, label, description, source}

filter(items, query, config)

staticmmo-markdown-editor.jhs:848

Keep the items matching the query, the best first

static filter(items, query, config)
itemsArray- normalized items
querystring
configObject- the trigger's options
returnsArraythe items to show

highlight(node, label, query)

staticmmo-markdown-editor.jhs:872

Write a label, the part matching the query in bold (text nodes only)

static highlight(node, label, query)
node
label
query

inCode(before, index)

staticmmo-markdown-editor.jhs:888

Whether a position of the markdown is inside a code block or a code span

static inCode(before, index)
beforestring- the markdown up to the position (at least)
indexint- the position
returnsboolean

dedent(text)

staticmmo-markdown-editor.jhs:901

Remove the indentation every line of a text shares (the indentation of the page's html)

static dedent(text)
text

Slots1

(default)

mmo-markdown-editor.jhs

<datalist trigger="@"> elements, each a trigger and its values, and a <script type="text/markdown"> holding the initial markdown

<slot>