Attribution
This action was inspired by Add to list plus by @dchar. Add to List plus is based on Add to List by @agiletortoise.
In addition to the inspiration, the Add to List plus JavaScript code that presents a dialog to select an existing list, or creates a new one, is used in this action. The viewListAfterSuccess code has similarly been copied.
The action dialog is created and evaluated using MGCheckListPrompt, by @mattgemmell.
Help regarding the Preview (v1.1) was provided by @sylumer, @agiletortoise, and @FlohGro. For more information: End an action, yet still honor the AFTER SUCCESS configuration? - Actions - Help & Questions - Drafts Community
@sylumer suggested that this action be callable from another action. He also provided the necessary guidance.
Overview
This action can be used to add lines from a source draft to target list, i.e., another draft (formatted using markdown). The target list can be: 1) hard-coded, 2) selected from all current lists, or 3) created by this action.
Target lists are drafts that are archived and tagged with a configured value (by default the tag is list). Source drafts can be anywhere in the Drafts application.
Features
-
All lines from the source draft are added individually to the target list.
-
A time prefix (
YYYY-MM-DD HH:MM
orHH:MM
) can be included with each added line. -
Added lines can be appended or prepended.
-
A horizontal rule (-–) can be added before each group of lines added to the target draft.
-
A date line (
YYYY-MM-DD, DayOfWeek
) can be included with each group of lines added to the target draft. If this option is selected, the added date and lines are enclosed by horizontal rules. (This action includes logic to prevent horizontal rules on two consecutive lines.) -
After the target list is updated, it can be displayed in the Drafts editor and/or previewed (i.e., the markdown is rendered). Note: To preview a target list without changing it, run this action with an empty draft in the Drafts editor.
-
Blank lines above and below text in the source draft can be used or ignored. Similarly, interleaving blank lines can be used or ignored.
-
Several of the options mentioned above can be changed at runtime using an action dialog.
-
The default options can be superseded by using an action that calls this action via the Include Action step. The override options in the caller are the same as the options within this action except with an added leading underscore. For example _listTag can be used to override the option listTag. For an example caller, see: Add Lines to List (caller) | Drafts Directory.
Tested With
-
Drafts (iOS), Version 42.2.1 (415) // iOS Version 17.2.1/iPhone 15 Pro Max
-
Drafts (macOS), version 14.6.9 (14D100, Apple Silicon, sandboxed) // Sonoma 14.2.1 (23C71)/MacBookPro18,2
Version History
( expand / collapse )
1.0 - initial version
1.1
a. If the source draft is empty no content is added to the target list but it can still be loaded and/or previewed.
b. The method used to to preview the target list has been changed such that the action ends nornally; thus the action After Success configuration is honored.
2.0
a. The default options can now be superseded by using an action that calls this action via the Include Action step. The override options in the caller are the same as the options within this action except with an added leading underscore. For example _listTag can be used to override the option listTag. For an example caller, see: Add Lines to List (caller) | Drafts Directory.
b. The list dialog prompts and logic were refined.
c. Changed option excludeBlankLines to excludeInnerBlankLines.
d. The icon color was changed from green to red. By default, the icons of calling actions are green.
e. Bug fix: When addCurrentDateToEachBlock = true
and prependLines = false
, the closing horizontal rule was prepended. It is now appended.
3.0
Changed option addCurrentDateToEachLine to addCurrentTimeToEachLine. If true
, a YYYY-MM-DD HH:MM:
or a HH:MM:
prefix is added to each line before it is added to the list. If option addCurrentDateToEachBlock = true
, it will be the latter, HH:MM:
.
4.0
a. If the editor is displaying a list, it is previewed (rather than displaying an error).
b. If a specified list is not found, there is an option to create it.
c. If running the action from a blank draft, can optionally open and/or preview the configured list. Added related settings: viewListIfDraftIsEmpty, previewListIfDraftIsEmpty, promptOptionsIfDraftIsEmpty.
d. Change the default value of newListHeading to ‘###’.
e. Added settings theListFontSize (default: 80%) and theListFontFamily (default “Courier New”, Courier, Monaco, “DejaVu Sans Mono”, monospace). The former affects all of the fonts in the draft list, whereas the latter only affects the list entries in the draft list.
f. The draft content send to the Preview is modified to add a \n before and after each HORIZONTAL_RULE. That enables the content to remain condensed (vertically) in the drafts editor, while producing a preview that works better when the ‘Copy Rich Text’ (macOS) option is used.
g. If todays ‘date group’ already exists, new draft lines are added to the existing group (rather than creating a duplicate group).
h. When adding blank lines, a prefix is no longer added to each blank line.
i. The following are properly rendered when a list item is previewed. The latter three were previously supported; the first two were added to this version.
- strike through
- ==highlighted==
- this is strong
- this is italic
- this is strong italic
j. Preview font and background colors modified to work better when using ‘Copy Rich Text’ (macOS). The colors vary depending on Editor > Appearance:
light: body { background: white; color: black; }
dark: body { background: white; color: black; }
k. When Preview is selected, the list markdown content, with one modification, is written to the system clipboard. The modification is that a newline is added before and after each HORIZONTAL_RULE.
l. Bug Fix: The current time is now properly based on localtime.