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

PropertyTypeDescription
appAppThe Obsidian app instance.
(Inherited from MarkdownFileInfo)
backlinksBacklinkComponent | nullBacklinks component.
backlinksElHTMLElementThe embedded backlinks element for the current file.
currentModeMarkdownSubViewThe current mode of the markdown view.
datastringIn-memory data.
(Inherited from TextFileView)
dirtybooleanWhether current file is dirty (different from saved contents).
(Inherited from TextFileView)
editModeMarkdownEditViewobsidian#Editor component of the view.
editorEditorThe editor of the markdown view.
editor?EditorThe editor associated with the markdown edit view.
(Inherited from MarkdownFileInfo)
hoverPopoverHoverPopover | nullThe hover popover of the markdown view.
inlineTitleElHTMLElementEditable title element of the view.
isPlaintextbooleanWhether editor should be rendered as plaintext.
(Inherited from TextFileView)
lastSavedDatanull | stringThe data that was last saved.
(Inherited from TextFileView)
metadataEditorMetadataEditorFrontmatter editor of the editor.
metadataEditor?MetadataEditorThe metadata (frontmatter/properties) editor for this file.
(Inherited from MarkdownFileInfo)
modeButtonElHTMLAnchorElementButton for switching between different modes of the view.
modesMarkdownViewModesThe registered modes of the view.
previewModeMarkdownPreviewViewThe preview mode of the markdown view.
rawFrontmatterstringFile frontmatter as a raw string.
requestSave() => voidDebounced save in 2 seconds from now
(Inherited from TextFileView)
saveAgainbooleanWhether on saving, the file should be saved again (for dirtiness checks).
(Inherited from TextFileView)
savingbooleanWhether the file is currently saving.
(Inherited from TextFileView)
scrollnull | numberCurrent scroll position of the editor.
showBacklinksbooleanWhether to show backlinks in the editor.
sourceModeMarkdownViewSourceModeThe CM5 source mode editor component.

Methods

MethodReturnsDescription
canShowProperties()booleanWhether the editor can render properties according to the current mode and config.
canToggleBacklinks()booleanWhether the editor can toggle backlinks according to current mode.
clear()voidClear the view data of the markdown view.
collapseProperties(collapse)voidCollapse the properties editor.
editProperty(_unused)voidEdit the focused property in the metadata editor.
focusMetadata(focus?)voidFocus on the metadata editor given property information.
getEphemeralState()MarkdownViewEphemeralStateGets the ephemeral (non-persistent) state of the editor.
getFile()null | TFileGet the file attached to the view.
getHoverSource()stringGet the hover source of the editor.
getMode()MarkdownViewModeTypeGet the current mode of the markdown view.
getSelection()stringGet selection of current mode.
getViewData()stringGet the view data of the markdown view.
getViewType()stringGet 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)voidValidate correctness of frontmatter and update metadata editor.
metadataHasFocus()booleanWhether the metadata editor has focus.
onConfigChanged(configKey)voidHandles an app config change relevant to the view (e.g. spellcheck).
onCssChange()voidOn app css change, update source mode editor.
onExternalDataChange(file, data)voidUpdate editor on external data change (from sync plugin).
onInlineTitleBlur()Promise<void>On blur of inline title, save new filename.
onInternalDataChange()voidOn data change of editor, update internal data and metadata editor.
onload()voidOn loading markdown view, register resize, css-change and quick-preview events.
onLoadFile(file)Promise<void>On load file.
(Inherited from TextFileView)
onMarkdownFold()voidOn fold of markdown in source editor, save fold info to fold manager.
onMarkdownScroll()voidOn markdown scroll in editors, update scroll, sync state and trigger markdown scroll event.
onModify(file)voidIs 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()voidOpens PDF modal for exporting PDF of the current file.
redo()voidRedo action of source mode editor.
registerMode(mode)MarkdownSubViewRegister editor mode component to view.
replaceScope(scope)voidReplaces 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)voidSave the frontmatter of the file.
saveImmediately()voidIf any changes(dirty = true) in the file forces the file to save.
(Inherited from TextFileView)
setData(data, clear)voidSet 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)voidSet the view data of the markdown view.
shiftFocusAfter()voidShift focus to first line of editor.
shiftFocusBefore()voidShift focus to inline title.
showSearch(replace?)voidShow the search modal.
syncScroll()voidSyncs the current scroll position and triggers the markdown-scroll event.
toggleBacklinks()Promise<void>Toggle backlinks on editor.
toggleCollapseProperties()voidToggle collapse status of properties editor if allowed.
toggleMode()voidToggle between source and preview mode.
triggerClickableToken(token, newLeaf)voidExecute functionality of token (open external link, open internal link in leaf, ...).
undo()voidUndo action of source mode editor.
updateBacklinks()voidUpdate the backlinks component for new file.
updateButtons()voidUpdate reading/source view action buttons of modeButtonEl with current mode.
updateOptions()voidUpdate options of the editors from settings.
updateShowBacklinks()voidHide/render backlinks component.

Links to this page: