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.
mermaid
are converted to mermaid division blocks for rendering with the
mermaid library.the rendering engine to use - "MMD" is MultiMarkdown, and "GFM" is GitHub Flavour Markdown.
// Example
draft.TA_MDPreviewAdvanced("MMD");
alert(draft.getTemplateTag("preview"));
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.
the text to insert into the draft.
the line number to make the insertion after.
// Example
draft.TA_addAfterLine("//foo", 5);
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.
the text to insert into the draft.
the line number to make the insertion at the end of.
// Example
draft.TA_addAtEndOfLine("//foo", 5);
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.
the text to insert into the draft.
the line number to make the insertion at the start of.
// Example
draft.TA_addAtStartOfLine("//foo", 5);
Add an array of tags to a draft. This function returns the number of tags added to the draft.
an array of tag names to be added to the draft.
// Example
draft.TA_addTags(["foo", "bar", "quz", "qux"]);
Archive all inbox drafts with a specific set of tags. Returns the number of drafts that were archived.
An array of tag names to be matched against.
// Example
draft.TA_archiveInboxDraftsTagged(["foo", "bar"]);
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();
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.
the content of the wiki-style cross-link.
// Example
draft.TA_backLinkSectionInsertLink("Another Draft's Title");
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() + "*");
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
;
when true
, causes the list of links to be deduplicated before display. Defaults to true
.
draft.TA_chooseAndOpenMDLink();
Converts all non-blank non-task lines to tasks. Uses the taskBasicStart, taskBasicComplete and taskBasicIncomplete Library settings.
// Example
draft.TA_convertAllToTasks();
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.
the encryption key used in the AES algorithm.
// Example
const ENCRYPTION_KEY = "FFEEDDCCBBAA99887766554433221100";
alert("DECODED CONTENT:" + draft.TA_decryptAES(ENCRYPTION_KEY));
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.
the encryption key used in the AES algorithm.
// Example
const ENCRYPTION_KEY = "FFEEDDCCBBAA99887766554433221100";
draft.TA_decryptAESNew(ENCRYPTION_KEY);
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 encryption key used in the AES algorithm.
// Example
const ENCRYPTION_KEY = "FFEEDDCCBBAA99887766554433221100";
draft.TA_decryptAESOntoClipboard(ENCRYPTION_KEY);
alert("DECODED CONTENT:" + app.getClipboard());
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.
the encryption key used in the AES algorithm.
// Example
const ENCRYPTION_KEY = "FFEEDDCCBBAA99887766554433221100";
draft.TA_decryptAESSelf(ENCRYPTION_KEY);
alert("DECODED CONTENT:" + app.getClipboard());
Deduplicates lines in the draft, retaining the original order of first occurrence.
// Example
draft.TA_deduplicateLines();
Adds a set of tags defined as an array of strings from the draft.
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();
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.
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();
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.
The name of the syntax for the dictated draft. Defaults to the tadBasicSyntax
property of the library object (i.e. settings).
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", "- ");
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.
The name of the syntax for the dictated draft. See Draft.TA_dictateList()
for default.
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", "* ");
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();
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();
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();
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();
Counts and returns the number of flagged drafts in a folder.
the folder (see draftFolderTab) for which to count.
// Example
alert(draft.TA_draftCountSummaryFlagged("inbox"));
Counts and returns the number of drafts (flagged & unflagged) in a folder.
the folder (see draftFolderTab) for which to count.
// Example
alert(draft.TA_draftCountSummaryFolder("archive"));
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.
the name of the tag to generate the counts for.
// Example
alert(draft.TA_draftCountSummaryTag("foo"));
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.
the nworkspace object to generate the counts for.
// Example
alert(draft.TA_draftCountSummaryWorkspace(Workspace.query("all")[0])));
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.
the text to set as the draft content.
the optional grammar/syntax for the new draft.
// Example
draft.TA_draftNew("Lorem Ipsum Dolor Sit Amet", "Plain Text");
Create a new draft based on the current clipboard content.
// Example
draft.TA_draftNewFromClipboard();
Create and load a new draft based on the current clipboard content. The editor will also be set to activate.
// Example
draft.TA_draftNewFromClipboardAndLoad();
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();
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();
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();
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();
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();
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();
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.
The syntax type the new draft should be set to.
// Example
draft.TA_draftNew_ContentSyntax(, "Markdown");
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();
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.
an array of the tag names to add to the draft.
the name of the syntax grammar type to set the draft to.
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);
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();
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();
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();
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();
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.
the encryption key used in the AES algorithm.
// Example
const ENCRYPTION_KEY = "FFEEDDCCBBAA99887766554433221100";
alert("ENCODED CONTENT:" + draft.TA_encryptAES(ENCRYPTION_KEY));
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.
the encryption key used in the AES algorithm.
// Example
const ENCRYPTION_KEY = "FFEEDDCCBBAA99887766554433221100";
draft.TA_encryptAESNew(ENCRYPTION_KEY);
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.
the encryption key used in the AES algorithm.
// Example
const ENCRYPTION_KEY = "FFEEDDCCBBAA99887766554433221100";
draft.TA_encryptAESOntoClipboard(ENCRYPTION_KEY);
alert("ENCODED CONTENT:" + app.getClipboard());
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.
the encryption key used in the AES algorithm.
// Example
const ENCRYPTION_KEY = "FFEEDDCCBBAA99887766554433221100";
draft.TA_encryptAESSelf(ENCRYPTION_KEY);
alert("ENCODED CONTENT:" + app.getClipboard());
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.
option to convert Drafts style checkboxes to HTML-base checkboxes. Defaults to false
.
// Example
draft.TA_explodedMDPreview(true);
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.
the file path the draft content should be written to.
draft.TA_exportFileMac("$HOME/Desktop/example.txt");
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.
the file path to export the draft to.
// Example
draft.TA_exportOutsideMacSandbox("$HOME/Library/Mobile Documents/com~apple~CloudDocs/Temp/readme.md");
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"));
Return an array of Markdown Headings in a draft. The hash tags are included.
// Example
alert(draft.TA_getMDHeadings()[2]);
//Shows the third heading.
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.
the number of recent drafts to retrieve. Defaults to 10.
an optional template tag string containing a Draft template tag to retrieve.
// Example
alert(draft.TA_getRecentDraftData(12, "safe_title"));
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.
the prefix string to use with the dataid
, the default is DATAID
.
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 createdmodifiedAt
- 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 modifiednumberofversions
- 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.Counts lines the number of lines in the draft.
// Example
alert(draft.TA_lineCount(0));
Pass in a base of 0 or 1 for how many lines an empty string counts as, defaults to 0.
Run a function against each line in a draft.
The name of the function to run against the line.
// Example
draft.TA_lineForEach(sendToReminders);
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)"]
.
when true
, causes the array of links to be deduplicated before being returns. Defaults to true
.
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();
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.
the string to use when joining two lines with a 'spacer'. Defaults to a single space character.
determines if lines should be trimmed of whitespace before joining. This defaults to true
.
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.
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();
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();
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");
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();
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);
Creates a new example GitHub Markdown draft.
// Example
draft.TA_newExample_GitHubMarkdown();
Creates a new example JavaScript draft.
// Example
draft.TA_newExample_JavaScript();
Creates a new example Markdown draft.
// Example
draft.TA_newExample_Markdown();
Creates a new example MultiMarkdown draft.
// Example
draft.TA_newExample_MultiMarkdown();
Creates a new example Plain Text draft.
// Example
draft.TA_newExample_PlainText();
Creates a new example Simple List draft.
// Example
draft.TA_newExample_SimpleList();
Creates a new example Taskpaper draft.
// Example
draft.TA_newExample_Taskpaper();
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();
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());
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
.
the content to push to Pastebin a new paste. Defaults to the content of the draft.
an optional title for the new paste. Defaults to the title of the draft.
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.
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.
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.
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.
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.
Process each line in the draft with a function and replace the content of the draft with the result.
the function that should be used to process each line.
// Example
function hi(strName)
{
return "Hello " + strName;
}
draft.TA_processLinesFunctionReplace(hi);
// Process each line in the draft with a function and return the result.
the function that should be used to process each line.
// Example
function hi(strName)
{
return "Hello " + strName;
}
alert(draft.TA_processLinesFunctionRetain(hi);
Get all drafts. Returns an array of all drafts, excluding those that are trashed.
// Example
alert(draft.TA_queryAllDrafts().length);
Queue up a named Drafts action to run on the draft.
Returns true
if the action was found and queued up.
the name of the action to queue up.
draft.TA_queueActionByName("TAD-Instructions");
Return a random line from a draft.
// Example
alert(draft.TA_randomLine());
Removes lines from the draft containing no content or whitespace only.
// Example
draft.TA_removeBlankLines();
Removes lines from the draft containing no content.
// Example
draft.TA_removeEmptyLines();
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();
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();
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();
Removes leading whitespace from the lines of a draft. Empty and lines only containing whitespace are removed.
// Example
draft.TA_removeWhitespaceLeading();
Removes leading and trailing whitespace from the lines of a draft. Empty and lines only containing whitespace are removed.
// Example
draft.TA_removeWhitespaceLeadingTrailing();
Removes trailing whitespace from the lines of a draft. Empty and lines only containing whitespace are removed.
// Example
draft.TA_removeWhitespaceTrailing();
Prompts the user for a tag to delete and deletes it. Displays an information message if no tags are available.
Whether to display a summary information message. true
will, false
won't (default).
// Example
draft.TA_selectAnyTagDelete(true);
Prompts the user for a tag to rename and what to rename it to. Displays an information message if no tags are available.
Whether to display a summary information message. true
will, false
won't (default).
// Example
draft.TA_selectAnyTagRename(true);
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.
Whether to display a summary information message. true
will, false
won't (default).
// Example
draft.TA_selectRecentTagDelete(true);
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.
Whether to display a summary information message. true
will, false
won't (default).
// Example
draft.TA_selectRecentTagRename(true);
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();
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.
An array of syntax names to choose from.
// Example
draft.TA_setSyntax(["Taskpaper", "Simple List"]);
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();
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.
the name of the syntax.
// Example
draft.TA_setSyntaxBuiltIn("JavaScript");
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.
the name of the syntax.
// Example
draft.TA_setSyntaxByName("JavaScript");
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.
the name of the syntax.
// Example
draft.TA_setSyntaxCustom("UpMark");
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.
the name of the syntax.
// Example
draft.TA_setSyntaxFile("UpMark");
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.
the type of the syntax.
the name of the syntax.
// Example
draft.TA_setSyntaxOfType("builtIn", "JavaScript");
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.
specifies the file extension, defaults to txt
.
when true
will run the content through the Drafts HTML processor, defaults to false
.
// Example
draft.TA_shareFile("md", false);
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();
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.
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);
Adds a set of tags defined as a string of tag names to the draft.
an array of tags to be added, with each tag being specified by name.
// Example
draft.TA_tagAddArray(["foo","bar","baz"]);
Adds a set of tags defined as a comma separated string of tag names to the draft.
a string of comma separated tags to be added, with each tag being specified by name.
// Example
draft.TA_tagAddCSV("foo,bar,baz");
Removes a tag on all drafts. Effectively deletes a tag.
The tag to be deleted.
Whether to display a summary information message. true
will, false
won't (default).
// Example
draft.TA_tagDelete("foo", "bar", true);
Return an array of all tag names held against drafts. The array is sorted in alphabetical order.
// Example
alert(draft.TA_tagFetchAll().join("\n"));
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.
an array of tags to be removed, with each tag being specified by name.
// Example
draft.TA_tagRemove(["foo", "bar"]);
Removes all tags from the draft.
// Example
draft.TA_tagRemoveAll();
Replaces a tag on all drafts with another tag. Effectively a rename of a tag on all drafts.
The original tag to be renamed.
What to rename the original tag to.
Whether to display a summary information message. true
will, false
won't (default).
// Example
draft.TA_tagRename("foo", "bar", true);
Replaces one tag on a draft with another tag. Effectively a rename of a tag on a single draft.
The original tag to be renamed.
What to rename the original tag to.
// Example
draft.TA_tagRenameInstance("foo", "bar");
Send all empty drafts to the trash. Returns the number of drafts that have been trashed.
// Example
draft.TA_trashEmptyDrafts();
Trash all inbox drafts with a specific set of tags. Returns the number of drafts that were moved to the trash.
An array of tag names to be matched against.
// Example
draft.TA_trashInboxDraftsTagged(["foo", "bar"]);
Update an embedded content block in a draft.
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()}`);
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 the total number of versions for all non-trashed drafts.
// Example
alert(draft.TA_versionCount());
Returns the highest number of versions possessed by a non-trashed draft.
// Example
alert(draft.TA_versionCountMax());
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));
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).
defaults to false
, but when set to true
, will alphabetically sort the array of links returned.
defaults to false
, but when set to true
, will ensure uniqueness of links in the array of links returned.
draft.TA_wikiLinkContent(false, true);
Counts the number of words in the draft.
// Example
alert(draft.TA_wordCount());
Draft (Drafts)
The ThoughtAsylum library includes a set of extensions to the Draft object