rendered-markdown
The parts of a Reading view’s behavior that Obsidian keeps inside its preview renderer, ported for markdown rendered anywhere else with MarkdownRenderer.render.
MarkdownPreviewRenderer.registerDomEvents covers internal and external links, tags, drags, context menus and the footnote HOVER. Three things it does not cover, read from Obsidian 1.15.0: the footnote CLICK (onFootnoteLinkClick), and the heading and list FOLDING, whose indicators the renderer only adds in its own onRender and whose clicks only it handles. Without these, a footnote click in standalone rendered markdown falls through to the browser’s hash navigation, and nothing can be folded.
Interfaces
Section titled “Interfaces”| Interface | Description |
|---|---|
| RegisterFoldHandlersParams | Parameters for registerFoldHandlers. |
| RegisterFootnoteLinkHandlerParams | Parameters for registerFootnoteLinkHandler. |
Functions
Section titled “Functions”| Function | Description |
|---|---|
| isOwnedByRenderedMarkdown | Whether an element belongs to the markdown rendered into rootEl, rather than to a Reading view or a Bases view nested inside it (an embed), which handles its own events. A port of Obsidian’s static MarkdownPreviewRenderer.belongsToMe, which obsidian-typings does not declare. |
| registerFoldHandlers | Makes the headings and the nested lists of rendered markdown foldable, the way they are in a Reading view: it adds Obsidian’s own collapse indicators and handles their clicks. A folded heading hides every block after it up to the next heading of the same or a higher level; unfolding it shows them again, except those a folded heading among them still hides. A folded list item hides its nested lists. Call it again after the element is re-rendered: blocks that already have an indicator are left alone, and the click handler is registered only once per element. |
| registerFootnoteLinkHandler | Makes a footnote link in rendered markdown act as it does in a Reading view: a click scrolls to the footnote, or back to its reference, and flashes it, instead of navigating to the link’s # hash. Registered by registerLinkHandlers, which is the usual way in; call it directly only for an element whose other links are handled some other way. |