Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Draft

Draft (Drafts)

The ThoughtAsylum library includes a set of extensions to the Draft object

Hierarchy

  • Draft

Index

Methods

Methods

TA_MDPreviewAdvanced

  • TA_MDPreviewAdvanced(p_strEngine: string): void
  • Preview of Markdown content that includes a variety of enhancements over basic rendering. This function takes the content of a draft and converts it to HTML using the specified Markdown rendering engine. As well as the usual Markdown rendering functionality, this action modifies tge content at various stages to allow some additional functionality to be used in preview actions.

    • Wiki-style cross-links are transcluded.
    • Template tags are processed.
    • Code blocks defined as mermaid are converted to mermaid division blocks for rendering with the mermaid library.
    • Non-mermaid code blocks are modified for syntax highlighting via the highlight.js library.
    • External Base-64 encoded images are decoded and included.
    • Drafts/GitHub style checkboxes are rendered as the equivalent HTML checkboxes.
    • Critic Markdown for strikethrough is supported; GFM only as in MMD strikethrough notation denotes subscript text.
      The HTML the function generates is assigned to a custom template tag, `preview`, so that this may be included in an HTML preview action step.

    Parameters

    • p_strEngine: string

      the rendering engine to use - "MMD" is MultiMarkdown, and "GFM" is GitHub Flavour Markdown.

      // Example
      draft.TA_MDPreviewAdvanced("MMD");
      alert(draft.getTemplateTag("preview"));
      

    Returns void

TA_addAfterLine

  • TA_addAfterLine(p_strAddText: string, p_intAfterLine: number): string
  • Add text to draft after specified line. The function will split the draft into two parts after the specified line number. The additional text is wrapped with new line characters and inserted between the two. The resulting text combination is set as the content of the draft, and is returned by the function.

    Parameters

    • p_strAddText: string

      the text to insert into the draft.

    • p_intAfterLine: number

      the line number to make the insertion after.

      // Example
      draft.TA_addAfterLine("//foo", 5);
      

    Returns string

TA_addAtEndOfLine

  • TA_addAtEndOfLine(p_strAddText: string, p_intAtEndOfLine: number): string
  • Add text to draft at the end of the specified line. The function will split the draft into two parts after the specified line number. The additional text is inserted between the two with a single new line character at the end. The resulting text combination is set as the content of the draft, and is returned by the function.

    Parameters

    • p_strAddText: string

      the text to insert into the draft.

    • p_intAtEndOfLine: number

      the line number to make the insertion at the end of.

      // Example
      draft.TA_addAtEndOfLine("//foo", 5);
      

    Returns string

TA_addAtStartOfLine

  • TA_addAtStartOfLine(p_strAddText: string, p_intAtStartOfLine: number): string
  • Add text to draft at the end of the specified line. The function will split the draft into two parts before the specified line number. The additional text is inserted between the two with a single new line character at the start. The resulting text combination is set as the content of the draft, and is returned by the function.

    Parameters

    • p_strAddText: string

      the text to insert into the draft.

    • p_intAtStartOfLine: number

      the line number to make the insertion at the start of.

      // Example
      draft.TA_addAtStartOfLine("//foo", 5);
      

    Returns string

TA_addTags

  • TA_addTags(p_astrTags: string[]): number
  • Add an array of tags to a draft. This function returns the number of tags added to the draft.

    Parameters

    • p_astrTags: string[]

      an array of tag names to be added to the draft.

      // Example
      draft.TA_addTags(["foo", "bar", "quz", "qux"]);
      

    Returns number

TA_archiveInboxDraftsTagged

  • TA_archiveInboxDraftsTagged(p_astrTags: string[]): number
  • Archive all inbox drafts with a specific set of tags. Returns the number of drafts that were archived.

    Parameters

    • p_astrTags: string[]

      An array of tag names to be matched against.

      // Example
      draft.TA_archiveInboxDraftsTagged(["foo", "bar"]);
      

    Returns number

TA_backLinkAdHoc

  • TA_backLinkAdHoc(): boolean
  • Display a list of drafts that cross-link to the draft (using wiki-style links), and that the user can then select to load into the editor. The list of backlinks the function generates includes links based on the draft title and display title, with and without the d:, and for UUID based links. The list also includes a snippet of text from the draft, the last modified date (the drafts are presented most recently modified first), and the UUID; to help the user select where titles alone are non-unique, or ambiguous, or simply not specific enough to make a decision. The function returns true if the user selects and loads a draft, and false if they cancel out. The function will also return false if there are no backlinks found, as well as displaying a message to the user indicating that no backlinks could be found.

    // Example
    draft.TA_backLinkAdHoc();
    

    Returns boolean

TA_backLinkSectionInsertLink

  • TA_backLinkSectionInsertLink(p_strLink: string): void
  • Add a cross-link to the back link section of a draft. The content of the link to be added to the draft is passed in via parameter. The section is defined by a set of TadLibrary properties backlink_* that set the details for the start and end of a standardised back links section in a draft as well as some link properties too. If a back link section is available, the cross link will be created at the end of the section. If a back link section is not available, one will be created and the cross link added to it.

    Parameters

    • p_strLink: string

      the content of the wiki-style cross-link.

      // Example
      draft.TA_backLinkSectionInsertLink("Another Draft's Title");
      

    Returns void

TA_bodyFirstNonBlankLine

  • TA_bodyFirstNonBlankLine(): string
  • Return the first non-blank line in a draft's body, if available. A blank line is considered to be one only containing whitespace or no characters. Where there are no non-blank lines, a null string is returned.

    // Example
    alert("*" + draft.TA_bodyFirstNonBlankLine() + "*");
    

    Returns string

TA_chooseAndOpenMDLink

  • TA_chooseAndOpenMDLink(p_bDeduplicate?: boolean, p_bNotifyNoMatch?: boolean): boolean
  • Open a Markdown URL from the draft's content. The function identifies Markdown links in the draft's content (excluding image links) and displays a list of link titles to the user. When the user selects a title, the function will then attempt to open the corresponding URL. If an attempt is made to open a URL, the function returns true, otherwise it returns false;

    Parameters

    • Optional p_bDeduplicate: boolean

      when true, causes the list of links to be deduplicated before display. Defaults to true.

      draft.TA_chooseAndOpenMDLink();
      
    • Optional p_bNotifyNoMatch: boolean

    Returns boolean

TA_convertAllToTasks

  • TA_convertAllToTasks(): void
  • Converts all non-blank non-task lines to tasks. Uses the taskBasicStart, taskBasicComplete and taskBasicIncomplete Library settings.

    // Example
    draft.TA_convertAllToTasks();
    

    Returns void

TA_decryptAES

  • TA_decryptAES(p_strKey: string): string
  • Decrypt the content of a draft using AES encryption. This is a key-based encryption and uses the crypto-js library to do the decryption. Please choose an appropriate AES key length when encrypting (128/192/256-bit) - e.g. a 64 character hexadecimal string for 256-bit encryption. The function returns the decrypted content.

    Parameters

    • p_strKey: string

      the encryption key used in the AES algorithm.

      // Example
      const ENCRYPTION_KEY = "FFEEDDCCBBAA99887766554433221100";
      alert("DECODED CONTENT:" + draft.TA_decryptAES(ENCRYPTION_KEY));
      

    Returns string

