Create new instance.
Array of versions representing the entire saved version history for this draft.
Date the draft was created. This property is generally maintained by Drafts automatically and is it not recommended it be set directly unless needed to maintain information from an external source when importing.
Date the draft was last modified. This property is generally maintained by Drafts automatically and is it not recommended it be set directly unless needed to maintain information from an external source when importing.
Numeric latitude where the draft was created. This value will be 0
if no location information was available.
Numeric longitude where the draft was created. This value will be 0
if no location information was available.
Numeric longitude where the draft was last modified. This value will be 0
if no location information was available.
Numeric longitude where the draft was last modified. This value will be 0
if no location information was available.
The full text content.
Generally, the first line of the draft, but cleaned up as it would be displayed in the draft list in the user interface, removing Markdown header characters, etc.
Is the draft current in the archive. If false
, the draft is in the inbox.
Current flagged status.
Is the draft currently in the trash.
The lines of content separated into an array on \n
line feeds. This is a convenience method an equivalent to content.split('\n');
URL which can be used to open the draft. URLs are cross-platform, but specific to an individual user's drafts datastore.
The length of the last text selection.
The index location in the string of the beginning of the last text selection.
The syntax definition used when displaying this draft in the editor.
The first line.
Unique identifier.
Array of string tag names assigned.
Array of versions representing the entire saved version history for this draft.
Append text to the end of the draft's content
. This is a convenience function.
The text to append
An optional separator string to use between content and added text. Defaults to a single line feed.
Return the a trimmed display version of the "body" of the draft (content after first line), similar to what is displayed as a preview in the draft list._
Prepend text to the beginning of the draft's content
. This is a convenience function.
The text to prepend
An optional separator string to use between content and added text. Defaults to a single line feed.
Save changes made to the draft to the database. update()
must be called to save changes made to a draft.
Create a new draft object. This is an in-memory object only, unless "update()" is called to save the draft.
Find an existing draft based on UUID.
Perform a search for drafts and return an array of matching draft objects.
Search string, as you would type in the search box in the draft list. Will find only drafts with a matching string in their contents. Use empty string (""
) not to filter.
Filter by one of the allowed values
Results will only include drafts with one or more of these tags assigned.
Results will omit drafts with any of these tags assigned.
If true
, sort descending. Defaults to false
.
If true
, sort flagged drafts to beginning. Defaults to false
.
Search for drafts containing the title string in the first line of their content. This mimics the logic used by the /open?title=Title
URL scheme to locate drafts by title when triggering embedded cross-links.
Assign a tag
Check whether a tag is currently assigned to the draft.
Remove a tag if it is assigned to the draft.
Return array of recently used tags. Helpful for building prompts to select tags.
Get the current value of a custom template tag.
Runs the template string through the Mustache template engine to evaluate tags. Allows additional values and partials to be provided to the context.
Template string
An object containing additional values you wish to make available in the Mustache context.
An object containing string keys and values which will contain additional templates you which to make available for use as partials and layouts.
Runs the template string through the Drafts Template engine to evaluate tags.
Set a custom template tag value for use in templates. For example, calling setTemplateTag("mytag", "mytext")
will create a tag [[mytag]]
, which subsequent action steps in the same action can use in their templates. These values are also available in Mustache templates, but as {{mytag}}
.
Create a version in the version history representing the current state of the draft.
Generated using TypeDoc
Draft
The Draft object represents a single draft. When an action is run, the current draft is available as the global variable
draft
. Scripts can also create new drafts, access and set values, and update the draft to persist changes.Example: Creating a draft
// create a new draft, assign content and save it let d = new Draft(); d.content = "My new draft"; d.addTag("personal"); d.update();
Example: Querying drafts
// query a list of drafts in the inbox with the tag "blue" let drafts = Draft.query("", "inbox", ["blue"])