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();

Querying drafts

// query a list of drafts in the inbox with the tag "blue"
let drafts = Draft.query("", "inbox", ["blue"])

Hierarchy

  • Draft

ActionLog

actionLogs: ActionLog[]

Array of versions representing the entire saved version history for this draft.

Date

createdAt: Date

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.

modifiedAt: Date

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.

Deprecated

languageGrammar: "Plain Text" | "Markdown" | "Taskpaper" | "JavaScript" | "Simple List" | "MultiMarkdown" | "GitHub Markdown"

Deprecated

use syntax property.

  • Returns string[]

    Deprecated

    use Tag.recentTags() instead.

Linked Items

linkedItems: [linkedItem]

Convenience method to return the linked items in the content, as located by the syntax definitions' linkDefinitions. In Markdown syntaxes, these map to [[wiki-style]] cross-links.

Location

createdLatitude: number

Numeric latitude where the draft was created. This value will be 0 if no location information was available.

createdLongitude: number

Numeric longitude where the draft was created. This value will be 0 if no location information was available.

modifiedLatitude: number

Numeric longitude where the draft was last modified. This value will be 0 if no location information was available.

modifiedLongitude: number

Numeric longitude where the draft was last modified. This value will be 0 if no location information was available.

Navigation Markers

navigationMarkers: [navigationMarker]

Array of navigation markers in the content. Navigation markers are defined by the syntax definition assigned to the draft, and are used in the Navigation feature.

  • The next navigation marker in the content, relative to the character location. This is a convenience method to assist in navigating by marker.

    Parameters

    • location: number

    Returns navigationMarker

  • The previous navigation marker in the content, relative to the character location. This is a convenience method to assist in navigating by marker.

    Parameters

    • location: number

    Returns navigationMarker

Other

  • Create new instance.

    Returns Draft

content: string

The full text content.

displayTitle: string

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.

isArchived: boolean

Is the draft current in the archive. If false, the draft is in the inbox.

isFlagged: boolean

Current flagged status.

isTrashed: boolean

Is the draft currently in the trash.

lines: [string]

The lines of content separated into an array on \n line feeds. This is a convenience method an equivalent to content.split('\n');

permalink: string

URL which can be used to open the draft. URLs are cross-platform, but specific to an individual user's drafts datastore.

selectionLength: number

The length of the last text selection.

selectionStart: number

The index location in the string of the beginning of the last text selection.

syntax: Syntax

The syntax definition used when displaying this draft in the editor.

title: string

The first line.

urls: [string]

Convenience method to scan the draft content for valid URLs, and return all found URLs as an array. This will return valid full URL strings - both for http(s) and custom URLs found in the text.

uuid: string

Unique identifier.

  • Append text to the end of the draft's content. This is a convenience function.

    Parameters

    • text: string

      The text to append

    • Optional separator: string

      An optional separator string to use between content and added text. Defaults to a single line feed.

    Returns void

  • 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._

    Parameters

    • maxLength: number

    Returns string

  • Insert text into the draft's content at the line indicated. This is a convenience function.

    Parameters

    • text: string

      The text to in

    • line: number

      The index of the line number at which to insert the text. Line numbers are zero-based, so 0 is the first line. Drafts will range-check the line.

    Returns void

  • Convenience method to filter lines of a draft, returning only the lines that begin with a certain string.

    Parameters

    • prefix: string

    Returns [string]

  • Prepend text to the beginning of the draft's content. This is a convenience function.

    Parameters

    • text: string

      The text to prepend

    • Optional separator: string

      An optional separator string to use between content and added text. Defaults to a single line feed.

    Returns void

  • Provide standard object representation of draft, compatible with JSON.stringify.

    Returns object

  • Save changes made to the draft to the database. update() must be called to save changes made to a draft.

    Returns void

  • Create a new draft object. This is an in-memory object only, unless "update()" is called to save the draft.

    Returns Draft

Querying

  • Find an existing draft based on UUID.

    Parameters

    • uuid: string

    Returns Draft

  • Perform a search for drafts and return an array of matching draft objects.

    Parameters

    • queryString: string

      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. Support query string structured details available in User Guide.

    • filter: "inbox" | "flagged" | "archive" | "trash" | "all"

      Filter by one of the allowed values

    • tags: string[]

      Results will only include drafts with all the listed tags assigned.

    • omitTags: string[]

      Results will omit drafts with any of these tags assigned.

    • sort: sortBy
    • sortDescending: boolean

      If true, sort descending. Defaults to false.

    • sortFlaggedToTop: boolean

      If true, sort flagged drafts to beginning. Defaults to false.

    Returns Draft[]

  • 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.

    Parameters

    • title: string

    Returns Draft[]

Tag

tags: string[]

Array of string tag names assigned.

  • Assign a tag

    Parameters

    • tag: string

    Returns void

  • Check whether a tag is currently assigned to the draft.

    Parameters

    • tag: string

    Returns boolean

  • Remove a tag if it is assigned to the draft.

    Parameters

    • tag: string

    Returns void

Tasks

completedTasks: [Task]

Array of completed task lines found in the content of the draft, based on active syntax definition for the draft. See Task documentation for usage details.

incompleteTasks: [Task]

Array of incomplete task lines found in the content of the draft, based on active syntax definition for the draft. See Task documentation for usage details.

tasks: [Task]

Array of task lines found in the content of the draft, based on active syntax definition for the draft. See Task documentation for usage details. Includes all found tasks, regardless of status.

  • Update the text representing the task to a next valid state as defined by syntax. If this task has only two states, this is effectively a toggle, if more than two states exist, the next state will be set, including cycling around to the initial state. Note that the task object is not updated to reflect changes made.

    Parameters

    Returns boolean

    boolean If true, advance was successful

  • Update the text representing the task to a completed state as defined by syntax. Note that the task object is not updated to reflect changes made.

    Parameters

    Returns boolean

    boolean If true, completion was successful

  • Update the text representing the task to a initial state as defined by syntax. Note that the task object is not updated to reflect changes made.

    Parameters

    Returns boolean

    boolean If true, reset was successful

Template

  • Get the current value of a custom template tag.

    Parameters

    • tagName: string

    Returns string

  • Runs the template string through the Mustache template engine to evaluate tags. Allows additional values and partials to be provided to the context.

    Parameters

    • template: string

      Template string

    • additionalValues: Object

      An object containing additional values you wish to make available in the Mustache context.

    • partials: Object

      An object containing string keys and values which will contain additional templates you which to make available for use as partials and layouts.

    Returns string

  • Runs the template string through the Drafts Template engine to evaluate tags.

    Parameters

    • template: string

    Returns string

  • 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}}.

    Parameters

    • tagName: string
    • value: string

    Returns void

Version

versions: Version[]

Array of versions representing the entire saved version history for this draft.

  • Create a version in the version history representing the current state of the draft.

    Returns any

Generated using TypeDoc