components/embeddable-markdown-editor-component
Contains class EmbeddableMarkdownEditorComponent: a full Obsidian Markdown editor (Live Preview, editor commands, hotkeys) mounted in any element and owned as a component.
Obsidian does not export its editor class, so the component borrows it from a throwaway Markdown embed: an editable embed builds an iframed editor whose grandparent prototype is the scrollable Markdown editor every embed and table cell editor uses. The probe opens no leaf and fires no workspace event (embeddable-markdown-editor-component .obsidian.integration.test.ts measures that), and it runs once per copy of this library, on first use rather than at module load. The class is cached per copy and never in the shared-state bag, because a constructor is not plain data.
Adapted from the “Embeddable CM Markdown Editor” gist (https://gist.github.com/Fevol/caa478ce303e69eabede7b12b2323838), itself a rework of the Kanban plugin’s src/components/Editor/MarkdownEditor.tsx, under the MIT license below.
Copyright 2024 Matthew Meyers, Fevol
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Classes
Section titled “Classes”| Class | Description |
|---|---|
| EmbeddableMarkdownEditorComponent | A full Obsidian Markdown editor mounted in any element: Live Preview, editor commands, hotkeys and the editor suggesters all work in it as they do in a note. Add it as a child of the component that owns its element; unloading it destroys the editor and removes the editor’s element. It works on desktop and mobile. |
Interfaces
Section titled “Interfaces”| Interface | Description |
|---|---|
| EmbeddableMarkdownEditorComponentConstructorParams | The parameters of the EmbeddableMarkdownEditorComponent constructor. |
| EmbeddableMarkdownEditorComponentEnterParams | The parameters of EmbeddableMarkdownEditorComponentConstructorParams.onEnter. |
| EmbeddableMarkdownEditorComponentSelection | A selection in an EmbeddableMarkdownEditorComponent, as document offsets. |