TA_decryptAESNew

  • TA_decryptAESNew(p_strKey: string): Draft
  • Decrypt the content of a draft using AES encryption and place in a new draft. This is a key-based encryption and uses the crypto-js library to do the decryption. Please choose an appropriate AES key length when encrypting (128/192/256-bit) - e.g. a 64 character hexadecimal string for 256-bit encryption. Returns the new draft.

    Parameters

    • p_strKey: string

      the encryption key used in the AES algorithm.

      // Example
      const ENCRYPTION_KEY = "FFEEDDCCBBAA99887766554433221100";
      draft.TA_decryptAESNew(ENCRYPTION_KEY);
      

    Returns Draft

TA_decryptAESOntoClipboard

  • TA_decryptAESOntoClipboard(p_strKey: string): void
  • Decrypt the content of a draft using AES encryption. This is a key-based encryption and uses the crypto-js library to do the decryption. Please choose an appropriate AES key length when encrypting (128/192/256-bit) - e.g. a 64 character hexadecimal string for 256-bit encryption.

    Parameters

    • p_strKey: string

      the encryption key used in the AES algorithm.

      // Example
      const ENCRYPTION_KEY = "FFEEDDCCBBAA99887766554433221100";
      draft.TA_decryptAESOntoClipboard(ENCRYPTION_KEY);
      alert("DECODED CONTENT:" + app.getClipboard());
      

    Returns void

TA_decryptAESSelf

  • TA_decryptAESSelf(p_strKey: string): void
  • Replace the content of a draft with AES decryption of its content. This is a key-based encryption and uses the crypto-js library to do the decryption. Please choose an appropriate AES key length when encrypting (128/192/256-bit) - e.g. a 64 character hexadecimal string for 256-bit encryption.

    Parameters

    • p_strKey: string

      the encryption key used in the AES algorithm.

      // Example
      const ENCRYPTION_KEY = "FFEEDDCCBBAA99887766554433221100";
      draft.TA_decryptAESSelf(ENCRYPTION_KEY);
      alert("DECODED CONTENT:" + app.getClipboard());
      

    Returns void

TA_deduplicateLines

  • TA_deduplicateLines(): void
  • TA_deduplicateLines(): void
  • Deduplicates lines in the draft, retaining the original order of first occurrence.

    // Example
    draft.TA_deduplicateLines();
    

    Returns void

  • Adds a set of tags defined as an array of strings from the draft.

    Returns void

TA_deobfuscate

  • TA_deobfuscate(): void
  • Deobfuscate the content of a draft that was obfuscated by using AES encryption and the draft UUID as the key. This function is effectively a step up from ROT13 which can practically be read by sight once you know what the character mappings are. Since the encryption key is a property of the draft it is anything but crytographically secure, but it ensures that the content is not casually readable. This function's counterpart is TA_obfuscate().

    // Example
    draft.TA_deobfuscate();
    

    Returns void

TA_devBeautifyJS

  • TA_devBeautifyJS(p_jsonAltSettings?: JSON): string
  • Reformat the JavaScript content of a draft. This uses a version of the js-beautifier library. It's a little outdated, but functional for now and may be updated in the future to work with a newer library. Provision has been made for this via the library settings which hold an update location for the library. Default setings will be used unless a JSON file is present (name specified by beautifierSettings library property) in the /Library/Scripts folder in Drafts, or if the parameter is passed in via the parameter. The order of priority is the parameter, followed by the settings file, followed by the library default settings. Whatever settigns take priority, those settings will be passed to the beautification function. The default settings are available on GitHub for the js-beautifier information, and en example alternative configuration is shown below. Please note that this function should only be run on a string containing JavaScript. If this function is run on non-JavaScript, then the results could well be rather unexpected. The function returns the reformatted code.

    Parameters

    • Optional p_jsonAltSettings: JSON

      an optional set of Beautifier.js settings expressed as a JSON object. Default is undefined.

      {
          "indent_size" : 1,
          "indent_char" : "\t",
          "indent_with_tabs" : true,
          "eol" : "\n",
          "end_with_newline" : false,
          "indent_level" : 0,
          "preserve_newlines" : true,
          "max_preserve_newlines" : 10,
          "space_in_paren" : false,
          "space_in_empty_paren" : false,
          "jslint_happy" : false,
          "space_after_anon_function" : false,
          "brace_style" : "expand",
          "unindent_chained_methods" : false,
          "break_chained_methods" : false,
          "keep_array_indentation" : false,
          "unescape_strings" : false,
          "wrap_line_length" : 0,
          "e4x" : false,
          "comma_first" : false,
          "operator_position" : "before-newline",
          "eval_code" : false,
          "space_before_conditional" : true
          }
      

      // Example
      draft.TA_devBeautifyJS();
      

    Returns string

TA_dictateList

  • TA_dictateList(p_strGrammar?: string, p_strMarker?: string): boolean
  • Prompts a user to dictate a list. Each entry dicatated on a new line will be created as a separate list item. Note that you can create a new line in English dictations simply by saying "new line". By default the function will use the library defaults for a task marker - comprising a concatenation of the library properties taskBasicStart, taskBasicIncomplete, and taskBasicEnd. When dictation is received, the function will return the created draft object. When dictation is not received (e.g. if the user cancels), the draft object being used for the function will be returned.

    Parameters

    • Optional p_strGrammar: string

      The name of the syntax for the dictated draft. Defaults to the tadBasicSyntax property of the library object (i.e. settings).

    • Optional p_strMarker: string

      The string used at the start of a dictated line to mark the line as a list item. Defaults to a concatenation of tadBasicSyntax properties of the library object (i.e. settings).

      // Example
      draft.TA_dictateList("Markdown", "- ");
      

    Returns boolean

TA_dictateListAndLoad

  • TA_dictateListAndLoad(p_strGrammar: string, p_strMarker: string): Draft
  • Prompts a user to dictate a list. Each entry dicatated on a new line will be created as a separate list item. Note that you can create a new line in English dictations simply by saying "new line". By default the function will use the library defaults for a task marker - comprising a concatenation of the library properties taskBasicStart, taskIncomplete, and taskBasicEnd. When dictation is received, the function will load the new draft into the editor and return the created draft object. When dictation is not received (e.g. if the user cancels), the draft object being used for the function will loaded into the editor and it will be returned.

    Parameters

    • p_strGrammar: string

      The name of the syntax for the dictated draft. See Draft.TA_dictateList() for default.

    • p_strMarker: string

      The string used at the start of a dictated line to mark the line as a list item. See Draft.TA_dictateList() for default.

      // Example
      draft.TA_dictateListAndLoad("MultiMarkdown", "* ");
      

    Returns Draft

TA_dictateListMarkdown

  • TA_dictateListMarkdown(): Draft
  • Prompts a user to dictate a new Simple List list. Each entry dicatated on a new line will be created as a separate list item. Note that you can create a new line in English dictations simply by saying "new line". -[ ] will be used for denoting list items. When dictation is received, the function will load the new draft into the editor and return the created draft object. When dictation is not received (e.g. if the user cancels), the draft object being used for the function will loaded into the editor and it will be returned.

    // Example
    draft.TA_dictateListMarkdown();
    

    Returns Draft

