Skip to content

MarkdownView

Official

A view for markdown files.

Import:

import { MarkdownView } from 'obsidian';

Signature:

export class MarkdownView extends TextFileView implements MarkdownFileInfo

Extends: TextFileView

Implements: MarkdownFileInfo

Constructor

new MarkdownView(leaf: WorkspaceLeaf)

Constructor.

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

Properties

Property Type Description
app App The Obsidian app instance.
(Inherited from MarkdownFileInfo)
backlinks BacklinkComponent | null Backlinks component.
backlinksEl HTMLElement The embedded backlinks element for the current file.
currentMode MarkdownSubView The current mode of the markdown view.
data string In-memory data.
(Inherited from TextFileView)
dirty boolean Whether current file is dirty (different from saved contents).
(Inherited from TextFileView)
editMode MarkdownEditView obsidian#Editor component of the view.
editor Editor The editor of the markdown view.
editor? Editor The editor associated with the markdown edit view.
(Inherited from MarkdownFileInfo)
hoverPopover HoverPopover | null The hover popover of the markdown view.
inlineTitleEl HTMLElement Editable title element of the view.
isPlaintext boolean Whether editor should be rendered as plaintext.
(Inherited from TextFileView)
lastSavedData null | string The data that was last saved.
(Inherited from TextFileView)
metadataEditor MetadataEditor Frontmatter editor of the editor.
metadataEditor? MetadataEditor The metadata (frontmatter/properties) editor for this file.
(Inherited from MarkdownFileInfo)
modeButtonEl HTMLAnchorElement Button for switching between different modes of the view.
modes MarkdownViewModes The registered modes of the view.
previewMode MarkdownPreviewView The preview mode of the markdown view.
rawFrontmatter string File frontmatter as a raw string.
requestSave () => void Debounced save in 2 seconds from now
(Inherited from TextFileView)
saveAgain boolean Whether on saving, the file should be saved again (for dirtiness checks).
(Inherited from TextFileView)
saving boolean Whether the file is currently saving.
(Inherited from TextFileView)
scroll null | number Current scroll position of the editor.
showBacklinks boolean Whether to show backlinks in the editor.
sourceMode MarkdownViewSourceMode The CM5 source mode editor component.

Methods

Method Returns Description
canShowProperties() boolean Whether the editor can render properties according to the current mode and config.
canToggleBacklinks() boolean Whether the editor can toggle backlinks according to current mode.
clear() void Clear the view data of the markdown view.
collapseProperties(collapse) void Collapse the properties editor.
editProperty(_unused) void Edit the focused property in the metadata editor.
focusMetadata(focus?) void Focus on the metadata editor given property information.
getEphemeralState() MarkdownViewEphemeralState Gets the ephemeral (non-persistent) state of the editor.
getFile() null | TFile Get the file attached to the view.
getHoverSource() string Get the hover source of the editor.
getMode() MarkdownViewModeType Get the current mode of the markdown view.
getSelection() string Get selection of current mode.
getViewData() string Get the view data of the markdown view.
getViewType() string Get the view type of the markdown view.
loadFileInternal(file, clear) Promise<unknown> Load a file into the editor, optionally clearing existing content.
(Inherited from TextFileView)
loadFrontmatter(data) void Validate correctness of frontmatter and update metadata editor.
metadataHasFocus() boolean Whether the metadata editor has focus.
onConfigChanged(configKey) void Handles an app config change relevant to the view (e.g. spellcheck).
onCssChange() void On app css change, update source mode editor.
onExternalDataChange(file, data) void Update editor on external data change (from sync plugin).
onInlineTitleBlur() Promise<void> On blur of inline title, save new filename.
onInternalDataChange() void On data change of editor, update internal data and metadata editor.
onload() void On loading markdown view, register resize, css-change and quick-preview events.
onLoadFile(file) Promise<void> On load file.
(Inherited from TextFileView)
onMarkdownFold() void On fold of markdown in source editor, save fold info to fold manager.
onMarkdownScroll() void On markdown scroll in editors, update scroll, sync state and trigger markdown scroll event.
onModify(file) void Is called when the vault has a 'modify' event. Reloads the file if the view is currently not saving the file and the modified file is the file in this view.
(Inherited from TextFileView)
onSwitchView(event) Promise<void> On mod click, opens editor of opposite mode in split view to right.
onUnloadFile(file) Promise<void> On unload file.
(Inherited from TextFileView)
printToPdf() void Opens PDF modal for exporting PDF of the current file.
redo() void Redo action of source mode editor.
registerMode(mode) MarkdownSubView Register editor mode component to view.
replaceScope(scope) void Replaces the active scope, falling back to the initial scope when null is given.
save(clear?) Promise<void> Save the file.
(Inherited from TextFileView)
saveFrontmatter(properties) void Save the frontmatter of the file.
saveImmediately() void If any changes(dirty = true) in the file forces the file to save.
(Inherited from TextFileView)
setData(data, clear) void Set the data to the editor. This is used to load the file contents.
(Inherited from TextFileView)
setMode(component) Promise<void> Set the mode of the editor.
setViewData(data, clear) void Set the view data of the markdown view.
shiftFocusAfter() void Shift focus to first line of editor.
shiftFocusBefore() void Shift focus to inline title.
showSearch(replace?) void Show the search modal.
syncScroll() void Syncs the current scroll position and triggers the markdown-scroll event.
toggleBacklinks() Promise<void> Toggle backlinks on editor.
toggleCollapseProperties() void Toggle collapse status of properties editor if allowed.
toggleMode() void Toggle between source and preview mode.
triggerClickableToken(token, newLeaf) void Execute functionality of token (open external link, open internal link in leaf, ...).
undo() void Undo action of source mode editor.
updateBacklinks() void Update the backlinks component for new file.
updateButtons() void Update reading/source view action buttons of modeButtonEl with current mode.
updateOptions() void Update options of the editors from settings.
updateShowBacklinks() void Hide/render backlinks component.

Links to this page: