Skip to content

v0.2.0

Choose a tag to compare

@XueyanZhang XueyanZhang released this 18 Nov 03:14
· 1 commit to main since this release

What five integrations of 0.1.3 (a git CMS, a wiki, two agent UIs and a document editor) asked
for: per-editor options and a fuller handle, a styling contract, renderers you can replace,
lighter dependencies, table edits that change only the edited cell, and a documented Markdown
dialect. 0.x minor: two changes below need a line of code from you.

Breaking

  • Fenced code is unhighlighted unless you pass codeLanguages. The editor no longer
    imports or declares @codemirror/language-data, so its twenty-odd @codemirror/lang-*
    packages leave your lockfile unless you want them. HTML inside Markdown is still highlighted.
    To keep 0.1.x's highlighting, install the list and pass it:

    npm install @codemirror/language-data
    import { languages } from "@codemirror/language-data";
    import { createEditorState, mountEditor } from "@openmarkdown-dev/editor";
    
    mountEditor(document.getElementById("editor")!, createEditorState({ doc, codeLanguages: languages }));

    In React, pass it where you create the state, inside the mount effect:

    import { languages } from "@codemirror/language-data";
    
    useEffect(() => {
      const state = createEditorState({ doc: value, codeLanguages: languages, host: { onChange } });
      editor.current = mountEditor(parent.current!, state);
      return () => editor.current?.destroy();
    }, []);

    Each language still loads the first time a fence uses it. To bundle only a few, pass your own
    LanguageDescriptions (bundling).

  • /no-diagrams now draws diagrams when the environment has a renderDiagram. In 0.1.x it
    ignored the diagrams option and always showed mermaid fences as code. Without a
    renderDiagram, it still does, so upgrading needs no change. Once you give one page-wide
    (configureEditorEnvironment), every /no-diagrams editor draws diagrams; pass
    diagrams: false to an editor that should keep showing the code. See
    renderers.

Added

  • Per-editor options. createEditorState({ environment }) gives one editor its own color
    scheme, clipboard, link handlers, spelling and host keys; configureEditorEnvironment is now
    the page's defaults (same signature; the UI language stays page-wide). colorScheme also
    accepts a fixed "light" or "dark". editor.setEnvironment(...) changes it later.
  • Read-only: editable: false (and editor.setEditable / editor.editable()) forbids
    every change in every mode, including checkboxes and properties, and draws no editing
    controls.
  • Handle commands, so a toolbar needs no CodeMirror import: undo, redo, openSearch,
    closeSearch, isSearchOpen, revealText, focus, and isUnedited(file) for an
    unsaved-changes indicator.
  • Forms and CMS fields: id, ariaLabel and ariaLabelledBy on the editable text (a
    <label for> focuses the editor); EditorHost.uploadImage(bytes, hint) for image paste and
    drop without a document path; height: "auto" for an editor as tall as its content. Guide:
    embed in a form.
  • fromState: take over an existing CodeMirror state with its document, selection and undo
    history.
  • Text codec openMarkdownText / saveMarkdownText (type MarkdownText), for hosts that
    hold the file as a string; it keeps the BOM and line endings as the bytes codec does.
  • Pluggable renderers: renderMath(tex, displayMode) (returns MathML) and
    renderDiagram(source, scheme) (returns SVG) in the environment, used in place of the
    built-in ones in every entry and passed through the same sanitiser. Bring your page's MathJax,
    KaTeX or Mermaid. Types MathRenderer, DiagramRenderer, ColorSchemeSource,
    EditorOwnEnvironment.
  • ./no-renderers entry: no built-in formula or diagram renderer; nothing it imports
    reaches Temml or Mermaid, so a one-file (IIFE) bundle inlines neither
    (bundling into one file).
  • ./browser: a prebuilt, minified single-file build (the /no-diagrams entry with
    CodeMirror, Lezer and Temml inside) for pages with no bundler.
  • Styling contract: the mounted editor's root has the class .ome-root; editors nested in a
    table cell or property value have .ome-nested. New layout tokens --ome-font-size,
    --ome-line-height, --ome-content-width, --ome-padding-x, --ome-padding-y, and a "fit
    the host page" recipe (theming).
  • \(…\) inline and \[ … \] block math, as language models write it.
  • Syntax guide (syntax): every syntax the editor reads, and the
    ones it shows as written, generated from the tests; it also says what extensions can add
    for host syntax (decorations such as wikilinks; not new grammar or block renderers).

Changed

  • Style .ome-root, not .cm-editor. A cell being edited holds its own .cm-editor, so a
    rule like .field .cm-editor { min-height: 320px } also stretched table rows. Move such rules
    to .ome-root. Token defaults are now set on .ome-root; the look is unchanged.
  • Table cell edits change only the edited cell. Leaving a cell no longer re-aligns the whole
    table. A cell edit that changed nothing writes nothing; an aligned table re-pads the edited
    cell and widens only that column when the text no longer fits; a compact table changes only by
    what you typed. Row, column and alignment commands write in the table's own style. Format
    table is the one command that rewrites a whole table. README "Fidelity" lists the exact rules.
  • Math delimiters follow Pandoc and remark-math. $…$ needs a non-space after the opening
    $ and before the closing one, and no digit right after it, so $20-$30 is text. $$…$$
    inside a line is inline math. \$ inside a formula is a dollar.
  • Escape backslashes (\*not\*) are hidden off the caret and in reading mode, like other
    marks; the source keeps them and plain-text copy drops them.
  • Dependencies: mermaid is the range ^11.17.2 (was pinned to 11.17.2), so a host on
    another 11.x shares one copy. @codemirror/lang-html and @lezer/common are now declared
    peers (lang-html was already installed with lang-markdown); @codemirror/language-data is no
    longer a peer.
  • Smaller first load: the HTML grammar loads the first time a document holds HTML, and
    Mermaid's drawing code with the first diagram.
  • extensions accepts an array (Extension | readonly Extension[]).
  • Install docs: entries table, codeLanguages, and what to do under a release-age gate (bun's
    or pnpm's minimumReleaseAge).
  • @openmarkdown-dev/css: body size, line height, column width and padding are the layout
    tokens above, with the same defaults, so they can be overridden on .om-doc.
  • Examples and the home page's script snippet use 0.2.0.

Fixed

  • Inline math in a list item no longer overlaps the text before it.
  • While a table cell is edited, the table is no longer tinted as if selected.
  • Typing into an empty cell puts the text one space in from the left pipe (| x |).
  • Reading mode opens no cell editor, and its properties block no longer shows "+ Add property"
    or "Edit as source" after a mode switch.
  • Temml's "doesn't work in quirks mode" warning is no longer printed (under happy-dom, for
    example).