TA_dictateListSimple

  • TA_dictateListSimple(): Draft
  • Prompts a user to dictate a new Simple List list. Each entry dicatated on a new line will be created as a separate list item. Note that you can create a new line in English dictations simply by saying "new line". [ ] will be used for denoting list items. When dictation is received, the function will load the new draft into the editor and return the created draft object. When dictation is not received (e.g. if the user cancels), the draft object being used for the function will loaded into the editor and it will be returned.

    // Example
    draft.TA_dictateListSimple();
    

    Returns Draft

TA_dictateListTaskpaper

  • TA_dictateListTaskpaper(): Draft
  • Prompts a user to dictate a new Taskpaper list. Each entry dicatated on a new line will be created as a separate list item. Note that you can create a new line in English dictations simply by saying "new line". - will be used for denoting list items. When dictation is received, the function will load the new draft into the editor and return the created draft object. When dictation is not received (e.g. if the user cancels), the draft object being used for the function will loaded into the editor and it will be returned.

    // Example
    draft.TA_dictateListTaskpaper();
    

    Returns Draft

TA_draftCountSummary

  • TA_draftCountSummary(): void
  • Display a count of Drafts with various breakdowns in a preview window. The counts of flagged, not flagged and total are displayed for the inbox, archive and trash folders, as well as the subtotals thereof. The counts of individual tags are displayed for flagged, not flagged, inbox, archive, total (flagged + unflagged), and trash. The counts of syntaxes are displayed for all, trashed, and total. The counts of individual workspaces are displayed for flagged, not flagged, inbox, archive, total (flagged + unflagged), and trash. The resulting summary is displayed as rendered HTML in a preview window.

    // Example
    draft.TA_draftCountSummary();
    

    Returns void

TA_draftCountSummaryFlagged

  • TA_draftCountSummaryFlagged(p_strFolder: string): number
  • Counts and returns the number of flagged drafts in a folder.

    Parameters

    • p_strFolder: string

      the folder (see draftFolderTab) for which to count.

      // Example
      alert(draft.TA_draftCountSummaryFlagged("inbox"));
      

    Returns number

TA_draftCountSummaryFolder

  • TA_draftCountSummaryFolder(p_strFolder: string): number
  • Counts and returns the number of drafts (flagged & unflagged) in a folder.

    Parameters

    • p_strFolder: string

      the folder (see draftFolderTab) for which to count.

      // Example
      alert(draft.TA_draftCountSummaryFolder("archive"));
      

    Returns number

TA_draftCountSummaryTag

  • TA_draftCountSummaryTag(p_strTag: string): string
  • Counts and returns the number of draft occurrences with a particular tag that matches a folder or attribute. The return is an HTML formatted string exclusively for use with the draft.TA_draftCountSummary function. Calculations include flagged, not flagged, inbox, archive, total and trash.

    Parameters

    • p_strTag: string

      the name of the tag to generate the counts for.

      // Example
      alert(draft.TA_draftCountSummaryTag("foo"));
      

    Returns string

TA_draftCountSummaryWorkspace

  • TA_draftCountSummaryWorkspace(p_wsInfo: Workspace): string
  • Counts and returns the number of draft occurrences within a particular workspace that matches a folder or attribute. The return is an HTML formatted string exclusively for use with the draft.TA_draftCountSummary function. Calculations include flagged, not flagged, inbox, archive, total and trash.

    Parameters

    • p_wsInfo: Workspace

      the nworkspace object to generate the counts for.

      // Example
      alert(draft.TA_draftCountSummaryWorkspace(Workspace.query("all")[0])));
      

    Returns string

TA_draftNew

  • TA_draftNew(p_strContent: string, p_strGrammar?: string): Draft
  • Create and load a new draft based on the text passed in. Includes an optional parameter to sepcify a syntax, with standard syntaxes being defined in the constant TA_DRAFTS_SYNTAX. If not defined, Drafts' setting for default new drafts will be used. The editor will also be set to activate.

    Parameters

    • p_strContent: string

      the text to set as the draft content.

    • Optional p_strGrammar: string

      the optional grammar/syntax for the new draft.

      // Example
      draft.TA_draftNew("Lorem Ipsum Dolor Sit Amet", "Plain Text");
      

    Returns Draft

TA_draftNewFromClipboard

  • TA_draftNewFromClipboard(): Draft
  • Create a new draft based on the current clipboard content.

    // Example
    draft.TA_draftNewFromClipboard();
    

    Returns Draft

TA_draftNewFromClipboardAndLoad

  • TA_draftNewFromClipboardAndLoad(): Draft
  • Create and load a new draft based on the current clipboard content. The editor will also be set to activate.

    // Example
    draft.TA_draftNewFromClipboardAndLoad();
    

    Returns Draft

TA_draftNewFromClipboardURL

  • TA_draftNewFromClipboardURL(): Draft
  • Create a new draft based on the URL on the clipboard. The content for the new draft is fetched from the URL.

    // Example
    draft.TA_draftNewFromClipboardURL();
    

    Returns Draft

TA_draftNewFromClipboardURLAndLoad

  • TA_draftNewFromClipboardURLAndLoad(): Draft
  • Create and load a new draft based on the URL on the clipboard. The content for the new draft is fetched from the URL.

    // Example
    draft.TA_draftNewFromClipboardURLAndLoad();
    

    Returns Draft

TA_draftNewFromSelection

  • TA_draftNewFromSelection(): Draft
  • Create a new draft based on the current text selection in the editor. If no text is selected, a null (Draft) object will be returned instead of a (normal) Draft object.

    // Example
    draft.TA_draftNewFromSelection();
    

    Returns Draft

TA_draftNewFromSelectionAndLoad

  • TA_draftNewFromSelectionAndLoad(): Draft
  • Create and load a new draft based on the current text selection in the editor. The editor will also be set to activate. If no text is selected, a null (Draft) object will be returned instead of a (normal) Draft object.

    // Example
    draft.TA_draftNewFromSelectionAndLoad();
    

    Returns Draft

TA_draftNewFromTemplateDraft

  • TA_draftNewFromTemplateDraft(): Draft
  • Create a new draft based on a template stored in a template draft. Template drafts are stored in drafts in a folder and with tags as defined by the TADLibrary.templateFilter and TADLibrary.templateTags settings respectively. A list of templates is displayed for the user, from which they can choose the template to use. A new draft is then created with the content.

    // Example
    draft.TA_draftNewFromTemplateDraft();
    

    Returns Draft

TA_draftNewFromTemplateFile

  • TA_draftNewFromTemplateFile(): Draft
  • Create a new draft based on a template stored in a template draft. Template drafts are stored in the Drafts /Library/Templates/ folder. A list of templates is displayed for the user, from which they can choose the template to use. A new draft is then created with the content, tags and syntax baing based ont he source template draft. Note that the tags that define the draft as a template are epxlicitly excluded when generating the new draft.

    // Example
    draft.TA_draftNewFromTemplateFile();
    

    Returns Draft

TA_draftNew_ContentSyntax

  • TA_draftNew_ContentSyntax(p_strSyntax: string): void
  • Creates a new draft with a specific set of content and a specific syntax. The content is downloaded from a public git repository, so only supported syntaxes are available. See HTTP.TA_getSyntaxTest() for additional details.

    Parameters

    • p_strSyntax: string

      The syntax type the new draft should be set to.

      // Example
      draft.TA_draftNew_ContentSyntax(, "Markdown");
      

    Returns void

TA_draftNew_Discourse

  • TA_draftNew_Discourse(): void
  • Sets an empty draft as a Discourse draft, otherwise prompts to convert the existing one or create a new one. Sets the syntax and tags of the draft based on values held in the library settings.

    // Example
    draft.TA_draftNew_Discourse();
    

    Returns void

