e.g. "ctrl+shift+a"
Optionalnamespace: string
specify namespace of the handler for the cases where call for bind may be repeated. If a handler with this ID exists, it's replaced by the new handler.
Create a note link (jQuery object) for given note.
(or noteId)
Optionaloptions: CreateLinkOptionsNote containing the source code that is currently executing (in C terms, __FILE__).
Equal to startNote unless execution has moved into a descendant module note
loaded via require(). Don't confuse this with the note open in the UI — use
api.getActiveContextNote() for that.
day.js library for date manipulation. See https://day.js.org for documentation
this is producing local time! *
A byte count in the largest unit it fits in.
Optionaldecimals: number
places to keep, trailing zeros and all. Omit it to round to at most two and drop what is not needed, which reads best for a size at rest. Pass a number for a counter that is still climbing: there, dropping a trailing zero shortens the text on every other update and the line shifts about while it is being read.
A byte count in the largest unit it fits in.
Optionaldecimals: number
places to keep, trailing zeros and all. Omit it to round to at most two and drop what is not needed, which reads best for a size at rest. Pass a number for a counter that is still climbing: there, dropping a trailing zero shortens the text on every other update and the line shifts about while it is being read.
Returns day note for a given date. If it doesn't exist, it is automatically created.
Returns month-note. If it doesn't exist, it is automatically created.
Returns quarter note for given date. If such a note doesn't exist, it is automatically created.
Returns date-note for today. If it doesn't exist, it is automatically created.
Returns day note for the first date of the week of the given date. If it doesn't exist, it is automatically created.
Returns week note for given date. If such a note doesn't exist, it is automatically created.
Returns year-note. If it doesn't exist, it is automatically created.
Entity whose event triggered this execution, or null.
Most frontend scripts are started by the user or by the UI (startup scripts, widgets),
so this is usually null. It is set to a note when:
~renderNote relation — then it's the note being rendered
(the one carrying the relation), not the script note;api.runOnFrontend() — then it's the backend execution's
originEntity, provided that entity was a note.true to protect note, false to unprotect
true to protect subtree, false to unprotect
Return randomly generated string of given length. This random string generation is NOT cryptographically secure.
Optionallen: numberrandom string
jquery object on which to set up the tooltip
Show confirm dialog to the user.
Displays a confirmation dialog with the given message.
the message to display in the dialog. A string is rendered as HTML; pass an element where the wording needs structure the dialog should not have to parse — an admonition warning about what the action costs, say.
A promise that resolves to true if the user confirmed, false otherwise.
Show an error toast message to the user.
Show an info dialog to the user.
Show an info toast message to the user.
Show prompt dialog to the user.
promise resolving to the answer provided by the user
Note where the script execution started — the entry point of the current script bundle
(in C terms, the file containing main()). When a script is spread across multiple code
notes (descendant code notes loaded as modules via require()), every note in the
bundle shares the same startNote, while currentNote differs per note.
Messages from api.log() are grouped under this note.
Trigger command. This is a very low-level API which should be avoided if possible.
Trigger event. This is a very low-level API which should be avoided if possible.
Trilium runs in a backend and frontend process, when something is changed on the backend from a script, frontend will get asynchronously synchronized.
This method returns a promise which resolves once all the backend -> frontend synchronization is finished. Typical use case is when a new note has been created, we should wait until it is synced into frontend and only then activate it.
Activates newly created note. Compared to this.activateNote() also makes sure that frontend has been fully synced.
(or noteId)
Activates note in the tree and in the note detail.
(or noteId)
Adds a new launcher to the launchbar. If the launcher (id) already exists, it will be updated.
Adds given text to the editor cursor
this must be clear text, HTML is not supported.
Creates a new note as a child of the given parent, entirely on the frontend — no backend
scripting required (unlike api.runOnBackend(() => api.createTextNote(...))). By default the
new note is activated in the current tab with its title focused for editing; pass
{ activate: false } to create it silently.
note path (or noteId) of the parent under which to create the note
Optionalopts: CreateNoteOpts
creation options — e.g. { title, content, type, mime, activate }
the created note and its branch, resolved from the frontend cache
Obtains the currently active/focused split in the current tab.
Note that this method does not return the note context of the "Quick edit" panel, it will return the note context behind it.
instance of CodeMirror
active note (loaded into center pane)
returns a note path of active note or null if there isn't active note
See https://ckeditor.com/docs/ckeditor5/latest/api/module_core_editor_editor-Editor.html for documentation on the returned instance.
instance of CKEditor
Obtains the main context of the current tab. This is the left-most split.
Note that this method does not return the note context of the "Quick edit" panel, it will return the note context behind it.
Get access to the widget handling note detail. Methods like getWidgetType() and getTypeWidget() to get to the
implementation of actual widget type.
Returns component which owns the given DOM element (the nearest parent component in DOM tree)
DOM element
Instance name identifies particular Trilium instance. It can be useful for scripts if some action needs to happen on only one specific instance.
returns all main contexts representing tabs
Returns note by given noteId. If note is missing from the cache, it's loaded.
returns all note contexts (splits) in all tabs
Returns list of notes. If note is missing from the cache, it's loaded.
This is often used to bulk-fill the cache with notes which would have to be picked one by one otherwise (by e.g. createLink())
OptionalsilentNotFoundError: boolean
don't report error if the note is not found
Converts the given HTML string to Markdown.
Unlike the backend API, this runs on the server (the HTML→Markdown converter is backend-only), so it returns a promise.
HTML content to convert
Markdown representation of the input HTML
Whether backend script execution is enabled on the server (the
[Security] backendScriptingEnabled config toggle). When it's disabled,
api.runOnBackend() / api.runAsyncOnBackendWithManualTransactionHandling()
reject with a "Backend script execution is disabled" error, so check this
first to let a script degrade gracefully instead of throwing.
Whether the SQL console is enabled on the server (the
[Security] sqlConsoleEnabled config toggle). When it's disabled, backend
scripts that run raw SQL (api.sql.*) fail, so check this before invoking
SQL-backed logic via api.runOnBackend().
Log given message to the log pane in UI.
Accepts multiple arguments which are joined with spaces, similar to console.log.
Converts the given Markdown string to HTML.
Runs entirely in the browser; the promise is only needed because the Markdown renderer is loaded on demand.
Markdown content to convert
HTML representation of the input Markdown
Open a note in a new split.
(or noteId)
set to true to activate the new split, false to stay on the current split
This will refresh all currently opened notes which have included note specified in the parameter
noteId of the included note
Update frontend tree (note) cache from the backend.
Executes given anonymous function on the backend. Internally this serializes the anonymous function into string and sends it to backend via AJAX. This function is meant for advanced needs where an async function is necessary. In this case, the automatic request-scoped transaction management is not applied, and you need to manually define transaction via api.transactional().
If you have a synchronous function, please use api.runOnBackend().
(synchronous) function to be executed on the backend
list of parameters to the anonymous function to be sent to backend
return value of the executed function on the backend
Executes given anonymous function on the backend. Internally this serializes the anonymous function into string and sends it to backend via AJAX. Please make sure that the supplied function is synchronous. Only sync functions will work correctly with transaction management. If you really know what you're doing, you can call api.runAsyncOnBackendWithManualTransactionHandling()
(synchronous) function to be executed on the backend
list of parameters to the anonymous function to be sent to backend
return value of the executed function on the backend
This is a powerful search method - you can search by attributes and their values, e.g.: "#dateModified =* MONTH AND #log". See full documentation for all options at: https://triliumnext.github.io/Docs/Wiki/search.html
This is a powerful search method - you can search by attributes and their values, e.g.: "#dateModified =* MONTH AND #log". See full documentation for all options at: https://triliumnext.github.io/Docs/Wiki/search.html
Hoist note in the current tab. See https://triliumnext.github.io/Docs/Wiki/note-hoisting.html
set hoisted note. 'root' will effectively unhoist
Container of all the rendered script content