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.
Note 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.
dayjs
dayjs:__module
day.js library for date manipulation.
See https://day.js.org for documentation
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 event. This is a very low-level API which should be avoided if possible.
waitUntilSynced
waitUntilSynced:()=>Promise<void>
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.
Methods
activateNewNote
activateNewNote(notePath:string):Promise<void>
Activates newly created note. Compared to this.activateNote() also makes sure that frontend has been fully synced.
Parameters
notePath: string
(or noteId)
Returns Promise<void>
activateNote
activateNote(notePath:string):Promise<void>
Activates note in the tree and in the note detail.
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.
Parameters
parentNotePath: string
note path (or noteId) of the parent under which to create the note
Unlike the backend API, this runs on the server (the HTML→Markdown
converter is backend-only), so it returns a promise.
Parameters
html: string
HTML content to convert
Returns Promise<string>
Markdown representation of the input HTML
isBackendScriptingEnabled
isBackendScriptingEnabled():boolean
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.
Returns boolean
isSqlConsoleEnabled
isSqlConsoleEnabled():boolean
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().
Returns boolean
log
log(...args:unknown[]):void
Log given message to the log pane in UI.
Accepts multiple arguments which are joined with spaces, similar to console.log.
Parameters
...args: unknown[]
Returns void
markdownToHtml
markdownToHtml(markdown:string):Promise<string>
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.
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().
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()
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
Container of all the rendered script content