TA_draftSetUp

  • TA_draftSetUp(p_astrTags: string[], p_strSyntax: string, p_bRemoveTags?: boolean): void
  • Sets a draft up with a set of prescribed tags and syntax based on some properties from the library settings. Sets the syntax and tags based on parameters passed to it. Note, existing tags are not removed.

    Parameters

    • p_astrTags: string[]

      an array of the tag names to add to the draft.

    • p_strSyntax: string

      the name of the syntax grammar type to set the draft to.

    • Optional p_bRemoveTags: boolean

      will remove all existing tags if set to true, set to false by default.

      // Example
      draft.TA_draftSetUp(tadLib.draft_discourse.tags, tadLib.draft_discourse.syntax, false);
      

    Returns void

TA_draftSetUp_Discourse

  • TA_draftSetUp_Discourse(): void
  • Sets a draft for use in a Discourse forum, such as Drafts' own forum. Sets the syntax and tags of the draft based on values held in the library settings.

    // Example
    draft.TA_draftSetUp_Discourse();
    

    Returns void

TA_duplicate

  • Duplicates a draft including setting the content, the syntax, and the tags. The currently loaded draft remains loaded in the editor. i.e. a live backup copy is created.

    // Example
    draft.TA_duplicate();
    

    Returns Draft

TA_duplicateAndLoad

  • TA_duplicateAndLoad(): Draft
  • Duplicates a draft including setting the content, the syntax, and the tags, and then loads the new draft into the editor.

    // Example
    draft.TA_duplicateAndLoad();
    

    Returns Draft

TA_embedDraft

  • TA_embedDraft(): boolean
  • Embed the content of one draft into another using custom embed block markers. HTML comments containing custom comments are used to mark the start and end of an embed block. This will then not be shown in Markdown and HTML previews, but they do include wiki-style cross-links to the draft that is the source of the embed for ease of access. After manual selection of the source draft, the content is included, but an additional newline is also included after the first marker to ensure that any Markdown content renders correctly. The content will not refresh automatically, but it can be triggered to refresh by various other related actions. Returns true if an embed was made, and false if it was not.

    // Example
    draft.TA_embedDraft();
    

    Returns boolean

TA_encryptAES

  • TA_encryptAES(p_strKey: string): string
  • Encrypt the content of a draft using AES encryption. This is a key-based encryption and uses the crypto-js library to do the encryption. Please choose an appropriate AES key length when encrypting (128/192/256-bit) - e.g. a 64 character hexadecimal string for 256-bit encryption. The function returns the encrypted content.

    Parameters

    • p_strKey: string

      the encryption key used in the AES algorithm.

      // Example
      const ENCRYPTION_KEY = "FFEEDDCCBBAA99887766554433221100";
      alert("ENCODED CONTENT:" + draft.TA_encryptAES(ENCRYPTION_KEY));
      

    Returns string

TA_encryptAESNew

  • TA_encryptAESNew(p_strKey: string): Draft
  • Encrypt the content of a draft using AES encryption and place in a new draft. This is a key-based encryption and uses the crypto-js library to do the encryption. Please choose an appropriate AES key length when encrypting (128/192/256-bit) - e.g. a 64 character hexadecimal string for 256-bit encryption. Returns the new draft.

    Parameters

    • p_strKey: string

      the encryption key used in the AES algorithm.

      // Example
      const ENCRYPTION_KEY = "FFEEDDCCBBAA99887766554433221100";
      draft.TA_encryptAESNew(ENCRYPTION_KEY);
      

    Returns Draft

TA_encryptAESOntoClipboard

  • TA_encryptAESOntoClipboard(p_strKey: string): void
  • Encrypt the content of a draft using AES encryption to the clipboard. This is a key-based encryption and uses the crypto-js library to do the encryption. Please choose an appropriate AES key length when encrypting (128/192/256-bit) - e.g. a 64 character hexadecimal string for 256-bit encryption.

    Parameters

    • p_strKey: string

      the encryption key used in the AES algorithm.

      // Example
      const ENCRYPTION_KEY = "FFEEDDCCBBAA99887766554433221100";
      draft.TA_encryptAESOntoClipboard(ENCRYPTION_KEY);
      alert("ENCODED CONTENT:" + app.getClipboard());
      

    Returns void

TA_encryptAESSelf

  • TA_encryptAESSelf(p_strKey: string): void
  • Replace the content of a draft with AES encryption of its content. This is a key-based encryption and uses the crypto-js library to do the encryption. Please choose an appropriate AES key length when encrypting (128/192/256-bit) - e.g. a 64 character hexadecimal string for 256-bit encryption.

    Parameters

    • p_strKey: string

      the encryption key used in the AES algorithm.

      // Example
      const ENCRYPTION_KEY = "FFEEDDCCBBAA99887766554433221100";
      draft.TA_encryptAESSelf(ENCRYPTION_KEY);
      alert("ENCODED CONTENT:" + app.getClipboard());
      

    Returns void

TA_explodedMDPreview

  • TA_explodedMDPreview(p_bConvertCheckboxes?: boolean): void
  • Preview of Markdown content that includes numerous reference expansions. The function will expand standard template utility tag inclusions (as well as other tag inclusions), a single level of wiki-style tags linked to other drafts, and local images where a Base 64 version of the image has been co-located and stored in a .b64.txt file (convention). Drafts-style checkboxes ("[ ] / [X]") can also optionally be converted to HTML-based checkboxes via the setting of a parameter. The resulting converted string is then set as the value of a custom tag for the draft, preview. This HTML populated tag is then easily referenced in subsequent action steps such as a Preview.

    Parameters

    • Optional p_bConvertCheckboxes: boolean

      option to convert Drafts style checkboxes to HTML-base checkboxes. Defaults to false.

      // Example
      draft.TA_explodedMDPreview(true);
      

    Returns void

TA_exportFileMac

  • TA_exportFileMac(p_strDestinationPath: string): boolean
  • Write the content of a draft to a destination file in the Mac file system. This function uses a shell script and so will only work on the Mac. It outputs a file to the Drafts iCloud sandboxed directory and then uses a shell script to move the file to the specified file path.

    Parameters

    • p_strDestinationPath: string

      the file path the draft content should be written to.

      draft.TA_exportFileMac("$HOME/Desktop/example.txt");
      

    Returns boolean

TA_exportOutsideMacSandbox

  • TA_exportOutsideMacSandbox(p_strDestinationPath: string): boolean
  • Export a draft to a file path outside of the Drafts sandbox. This function will only work on a Mac as it requires the execution of a shell script to move a temporary file to the final location. Returns true if the file was placed successfully, and false if it was not.

    Parameters

    • p_strDestinationPath: string

      the file path to export the draft to.

      // Example
      draft.TA_exportOutsideMacSandbox("$HOME/Library/Mobile Documents/com~apple~CloudDocs/Temp/readme.md");
      

    Returns boolean

TA_getEmailAddresses

  • TA_getEmailAddresses(): string[]
  • Get e-mail addresses from a draft. Returns an array of e-mail addresses. The array is not deduplicated, but the order of entries will match the order they occur in the draft.

    // Example
    alert(draft.TA_getEmailAddresses().join("\n"));
    

    Returns string[]

TA_getMDHeadings

  • TA_getMDHeadings(): string[]
  • Return an array of Markdown Headings in a draft. The hash tags are included.

    // Example
    alert(draft.TA_getMDHeadings()[2]);
    //Shows the third heading.
    

    Returns string[]

TA_getRecentDraftData

  • TA_getRecentDraftData(p_intSelectLimit?: number, p_strTemplateTag?: string): void
  • Display a list of recent drafts and retrieve a specific piece of data from it. If no specific data is passed in (i.e. second parameter is ""), the user will be prompted to select data to retrieve. The retrieval is based around Drafts template tags.

    Parameters

    • Optional p_intSelectLimit: number

      the number of recent drafts to retrieve. Defaults to 10.

    • Optional p_strTemplateTag: string

      an optional template tag string containing a Draft template tag to retrieve.

      // Example
      alert(draft.TA_getRecentDraftData(12, "safe_title"));
      

    Returns void

TA_infoDump

  • TA_infoDump(p_strJSONDraftDataTagPrefix?: string, p_boolReturnJSON?: boolean): JSON | string
  • Dumps a set of draft related data into JSON and a Drafts template tag. The data dump is stored in a template tag generated from the first parameter followed by an underscore and then the UUID of the draft. This function can therefore be called several times, and the draft data for several other drafts can be held against a unique ID custom tag, derivable from the original draft's UUID. The second parameter determines the function's return type.

    Parameters

    • Optional p_strJSONDraftDataTagPrefix: string

      the prefix string to use with the dataid, the default is DATAID.

    • Optional p_boolReturnJSON: boolean

      when set to true, the function returns a JSON object, when false a stringified version. The default is false.

      // Example
      alert(draft.TA_infoDump("xxx", false));
      

      The available properties included in the information "dump" are:

      • dataid - a unique identifier for this JSON/object.
      • uuid - the unique identifier for the draft.
      • content - the content of the draft.
      • title - the first line of the draft.
      • syntaxName - the syntax specified for the draft.
      • selectionStart - the integer index of the start location of the last text selection in the draft.
      • selectionLength - the number of characters in the last text selection in the draft.
      • tags - an array of the names of the tags associated with the draft.
      • isArchived - true if the tag has been archived, false otherwise.
      • isTrashed - true if the tag has been trashed, false otherwise.
      • isFlagged - true if the tag has been flagged, false otherwise.
      • createdAt - the timestamp for when the draft was created.
      • createdLatitude - the latitude at which the draft was created.
      • createdLongitude - the longitude at which the draft was created
      • modifiedAt - the timestamp for when the draft was last modified.
      • modifiedLatitude - the latitude at which the draft was last modified.
      • modifiedLongitude - the longitude at which the draft was last modified
      • numberofversions - the number of versions of the draft that Drafts has stored.
      • permalink - a URL to open the draft.
      • selection - the text selection, or the full draft content if no text was selected.
      • safe_title - the first line of the draft with ASCII control characters and path separators removed.
      • selection_only - the text selection, or an empty string if no text was selected.
      • body - all of the draft except for the first line.
      • last_line - the last line of the draft.

    Returns JSON | string

TA_lineCount

  • Counts lines the number of lines in the draft.

    // Example
    alert(draft.TA_lineCount(0));
    

    Parameters

    • Optional p_intBase: TYPE_intCountBase

      Pass in a base of 0 or 1 for how many lines an empty string counts as, defaults to 0.

    Returns number

TA_lineForEach

  • TA_lineForEach(someFunction: string): string[]
  • Run a function against each line in a draft.

    Parameters

    • someFunction: string

      The name of the function to run against the line.

      // Example
      draft.TA_lineForEach(sendToReminders);
      

    Returns string[]

TA_matchMDLinks

  • TA_matchMDLinks(p_bDeduplicate?: boolean): string[]
  • Returns an array of Markdown link substrings from the draft's content. The function identifies Markdown links in the draft's content (excluding image links) and returns an array of those links - e.g. ["[foo](https://www.foo.com", "[bar](https://www.bar.com)"].

    Parameters

    • Optional p_bDeduplicate: boolean

      when true, causes the array of links to be deduplicated before being returns. Defaults to true.

    Returns string[]

TA_mdTitleLinks

  • TA_mdTitleLinks(): void
  • Convert all non-linked URLs as Markdown links using the page name as the title. The function finds URLs in the string and uses the prior two characters to determine if it is part of a Markdown link (preceded by ](), or an HTML source (preceded by ="). If it is not preceded by these, the URL will be used to fetch the page title. That title is then used to build a Markdown link which will replace all occurrences in the string of the URL. Note, each unique URL is only fetched once to ensure that the function runs faster; Before any updates are made to the draft, it forces a version to be saved and only then updates the draft. This means that you can easily revert to the previous state by restoring the previous version.

    // Example
    draft.TA_mdTitleLinks();
    

    Returns void

TA_mergeLines

  • TA_mergeLines(p_strSpacer?: string, p_bTrimLines?: boolean, p_astrContinue?: string[], p_astrForce?: string[]): string
  • Replace new lines to merge a draft's content into one line. Effectively concatenates multiple lines into one line (assuming the 'spacer' parameter does not contain a new line). The default character to concatenate lines with is a space, but can be set to any string. The function also allows an aray of exceptions to be specified, whereby if a line ends with one of those string, no spacer will be added. This can be further modified by a similar array that can specify when a line ending with a particular character string will always force a spacer to be included. The function returns the modified, merged string and sets the content of the draft to that string.

    Parameters

    • Optional p_strSpacer: string

      the string to use when joining two lines with a 'spacer'. Defaults to a single space character.

    • Optional p_bTrimLines: boolean

      determines if lines should be trimmed of whitespace before joining. This defaults to true.

    • Optional p_astrContinue: string[]

      an array of line endings where the next line should be joined to the current one with no 'spacer'. Defaults to an array including a hyphen, em dash, en dash and forward slash.

    • Optional p_astrForce: string[]

      an array of line endings where the next line should always be joined to the current one with a 'spacer'. Defaults to an empty array.

      draft.TA_mergeLines();
      

    Returns string

TA_metaRead

  • TA_metaRead(): void
  • Merge data for the draft from the custom meta data file into the custom meta data for the draft. The path to the data file is held in a TadLibrary instance property - tadLib.metaPath. The meta data for the draft is specified as sub-properties of the draft's meta property. If the draft does not have such a property, calling this function will initialise it. Data from the file, if the file exists, and if it contains any data will be merged with the meta data of the draft, and the draft's meta data property will be set as the combined set of data. Note that if the draft contains a meta property with a value that also has a value specified in the file, the resulting value of the draft will be the one from the file.

    // Example
    draft.TA_metaRead();
    

    Returns void

TA_metaTag

  • TA_metaTag(p_strPropertyName: string): void
  • Set a template tag for a draft for a cusrtom meta data property. This is to allow the value of a property to be referenced in other action steps that utilise template tags. The name of the template tag will be meta_ forrowed by the name of the property, and it's value will be that of the property at the time this function was called.

    // Example
    draft.TA_metaTag("author");
    

    Parameters

    • p_strPropertyName: string

    Returns void

TA_metaWrite

  • TA_metaWrite(): void
  • Replace the data for the draft in the custom meta data file with the custom meta data of the draft. The path to the data file is held in a TadLibrary instance property - tadLib.metaPath. The meta data for the draft is specified as sub-properties of the draft's meta property. If the draft does not have such a property, calling this function will initialise it. The file and data structure to save to the file will also be created if required. The data of the file will be entirely replaced with the data of the object. This means that if in the file the draft has a property x that is not defined for the draft object, x and its value will be removed when the draft meta data is saved to file. This is on purpose as then if you delete a meta data from the draft object and use this function to wriet the data, that property and its data will be removed from the file.

    // Example
    draft.TA_metaWrite();
    

    Returns void

TA_navigationMarkersGet

  • Return navigation markers for a draft. Temporarily loads the specified draft and queries the editor for the navigation markers, then reloads the original draft and restores the text selection. The function returns an array of standard Drafts navigation marker objects.

    alert(Draft.find("0BACEC09-708F-424B-81E3-39F3BF2A11B7").TA_navigationMarkersGet().length);
    

    Returns navigationMarker[]

TA_newExample_GitHubMarkdown

  • TA_newExample_GitHubMarkdown(): void
  • Creates a new example GitHub Markdown draft.

    // Example
    draft.TA_newExample_GitHubMarkdown();
    

    Returns void

TA_newExample_JavaScript

  • TA_newExample_JavaScript(): void
  • Creates a new example JavaScript draft.

    // Example
    draft.TA_newExample_JavaScript();
    

    Returns void

TA_newExample_Markdown

  • TA_newExample_Markdown(): void
  • Creates a new example Markdown draft.

    // Example
    draft.TA_newExample_Markdown();
    

    Returns void

TA_newExample_MultiMarkdown

  • TA_newExample_MultiMarkdown(): void
  • Creates a new example MultiMarkdown draft.

    // Example
    draft.TA_newExample_MultiMarkdown();
    

    Returns void

TA_newExample_PlainText

  • TA_newExample_PlainText(): void
  • Creates a new example Plain Text draft.

    // Example
    draft.TA_newExample_PlainText();
    

    Returns void

TA_newExample_SimpleList

  • TA_newExample_SimpleList(): void
  • Creates a new example Simple List draft.

    // Example
    draft.TA_newExample_SimpleList();
    

    Returns void

TA_newExample_Taskpaper

  • TA_newExample_Taskpaper(): void
  • Creates a new example Taskpaper draft.

    // Example
    draft.TA_newExample_Taskpaper();
    

    Returns void

TA_obfuscate

  • TA_obfuscate(): void
  • Obfuscate the content of a draft by using AES encryption and the draft UUID as the key. This function is effectively a step up from ROT13 which can practically be read by sight once you know what the character mappings are. Since the encryption key is a property of the draft it is anything but crytographically secure, but it ensures that the content is not casually readable. This function's counterpart is TA_deobfuscate().

    // Example
    draft.TA_obfuscate();
    

    Returns void

TA_postBodyToPastebin

  • TA_postBodyToPastebin(): string
  • Convenience function to post a public paste to Pastebin of the current draft with the paste being the body of the draft. This function returns the URL of the newly created paste when successful. If unsuccessful an error message is displayed and the function will return undefined.

    // Example
    alert(draft.TA_postBodyToPastebin());
    

    Returns string

TA_postToPastebin

  • TA_postToPastebin(p_strContent?: string, p_strTitle?: string, p_bCopyResult?: boolean, p_intPrivacy?: number, p_strSyntax?: string, p_strExpiry?: string, p_strFolderID?: string): string
  • Post to Pastebin based on current draft. By default the function will use the content of the draft as the paste content and the title of the draft as the paste title. This function returns the URL of the newly created paste when successful. If unsuccessful an error message is displayed and the function will return undefined.

    Parameters

    • Optional p_strContent: string

      the content to push to Pastebin a new paste. Defaults to the content of the draft.

    • Optional p_strTitle: string

      an optional title for the new paste. Defaults to the title of the draft.

    • Optional p_bCopyResult: boolean

      when set to true, the default, a link to the newly created paste will be copied to the clipboard. When set to false, or if the creation fails, no change to the clipboard will take place.

    • Optional p_intPrivacy: number

      this can be set to 0,1 or 2. The default is 0 and will result in a paste that is available publicly. When set to 1, it will be available publicly, but not listed publicly. When set to 2 the paste will be private and not available publicly.

    • Optional p_strSyntax: string

      by default, a new paste will try to be matched to the correct syntax available on Pastebin if one of the original default Drafts syntaxes. Over 200 syntaxes are supported by Pastebin and you can pass in the relevant syntax name as a string for this parameter to set the syntax - available syntaxes are listed against the api_paste_format API option listed on the API documentation page.

    • Optional p_strExpiry: string

      by default pastes are not set to expire, but the Pastebin supports shorthand text strings that it can parse to specify an expiry. Details of how to construct these strings can be found on the API documentation page under the details for the api_paste_expire_date API option.

    • Optional p_strFolderID: string

      by default pastes are not saved to a folder, but you can choose to save them to a particular folder. Enter the ID string for your folder for this paramater. The ID is the last part of the URL for viewing your folder.

      // Example
      alert(draft.TA_postToPastebin(draft.processTemplate("[[date]]"), draft.content, true, 2));
      // Posts a private paste of the current draft content with the title being the current date, auto setting the syntax.
      

    Returns string

TA_processLinesFunctionReplace

  • TA_processLinesFunctionReplace(p_funcCallback: Function): void
  • Process each line in the draft with a function and replace the content of the draft with the result.

    Parameters

    • p_funcCallback: Function

      the function that should be used to process each line.

      // Example
      function hi(strName)
      {
          return "Hello " + strName;
      }
      draft.TA_processLinesFunctionReplace(hi);
      

    Returns void

TA_processLinesFunctionRetain

  • TA_processLinesFunctionRetain(p_funcCallback: Function): string
  • // Process each line in the draft with a function and return the result.

    Parameters

    • p_funcCallback: Function

      the function that should be used to process each line.

      // Example
      function hi(strName)
      {
          return "Hello " + strName;
      }
      alert(draft.TA_processLinesFunctionRetain(hi);
      

    Returns string

TA_queryAllDrafts

  • TA_queryAllDrafts(): Draft[]
  • Get all drafts. Returns an array of all drafts, excluding those that are trashed.

    // Example
    alert(draft.TA_queryAllDrafts().length);
    

    Returns Draft[]

TA_queueActionByName

  • TA_queueActionByName(p_strName: string): boolean
  • Queue up a named Drafts action to run on the draft. Returns true if the action was found and queued up.

    Parameters

    • p_strName: string

      the name of the action to queue up.

      draft.TA_queueActionByName("TAD-Instructions");
      

    Returns boolean

TA_randomLine

  • TA_randomLine(): string
  • Return a random line from a draft.

    // Example
    alert(draft.TA_randomLine());
    

    Returns string

TA_removeBlankLines

  • TA_removeBlankLines(): void
  • Removes lines from the draft containing no content or whitespace only.

    // Example
    draft.TA_removeBlankLines();
    

    Returns void

TA_removeEmptyLines

  • TA_removeEmptyLines(): void
  • Removes lines from the draft containing no content.

    // Example
    draft.TA_removeEmptyLines();
    

    Returns void

TA_removeSpaceTabLeading

  • TA_removeSpaceTabLeading(): void
  • Removes leading spaces and tabs from the lines of a draft. Lines containing only spaces and tabs remain as empty lines. Initially empty lines remain unaffected.

    // Example
    draft.TA_removeSpaceTabLeading();
    

    Returns void

TA_removeSpaceTabLeadingTrailing

  • TA_removeSpaceTabLeadingTrailing(): void
  • Removes leading and trailing spaces and tabs from the lines of a draft. Lines containing only spaces and tabs remain as empty lines. Initially empty lines remain unaffected.

    // Example
    draft.TA_removeSpaceTabLeadingTrailing();
    

    Returns void

TA_removeSpaceTabTrailing

  • TA_removeSpaceTabTrailing(): void
  • Removes trailing spaces and tabs from the lines of a draft. Lines containing only spaces and tabs remain as empty lines. Initially empty lines remain unaffected.

    // Example
    draft.TA_removeSpaceTabTrailing();
    

    Returns void

TA_removeWhitespaceLeading

  • TA_removeWhitespaceLeading(): void
  • Removes leading whitespace from the lines of a draft. Empty and lines only containing whitespace are removed.

    // Example
    draft.TA_removeWhitespaceLeading();
    

    Returns void

TA_removeWhitespaceLeadingTrailing

  • TA_removeWhitespaceLeadingTrailing(): void
  • Removes leading and trailing whitespace from the lines of a draft. Empty and lines only containing whitespace are removed.

    // Example
    draft.TA_removeWhitespaceLeadingTrailing();
    

    Returns void

TA_removeWhitespaceTrailing

  • TA_removeWhitespaceTrailing(): void
  • Removes trailing whitespace from the lines of a draft. Empty and lines only containing whitespace are removed.

    // Example
    draft.TA_removeWhitespaceTrailing();
    

    Returns void

TA_selectAnyTagDelete

  • TA_selectAnyTagDelete(p_bInfo?: boolean): void
  • Prompts the user for a tag to delete and deletes it. Displays an information message if no tags are available.

    Parameters

    • Optional p_bInfo: boolean

      Whether to display a summary information message. true will, false won't (default).

      // Example
      draft.TA_selectAnyTagDelete(true);
      

    Returns void

TA_selectAnyTagRename

  • TA_selectAnyTagRename(p_bInfo?: boolean): void
  • Prompts the user for a tag to rename and what to rename it to. Displays an information message if no tags are available.

    Parameters

    • Optional p_bInfo: boolean

      Whether to display a summary information message. true will, false won't (default).

      // Example
      draft.TA_selectAnyTagRename(true);
      

    Returns void

TA_selectRecentTagDelete

  • TA_selectRecentTagDelete(p_bInfo?: boolean): void
  • Prompts the user for a tag to delete from a list of recent tags, and then deletes it. Displays an information message if no tags are available.

    Parameters

    • Optional p_bInfo: boolean

      Whether to display a summary information message. true will, false won't (default).

      // Example
      draft.TA_selectRecentTagDelete(true);
      

    Returns void

TA_selectRecentTagRename

  • TA_selectRecentTagRename(p_bInfo?: boolean): void
  • Prompts the user for a tag to rename from a list of recent tags, and what to rename it to. Displays an information message if no tags are available.

    Parameters

    • Optional p_bInfo: boolean

      Whether to display a summary information message. true will, false won't (default).

      // Example
      draft.TA_selectRecentTagRename(true);
      

    Returns void

TA_selectSetTags

  • TA_selectSetTags(): boolean
  • Set a draft's tags based on all previously used tags and what it currently has set. This allows the user to turn existing tags on and off against the draft. Returns true if changes are applied, and false if the user cancels.

    // Example
    draft.TA_selectSetTags();
    

    Returns boolean

TA_setSyntax

  • TA_setSyntax(p_astrSyntaxes: string[]): boolean
  • Displays a pop up window to allow the user to specify a syntax. The syntax names passed in should be exact matches to valid Drafts syntax types, and will be displayed as a list of buttons in the order they are provided to the function. Returns true if the user changes the syntax.

    Parameters

    • p_astrSyntaxes: string[]

      An array of syntax names to choose from.

      // Example
      draft.TA_setSyntax(["Taskpaper", "Simple List"]);
      

    Returns boolean

TA_setSyntaxAllStandard

  • TA_setSyntaxAllStandard(): boolean
  • Displays a pop up window to allow the user to specify a syntax from the standard Drafts syntaxes. Standard syntaxes are defined in the constant TA_DRAFTS_SYNTAX. Returns true if the user changes the syntax.

    // Example
    draft.TA_setSyntaxAllStandard();
    

    Returns boolean

TA_setSyntaxBuiltIn

  • TA_setSyntaxBuiltIn(p_strSyntax: string): void
  • Set the syntax of a draft to a built-in type. The name of the syntax must be known. The function will search for a matching syntax of type 'built-in', and once a match is found, that will be used for the setting of the specification for the draft. If no matches are found, the syntax of the draft will remain unchanged.

    Parameters

    • p_strSyntax: string

      the name of the syntax.

      // Example
      draft.TA_setSyntaxBuiltIn("JavaScript");
      

    Returns void

TA_setSyntaxByName

  • TA_setSyntaxByName(p_strSyntax: string): void
  • Set the syntax of a draft to an unknown type. The name of the syntax must be known, but the type of the syntax need not be known. The function will search for a matching syntax type in the following order: built in syntaxes, then custom syntaxes, and finally file syntaxes. Once a match is found, that will be used for the setting of the specification for the draft. If no matches are found, the syntax of the draft will remain unchanged.

    Parameters

    • p_strSyntax: string

      the name of the syntax.

      // Example
      draft.TA_setSyntaxByName("JavaScript");
      

    Returns void

TA_setSyntaxCustom

  • TA_setSyntaxCustom(p_strSyntax: string): void
  • Set the syntax of a draft to a custom type. The name of the syntax must be known. The function will search for a matching syntax of type 'custom', and once a match is found, that will be used for the setting of the specification for the draft. If no matches are found, the syntax of the draft will remain unchanged.

    Parameters

    • p_strSyntax: string

      the name of the syntax.

      // Example
      draft.TA_setSyntaxCustom("UpMark");
      

    Returns void

TA_setSyntaxFile

  • TA_setSyntaxFile(p_strSyntax: string): void
  • Set the syntax of a draft to a file type. The name of the syntax must be known. The function will search for a matching syntax of type 'file', and once a match is found, that will be used for the setting of the specification for the draft. If no matches are found, the syntax of the draft will remain unchanged.

    Parameters

    • p_strSyntax: string

      the name of the syntax.

      // Example
      draft.TA_setSyntaxFile("UpMark");
      

    Returns void

TA_setSyntaxOfType

  • TA_setSyntaxOfType(p_stType: syntaxType, p_strSyntax: string): void
  • Set the syntax of a draft to a syntax of a specific type. The name and type of the syntax must be known. The function will search for a matching syntax and once a match is found, that will be used for the setting of the specification for the draft. If no matches are found, the syntax of the draft will remain unchanged.

    Parameters

    • p_stType: syntaxType

      the type of the syntax.

    • p_strSyntax: string

      the name of the syntax.

      // Example
      draft.TA_setSyntaxOfType("builtIn", "JavaScript");
      

    Returns void

TA_shareFile

  • TA_shareFile(p_strFileExtension?: string, p_bAsHTML?: boolean): void
  • Quick share the content of a draft as a file. Uses the draft's safe title as the default for the filename, but if that happens to be null, will use the current timestamp instead. The user is prompted to change the filename, and after confirming, the content is passed to the share sheet. Note that if the second parameter is set to true, the content will process the content to HTML. This is useful for sharing a Markdown file as an HTML equivalent for example.

    Parameters

    • Optional p_strFileExtension: string

      specifies the file extension, defaults to txt.

    • Optional p_bAsHTML: boolean

      when true will run the content through the Drafts HTML processor, defaults to false.

      // Example
      draft.TA_shareFile("md", false);
      

    Returns void

TA_shareFileBasedOnSyntax

  • TA_shareFileBasedOnSyntax(): void
  • Quick share the content of a draft as a file based on the syntax of the draft. Uses the draft's safe title as the default for the filename, but if that happens to be null, will use the current timestamp instead. The file extension is derived from the syntax and information specified in the tadLibrary settings for different types of drafts. The user is prompted to change the filename, and after confirming, the content is passed to the share sheet.

    // Example
    draft.TA_shareFileBasedOnSyntax();
    

    Returns void

TA_split

  • TA_split(p_bLoadSecondDraft?: boolean): void
  • Splits a draft based on the position of the selection in the currently loaded draft. This is generally intended to be run against the currently active draft in the editor, but if you have an exact duplicate, it could be reasonably run against that instead, based on your current selection. After split, the editor is reactivated.

    Parameters

    • Optional p_bLoadSecondDraft: boolean

      when true, will load the second draft of the split. When false, the default, it will retain the currently loaded draft (typically the first of the split).

      // Example
      draft.TA_split(true);
      

    Returns void

TA_tagAddArray

  • TA_tagAddArray(p_astrTags: string[]): void
  • Adds a set of tags defined as a string of tag names to the draft.

    Parameters

    • p_astrTags: string[]

      an array of tags to be added, with each tag being specified by name.

      // Example
      draft.TA_tagAddArray(["foo","bar","baz"]);
      

    Returns void

TA_tagAddCSV

  • TA_tagAddCSV(p_strTags: string): void
  • Adds a set of tags defined as a comma separated string of tag names to the draft.

    Parameters

    • p_strTags: string

      a string of comma separated tags to be added, with each tag being specified by name.

      // Example
      draft.TA_tagAddCSV("foo,bar,baz");
      

    Returns void

TA_tagDelete

  • TA_tagDelete(p_strTag: string, p_bInfo?: boolean): void
  • Removes a tag on all drafts. Effectively deletes a tag.

    Parameters

    • p_strTag: string

      The tag to be deleted.

    • Optional p_bInfo: boolean

      Whether to display a summary information message. true will, false won't (default).

      // Example
      draft.TA_tagDelete("foo", "bar", true);
      

    Returns void

TA_tagFetchAll

  • TA_tagFetchAll(): string[]
  • Return an array of all tag names held against drafts. The array is sorted in alphabetical order.

    // Example
    alert(draft.TA_tagFetchAll().join("\n"));
    

    Returns string[]

TA_tagRemove

  • TA_tagRemove(p_astrTags: string[]): void
  • Removes a set of tags defined as an array of strings from the draft. Tags marked for removal that are not associated with the tag are effectively ignored.

    Parameters

    • p_astrTags: string[]

      an array of tags to be removed, with each tag being specified by name.

      // Example
      draft.TA_tagRemove(["foo", "bar"]);
      

    Returns void

TA_tagRemoveAll

  • TA_tagRemoveAll(): void
  • Removes all tags from the draft.

    // Example
    draft.TA_tagRemoveAll();
    

    Returns void

TA_tagRename

  • TA_tagRename(p_strFrom: string, p_strTo: string, p_bInfo?: boolean): void
  • Replaces a tag on all drafts with another tag. Effectively a rename of a tag on all drafts.

    Parameters

    • p_strFrom: string

      The original tag to be renamed.

    • p_strTo: string

      What to rename the original tag to.

    • Optional p_bInfo: boolean

      Whether to display a summary information message. true will, false won't (default).

      // Example
      draft.TA_tagRename("foo", "bar", true);
      

    Returns void

TA_tagRenameInstance

  • TA_tagRenameInstance(p_strFrom: string, p_strTo: string): void
  • Replaces one tag on a draft with another tag. Effectively a rename of a tag on a single draft.

    Parameters

    • p_strFrom: string

      The original tag to be renamed.

    • p_strTo: string

      What to rename the original tag to.

      // Example
      draft.TA_tagRenameInstance("foo", "bar");
      

    Returns void

TA_trashEmptyDrafts

  • TA_trashEmptyDrafts(): number
  • Send all empty drafts to the trash. Returns the number of drafts that have been trashed.

    // Example
    draft.TA_trashEmptyDrafts();
    

    Returns number

TA_trashInboxDraftsTagged

  • TA_trashInboxDraftsTagged(p_astrTags: string[]): number
  • Trash all inbox drafts with a specific set of tags. Returns the number of drafts that were moved to the trash.

    Parameters

    • p_astrTags: string[]

      An array of tag names to be matched against.

      // Example
      draft.TA_trashInboxDraftsTagged(["foo", "bar"]);
      

    Returns number

TA_updateEmbed

  • TA_updateEmbed(): void
  • Update an embedded content block in a draft.

    Returns void

TA_updateEmbedsInDraft

  • TA_updateEmbedsInDraft(): number
  • For a draft, update all of the embeds within it. All embed blocks within the draft are refreshed.

    // Example
    app.TA_displayInfoMessage(`Number of Embeds Refreshed: ${draft.TA_updateEmbedsInDraft()}`);
    

    Returns number

TA_updateEmbedsOfDraft

  • TA_updateEmbedsOfDraft(): number
  • For a draft, embed all the other drafts that embed it. All other drafts containing an embed block for the draft are refreshed.

    // Example
    app.TA_displayInfoMessage(`Number of Drafts Refreshed: ${draft.TA_updateEmbedsOfDraft()}`);
    

    Returns number

TA_versionCount

  • TA_versionCount(): number
  • Returns the total number of versions for all non-trashed drafts.

    // Example
    alert(draft.TA_versionCount());
    

    Returns number

TA_versionCountMax

  • TA_versionCountMax(): number
  • Returns the highest number of versions possessed by a non-trashed draft.

    // Example
    alert(draft.TA_versionCountMax());
    

    Returns number

TA_versionDraftMax

  • TA_versionDraftMax(): number
  • Returns an array of drafts with the highest number of versions possessed by a non-trashed draft.

    // Example - load a draft with the highest number of versions
    editor.load(Draft.find(draft.TA_versionDraftMax()[0].uuid));
    

    Returns number

TA_wikiLinkContent

  • TA_wikiLinkContent(p_bSort?: boolean, p_bUnique?: boolean): string[]
  • Extract Drafts wiki-link content from a draft's content. Parameters allow the links to be sorted alphabetically and deduplicated. Returns an array of all matching content (with the square brackets removed).

    Parameters

    • Optional p_bSort: boolean

      defaults to false, but when set to true, will alphabetically sort the array of links returned.

    • Optional p_bUnique: boolean

      defaults to false, but when set to true, will ensure uniqueness of links in the array of links returned.

      draft.TA_wikiLinkContent(false, true);
      

    Returns string[]

TA_wordCount

  • TA_wordCount(): number
  • Counts the number of words in the draft.

    // Example
    alert(draft.TA_wordCount());
    

    Returns number