mmo-markdown-editor
1 symbol · generated 5 Oct 2026
mmo-markdown-editor
mmo-markdown-editor.jhs:1A markdown editor, GitHub flavored: a toolbar, the source, its preview (beside it, or in its own tab), and suggestion lists opened by a key.
- Extends
- CustomShadowElement
Index
| value | the markdown | |
| mode | write, preview or split (the source beside its preview; the preview under the source on a narrow screen) | |
| placeholder | the text shown while the editor is empty | |
| rows | the height of the source, in lines | |
| name | the name of the value in a form | |
| readonly | the source cannot be changed: no toolbar, no trigger | |
| required | the form is invalid while the editor is empty | |
| formAssociated static readonly accessor | ||
| value accessor | Get the markdown | |
| mode accessor | Get the view: write, preview or split | |
| readonly accessor | Get whether the source cannot be changed | |
| triggers accessor | Get 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) static | Normalize an item: a string is its value and its label | |
| fold(text) static | The text compared by the filter: lower case, no accent | |
| filter(items, query, config) static | Keep the items matching the query, the best first | |
| highlight(node, label, query) static | Write a label, the part matching the query in bold (text nodes only) | |
| inCode(before, index) static | Whether a position of the markdown is inside a code block or a code span | |
| dedent(text) static | Remove 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
value
mmo-markdown-editor.jhsthe markdown
value
mode
mmo-markdown-editor.jhswrite, preview or split (the source beside its preview; the preview under the source on a narrow screen)
mode="split"
placeholder
mmo-markdown-editor.jhsthe text shown while the editor is empty
placeholder
rows
mmo-markdown-editor.jhsthe height of the source, in lines
rows="12"
name
mmo-markdown-editor.jhsthe name of the value in a form
name
readonly
mmo-markdown-editor.jhsthe source cannot be changed: no toolbar, no trigger
readonly
required
mmo-markdown-editor.jhsthe form is invalid while the editor is empty
required
Properties5
formAssociated
staticreadonlyaccessormmo-markdown-editor.jhs:92value
accessormmo-markdown-editor.jhs:201Get the markdown
- Type
string
mode
accessormmo-markdown-editor.jhs:220Get the view: write, preview or split
- Type
string
readonly
accessormmo-markdown-editor.jhs:233Get whether the source cannot be changed
- Type
boolean
triggers
accessormmo-markdown-editor.jhs:249Get the triggers, by their character
- Type
Object
Methods34
constructor()
mmo-markdown-editor.jhs:94init()
mmo-markdown-editor.jhs:109addTrigger(trigger, config)
mmo-markdown-editor.jhs:264Add (or replace) a trigger: typing its character opens a list of values
| trigger | string | - the character(s) opening the list: @, #, <, ::... |
| config | Object | Array | Function | - the trigger's options (see the element's description), or only its values |
| returns | MMO.elements.MarkdownEditor | the editor |
removeTrigger(trigger)
mmo-markdown-editor.jhs:281Remove a trigger
| trigger | string | - the character(s) opening its list |
| returns | MMO.elements.MarkdownEditor | the editor |
focus(options)
mmo-markdown-editor.jhs:291Give the focus to the source
| options |
insertText(text)
mmo-markdown-editor.jhs:299Insert text at the caret (replacing the selection), as if it was typed: it can be undone
| text | string | - the text to insert |
format(action)
mmo-markdown-editor.jhs:307Apply a toolbar action to the selection
| action | string | - heading, bold, italic, strike, code, link, quote, ul, ol, task, table or hr |
replace(start, end, text, selStart, selEnd)
mmo-markdown-editor.jhs:362Replace a range of the source, keeping the undo history, then select a part of what was inserted
| start | int | - where the range starts |
| end | int | - where it ends |
| text | string | - 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:386Wrap the selection in a marker, or unwrap it when it is already wrapped
| before | ||
| after | ||
| placeholder |
prefixLines(has, prefix, cycle)
mmo-markdown-editor.jhs:405Add a prefix to every line of the selection, or remove it when every line already has it
| has | RegExp | - matches the prefix at the start of a line |
| prefix | Function | - (line, index, current prefix or null) => the prefix to add |
| cycle = false | boolean | - a line's prefix is replaced by the next one instead of being removed (a heading's level) |
continueBlock()
mmo-markdown-editor.jhs:430Enter in a list (or a quote) starts the next item; in an empty item, it ends the list
| returns | boolean | true when it did |
onInput(event)
mmo-markdown-editor.jhs:454| event |
onKeyDown(event)
mmo-markdown-editor.jhs:465| event |
detect(open)
mmo-markdown-editor.jhs:523Find the trigger the caret is in, and open, filter or close its list
| open | boolean | - open a list that is not open yet (typing does, moving the caret does not) |
findTrigger()
mmo-markdown-editor.jhs:534The trigger before the caret, if the caret is in one
| returns | ?Object | {trigger, index, query} |
show(trigger, index, query)
mmo-markdown-editor.jhs:570Show the list of a trigger, filtered by the query
| trigger | ||
| index | ||
| query |
close()
mmo-markdown-editor.jhs:608Close the list
renderList()
mmo-markdown-editor.jhs:618activate(i)
mmo-markdown-editor.jhs:640| i |
pick(i)
mmo-markdown-editor.jhs:658Insert an item of the open list in place of the trigger and the query
| i | int | - the item's index in the list |
place()
mmo-markdown-editor.jhs:686Put the list under the caret (or above, when there is no room below)
caretCoordinates(index)
mmo-markdown-editor.jhs:721Where a character of the source is drawn, relative to the source's box: a hidden copy of the source, styled the same, measures it
| index | int | - the character's index |
| returns | Object | {top, left, height} |
schedulePreview()
mmo-markdown-editor.jhs:752renderPreview()
mmo-markdown-editor.jhs:763Render the preview now
updateMode()
mmo-markdown-editor.jhs:779updateHint()
mmo-markdown-editor.jhs:790updateForm()
mmo-markdown-editor.jhs:801formResetCallback()
mmo-markdown-editor.jhs:813item(item)
staticmmo-markdown-editor.jhs:826Normalize an item: a string is its value and its label
| item | string | Object | |
| returns | Object | {value, label, description, source} |
fold(text)
staticmmo-markdown-editor.jhs:837The text compared by the filter: lower case, no accent
| text |
filter(items, query, config)
staticmmo-markdown-editor.jhs:848Keep the items matching the query, the best first
| items | Array | - normalized items |
| query | string | |
| config | Object | - the trigger's options |
| returns | Array | the items to show |
highlight(node, label, query)
staticmmo-markdown-editor.jhs:872Write a label, the part matching the query in bold (text nodes only)
| node | ||
| label | ||
| query |
inCode(before, index)
staticmmo-markdown-editor.jhs:888Whether a position of the markdown is inside a code block or a code span
| before | string | - the markdown up to the position (at least) |
| index | int | - the position |
| returns | boolean |
dedent(text)
staticmmo-markdown-editor.jhs:901Remove the indentation every line of a text shares (the indentation of the page's html)
| 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>