MarkdownView
Official
A view for markdown files.
Import:
import { MarkdownView } from 'obsidian';Signature:
export class MarkdownView extends TextFileView implements MarkdownFileInfoExtends: 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 | Request a save, debounced by 2 seconds. (Inherited from TextFileView) | |
| savePromise | null | Promise<void> | The write in progress, or null when the view is not saving; a save waits for it before starting another.(Inherited from TextFileView) | |
| saving | boolean | Whether the file is currently saving, i.e. whether TextFileView.savePromise is set. (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. | |
| focusAfterMetadata() | void | Focuses the editor at its start, or the preview when no editor is available. | |
| focusBeforeMetadata() | void | Focuses the inline title when it is visible. | |
| 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. It returns 'source' for Live Preview as well as for Source mode, because both are the editing mode. To tell them apart, read source from MarkdownView.getState: it is true in Source mode and false in Live Preview. | |
| getSelection() | string | Get selection of current mode. | |
| getState() | MarkdownViewState | Get the state of the markdown view. | |
| 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. | |
| 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) | |
| setEphemeralState(state) | void | Set the ephemeral state of the markdown view. Resolves subpath to a line in the file, then passes the state on to the current mode. | |
| 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. | |
| showSource() | void | Switch the leaf to source mode and focus the editor after the properties, used by the "Show source" button of invalid properties. | |
| 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. | |
| writeData(file, data, previousData) | Promise<void> | Write the data to the file once the adapter is ready. On failure it restores TextFileView.lastSavedData, shows a notice and stores a backup of the unsaved text before rethrowing. (Inherited from TextFileView) |
Links to this page: