Skip to content

MarkdownPreviewRenderer

Official

The renderer of the markdown preview.

Import:

import { MarkdownPreviewRenderer } from 'obsidian';

Signature:

export class MarkdownPreviewRenderer

Constructor

new MarkdownPreviewRenderer(owner: unknown, containerEl: HTMLElement, parentEl: HTMLElement, workerPath: unknown, observeInsertion?: boolean | undefined)

Constructor.

To get the constructor instance, use getMarkdownPreviewRendererConstructor from obsidian-typings/implementations.

Methods

MethodReturnsDescription
addFooter()voidAdds a footer section to the rendered preview.
addHeader()voidAdds a header section to the rendered preview.
applyFoldInfo(foldInfo)voidApplies fold information to the preview.
applyScroll(scroll, options?)booleanScrolls the preview to a position.
applyScrollDelayed(scroll, options?, callback?)voidScrolls the preview to a position once rendering has completed.
applyScrollSection(section)boolean | undefinedScrolls the preview so the given section is at the top.
belongsToMe(el)booleanChecks whether an element belongs to this renderer.
cleanupParentComponents()voidRemoves child components whose elements no longer belong to this renderer.
clear()voidClears the rendered sections.
createCodeBlockPostProcessor(language, handler)(el: HTMLElement, ctx: MarkdownPostProcessorContext) => void
foldAllHeadings()voidFolds all headings in the preview.
foldAllLists()voidFolds all lists in the preview.
getFoldInfo()FoldInfoGets the current fold information.
getInternalLinkHref(el)null | stringGets the internal-link href for an element, if it belongs to this renderer.
getScroll()null | numberGets the current scroll position.
getSectionContainer(el)unknownGets the section whose element contains the given element.
getSectionForElement(el)unknownGets the section whose element contains the given element.
getSectionInfo(el)MarkdownSectionInformation | nullGets section information for an element.
getSectionTop(section)numberGets the scroll-top offset of a section.
handleDetached(el)booleanChecks whether an element belongs to one of this renderer's sections.
highlightEl(el)voidBriefly highlights an element.
measureSection(section)voidMeasures the rendered height of a section.
onCheckboxClick(evt, el)voidHandles a checkbox click within the preview.
onFootnoteLinkClick(evt, el)voidHandles a footnote-link click within the preview.
onHeadingCollapseClick(evt, el)voidHandles a heading-collapse-indicator click within the preview.
onListCollapseClick(evt, el)voidHandles a list-collapse-indicator click within the preview.
onRender()voidRenders the queued sections.
onRendered(callback)voidRegisters a callback to run after the next render, or immediately if already rendered.
onResize()voidHandles a resize of the preview container.
onScroll()voidHandles a scroll of the preview container.
parseAsync()voidParses the current text asynchronously.
parseFinish(text, parseResult)voidFinalizes a parse result into sections.
parseSync()voidParses the current text synchronously.
queueRender()voidQueues a render of the preview.
registerPostProcessor(postProcessor, sortOrder?)void
removeFooter()voidRemoves the footer section from the preview.
removeHeader()voidRemoves the header section from the preview.
renderHighlights(startSection, endSection)voidRenders search highlights across a range of sections.
rerender(full?)voidRe-renders the preview.
selectRange(range)voidSelects a range within the preview, scrolling its section into view.
set(text)voidSets the preview text and queues a render.
setListCollapse(el, collapsed)voidCollapses or expands the lists within an element.
showSection(section)voidEnsures a section is shown, updating the virtual display.
unfoldAllHeadings()voidUnfolds all headings in the preview.
unfoldAllLists()voidUnfolds all lists in the preview.
unregisterPostProcessor(postProcessor)void
updateFooter()voidRe-measures the footer section.
updateHeader()voidRe-measures the header section.
updateShownSections()voidRecomputes which sections should be shown based on heading-fold levels.
updateVirtualDisplay(scrollTop?)voidUpdates the virtually-rendered sections for the current scroll position.
static registerDomEvents(el, handlers, childElFn)voidRegisters the DOM events.
static unregisterCodeBlockPostProcessor(language)voidRemove the code block post processor currently registered with the given language.

Links to this page: