drafts
drafts copied to clipboard
Markdown Lists Reformat (*⇨-) Action
Markdown Lists Reformat (*⇨-) Action
Updated 08042024-192559
- GitHub Issue
- Drafts Directory -
https://directory.getdrafts.com/a/2Tt - WTF
- ID:
05C65F71-6E28-441A-A808-845F6C7FE2EF - Draft
Social
no idea why I hadn't before just made an Action for this but ... I have now. https://directory.getdrafts.com/a/2Tt
Meta
Description
Changes (replaces) any [* ]-formatted Markdown lists in the current Draft to hyphen format (- ).
Directory Description
Changes (replaces) any [* ]-formatted Markdown lists in the current Draft to hyphen format (- ) via regex (/^\*\s+/gm).
Source
- SnippetsLab
drafts://action?data=%7B%22groupDisposition%22:0,%22backingAssignFlag%22:0,%22uuid%22:%224693AE3F-BB41-4FCA-B494-64D9D65AA93B%22,%22backingPlatforms%22:3,%22keyCommand%22:%7B%22discoverabilityTitle%22:%22Markdown%20Lists%20Reformat%20(*%E2%87%A8-)%22,%22controlKey%22:false,%22shiftKey%22:false,%22input%22:%22%22,%22optionKey%22:false,%22type%22:%22action%22,%22commandKey%22:false%7D,%22actionDescription%22:%22Changes%20(replaces)%20any%20%5B*%20%5D-formatted%20Markdown%20lists%20in%20the%20current%20Draft%20to%20hyphen%20format%20(-%20).%22,%22disposition%22:0,%22assignTags%22:%5B%5D,%22visibility%22:2016,%22shouldConfirm%22:false,%22keyUseIcon%22:false,%22groupUUID%22:%22896E9936-31AB-4722-A67D-AA578EABE763%22,%22tintColor%22:%22yellow%22,%22backingIsSeparator%22:false,%22steps%22:%5B%7B%22platforms%22:3,%22type%22:%22script%22,%22isEnabled%22:true,%22data%22:%7B%22allowAsync%22:%22false%22,%22script%22:%22%5C/%5C/%20Get%20the%20content%20of%20the%20current%20draft%5Cnlet%20content%20%3D%20draft.content;%5Cn%5Cn%5C/%5C/%20Define%20a%20regular%20expression%20to%20find%20all%20instances%20of%20lists%20formatted%20with%20%5B*%20%5D%5Cnlet%20regex%20%3D%20%5C/%5E%5C%5C*%5C%5Cs+%5C/gm;%5Cn%5Cn%5C/%5C/%20Replace%20the%20matches%20with%20%5B-%20%5D%5Cnlet%20updatedContent%20%3D%20content.replace(regex,%20'-%20');%5Cn%5Cn%5C/%5C/%20Update%20the%20draft%20content%20with%20the%20new%20format%5Cndraft.content%20%3D%20updatedContent;%5Cn%5Cn%5C/%5C/%20Save%20the%20draft%5Cndraft.update();%22%7D,%22uuid%22:%22FFE84C7E-4D9B-42F5-8CAE-01DD2211837A%22%7D%5D,%22notificationType%22:2,%22name%22:%22Markdown%20Lists%20Reformat%20(*%E2%87%A8-)%22,%22icon%22:%22400-list2%22,%22logLevel%22:1,%22shortName%22:%22%22%7D
// Get the content of the current draft
let content = draft.content;
// Define a regular expression to find all instances of lists formatted with [* ]
let regex = /^\*\s+/gm;
// Replace the matches with [- ]
let updatedContent = content.replace(regex, '- ');
// Update the draft content with the new format
draft.content = updatedContent;
// Save the draft
draft.update();