Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions jgclark.DailyJournal/src/templatesStartEnd.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,16 @@ async function ensureCorrectNoteOpen(isNoteType: Function, noteType: string, wor
* @param {string} commandName - Name of the command for logging
*/
async function renderAndInsertTemplate(
templateData: string, templateTitle: string, commandName: string
templateData: string,
templateTitle: string,
commandName: string,
): Promise<void> {
// Render the template, using recommended decoupled method of invoking a different plugin
const result = await DataStore.invokePluginCommandByName('renderTemplate', 'np.Templating', [templateTitle])
if (result == null || result === '') {
throw new Error(`No result from running Template '${templateTitle}'. Stopping.`)
}
// TEST: turning off error message for now, as it fires on Templates that only do background work.
// if (result == null || result === '') {
// throw new Error(`No result from running Template '${templateTitle}'. Stopping.`)
// }

// Work out where to insert it in the note, by reading the template, and checking
// the frontmatter attributes for a 'location' field (append/insert/cursor)
Expand Down Expand Up @@ -176,8 +179,7 @@ async function applyTemplateToNote(

} catch (error) {
logError('applyTemplateToNote', error.message)
// Turning off error message for now, as I'm getting "No result from running Template 'Daily Shutdown'. Stopping." messages when it just does background work.
// await showMessage(`Error: ${error.message}`)
await showMessage(`Error: ${error.message}`)
}
}

Expand Down
7 changes: 7 additions & 0 deletions np.Tidy/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# 🧹 Tidy Up Changelog
See Plugin [README](https://github.com/NotePlan/plugins/blob/main/np.Tidy/README.md) for full details on the available commands and use from callbacks and templates.

## [1.16.0] - 2025-11-17 @jgclark
### New
- new **/Remove empty elements from recent notes** command, that uses the same settings as the existing '/Remove empty elements' command, but applies over all recent Calendar notes. (Optionally you can include regular notes as well, if you turn on the new setting.) (For @dwertheimer)
### Changes
- The name of the existing **/Remove empty blocks** command has been changed to **/Remove empty elements** to better reflect what it does.
- This now also removes empty tasks and checklists.

## [1.15.2] - 2025-11-01 @jgclark
- updates **/List duplicated content** command to refer to the related (but simpler) new feature added to NotePlan in v3.19.2.
- to align with that, the name of the command here is changed to **/List duplicated content**. (Note: this remains different to /List duplicate notes.)
Expand Down
22 changes: 17 additions & 5 deletions np.Tidy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ This plugin provides commands to help tidy up your notes:
- **/List stubs**: creates a note that lists all your notes that contain "stubs" -- i.e. that caontain `[[note links]]` (aka "wikilinks") that don't lead to other notes in NotePlan.
- **/Move top-level tasks in Editor to heading** (alias "mtth"): Move tasks orphaned at top of active note (prior to any heading) to under a specified heading. Note: this command does not work inside a template. See section below.
- **/Remove blank notes** (alias: "rbn"): deletes any completely blank notes, or just with a starting '#' character. Note: this command cannot remove Teamspace notes (as of NotePlan v3.18.1), so it won't try.
- **/Remove empty blocks** (alias: "reb"): in the open note removes empty list items, quotations and headings, and reduces multiple empty lines to a single empty line. **Smart heading preservation**: If a subheading has content, its parent heading will be preserved even if the parent appears to have no direct content. This ensures your note structure remains intact when subheadings contain valuable information.
- **/Remove empty elements** (alias: "ree"): in the open note removes empty list items, quotations and headings, and reduces multiple empty lines to a single empty line. **Smart heading preservation**: If a subheading has content, its parent heading will be preserved even if the parent appears to have no direct content. This ensures your note structure remains intact when subheadings contain valuable information. **Note**: By default, this command only processes Calendar notes. Enable the "Also cover Project notes?" setting to also process Project notes.
- **/Remove empty elements from recent notes** (alias: "reeRecent"): as above, but for all recent notes. It uses the same settings as the command above. **Note**: Template notes (those whose filename starts with '@Templates') are automatically excluded from processing.
- **/Remove orphaned blockIDs** (alias "rob"): Remove blockIDs from lines that had been sync'd, but have become 'orphans' as the other copies of the blockID have since been deleted.
- **/Remove section from recent notes** (alias "rsrn"): Remove a given section (heading + its content block) from recently-changed notes. Can be used with parameters from Template or x-callback.
- **/Remove section from all notes** (alias "rsan"). Remove a given section (heading + its content block) from _all notes_. Use wisely, as this is dangerous! (original function by @dwertheimer)
Expand All @@ -42,31 +43,42 @@ This command catches any such completed repeats that haven't had the next repeat
### Details on /Remove empty blocks
The **/Remove empty blocks** command intelligently cleans up your notes while preserving important structure:

**What it removes:**
#### What it removes
- Empty task or checklists (e.g. `* ` or `+ ` with no further content)
- Empty list items (e.g., `- ` or `* ` with no content)
- Empty quotations (e.g., `> ` with no content)
- Empty headings (e.g., `# ` with no text)
- Multiple consecutive empty lines (reduces to single empty lines)

**Smart heading behavior:**
#### Note type coverage
- **By default**: Only processes Calendar notes (daily, weekly, monthly, quarterly, yearly notes)
- **Project notes**: Can be included by enabling the "Also cover Project notes?" setting in plugin settings, or by passing `coverRegularNotesAsWell=true` as a parameter
- **Template notes**: When using "/Remove empty elements from recent notes", Template notes (those whose filename starts with '@Templates') are automatically excluded from processing to preserve template structure which will frequently have empty sections.

#### Smart heading behavior
- **Preserves parent headings** when their subheadings contain content
- **Removes headings** only when they have no content AND no subheadings with content
- This ensures your note hierarchy stays intact when subheadings contain valuable information

**Empty line handling:**
#### Empty line handling
- **Default behavior**: Reduces multiple consecutive empty lines to a single empty line
- **Strip all empty lines**: Available as an x-callback setting to remove ALL empty lines completely
```
noteplan://x-callback-url/runPlugin?pluginID=np.Tidy&command=Remove%20empty%20elements&arg0=Editor&arg1=true
```

**Advanced options:**
#### Advanced options
- **Preserve heading structure**: Availabe as an x-callback setting. When arg2 is true, keeps ALL headings (even empty ones) to maintain note templates and structure
- This is useful for note templates where you want to keep the heading hierarchy intact
```
noteplan://x-callback-url/runPlugin?pluginID=np.Tidy&command=Remove%20empty%20elements&arg0=Editor&arg1=false&arg2=true
```

- **Process Project notes**: When arg3 is true, processes Project notes as well as Calendar notes (overrides plugin setting)
```
noteplan://x-callback-url/runPlugin?pluginID=np.Tidy&command=Remove%20empty%20elements&arg0=Editor&arg1=false&arg2=false&arg3=true
```

### Details on /List conflicted notes
Important notes:
- Conflicted notes can appear on each device you run NotePlan on, and the conflicted copies do not sync. Therefore you should consider running this on each of your devices. Each device gets its own list of conflicted notes
Expand Down
47 changes: 38 additions & 9 deletions np.Tidy/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"plugin.name": "🧹 Tidy Up",
"plugin.author": "jgclark",
"plugin.description": "Tidy up and delete various things in your NotePlan notes",
"plugin.version": "1.15.2",
"plugin.version": "1.16.0",
"plugin.releaseStatus": "full",
"plugin.lastUpdateInfo": "v1.15.2: update '/List doubled notes' command to refer to new built-in feature.\nv1.15.1: update '/File root notes' to improve menu display, particularly for Teamspace folders.\nv1.15.0: new '/Remove empty elements' command, and its setting 'Strip all empty lines?'. New setting 'Ignore future calendar notes?' for '/Remove section from all notes' command. Other fixes and improvements.\nv0.14.12: improvements to '/List duplicates' command.\nv0.14.11: improvements to '/List stubs' command.\nv0.14.10: fix regression in '/Generate @repeats from recent notes' command.\nv0.14.9: update '/Generate @repeats from recent notes' and '/Remove blank notes' commands.\nv0.14.8: improvements to '/Remove section from all notes' command.\nv0.14.7: fix regression in '/Generate @repeats from recent notes' command.\nv0.14.6: fix to allow top-level tasks to be run by template.\nv0.14.5: fix to allow top-level tasks to be run by xcallback.\nv0.14.4: fix to allow blank Calendar notes to be removed by '/remove blank notes'.\nv0.14.3: fix unwanted popups in '/generate @repeats from recent notes' command.\nv0.14.2: add new option to file root notes.\nv0.14.1: rebuild.\nv0.14.0: new '/Generate repeats' command.\nv0.13.0: '/List conflicted notes' now clears out all copies, and offers side-by-side viewing of conflicted note versions. Also bug fixes.",
"plugin.lastUpdateInfo": "v1.16.0: new '/Remove empty elements from recent notes' command.\nv1.15.2: update '/List doubled notes' command to refer to new built-in feature.\nv1.15.1: update '/File root notes' to improve menu display, particularly for Teamspace folders.\nv1.15.0: new '/Remove empty elements' command, and its setting 'Strip all empty lines?'. New setting 'Ignore future calendar notes?' for '/Remove section from all notes' command. Other fixes and improvements.\nv0.14.12: improvements to '/List duplicates' command.\nv0.14.11: improvements to '/List stubs' command.\nv0.14.10: fix regression in '/Generate @repeats from recent notes' command.\nv0.14.9: update '/Generate @repeats from recent notes' and '/Remove blank notes' commands.\nv0.14.8: improvements to '/Remove section from all notes' command.\nv0.14.7: fix regression in '/Generate @repeats from recent notes' command.\nv0.14.6: fix to allow top-level tasks to be run by template.\nv0.14.5: fix to allow top-level tasks to be run by xcallback.\nv0.14.4: fix to allow blank Calendar notes to be removed by '/remove blank notes'.\nv0.14.3: fix unwanted popups in '/generate @repeats from recent notes' command.\nv0.14.2: add new option to file root notes.\nv0.14.1: rebuild.\nv0.14.0: new '/Generate repeats' command.",
"plugin.dependencies": [],
"plugin.script": "script.js",
"plugin.url": "https://github.com/NotePlan/plugins/blob/main/np.Tidy/README.md",
Expand Down Expand Up @@ -140,7 +140,17 @@
"arguments": [
"filename (or 'Editor' for the open note in the Editor) -- default: Editor",
"stripAllEmptyLines -- default: false; By default, multiple consecutive empty lines are reduced to a single empty line. But if this is set to true, then all empty lines will be removed.",
"preserveHeadingStructure -- default: false; When true, keeps all headings (even empty ones) to maintain note templates and structure. Useful for preserving heading hierarchy in templates."
"preserveHeadingStructure -- default: false; When true, keeps all headings (even empty ones) to maintain note templates and structure. Useful for preserving heading hierarchy in templates.",
"coverRegularNotesAsWell -- default: null; By default, only Calendar notes are processed. When true, processes Project notes as well. When false or null, uses the plugin setting 'Also cover Project notes?'."
]
},
{
"name": "Remove empty elements from recent notes",
"description": "Runs 'Remove empty elements' across recently-changed notes using your settings.",
"jsFunction": "removeEmptyElementsFromRecentNotes",
"alias": [
"reeRecent",
"tidy"
]
},
{
Expand Down Expand Up @@ -380,6 +390,14 @@
"default": false,
"required": true
},
{
"title": "Also cover Project notes?",
"key": "coverProjectNotes",
"description": "By default, '/Remove empty elements' only works on Calendar notes. Enable this setting to also process Project notes.",
"type": "bool",
"default": false,
"required": true
},
{
"type": "separator"
},
Expand Down Expand Up @@ -407,6 +425,9 @@
"default": true,
"required": true
},
{
"type": "separator"
},
{
"type": "heading",
"title": "'/Remove section from all/recent notes' commands settings"
Expand Down Expand Up @@ -495,24 +516,32 @@
"required": true
},
{
"title": "Run '/Remove orphaned blockIDs' command?",
"key": "runRemoveOrphansCommand",
"title": "Run '/Remove @done() markers' command?",
"key": "runRemoveDoneMarkersCommand",
"description": "",
"type": "bool",
"default": false,
"required": true
},
{
"title": "Run '/Remove @done() markers' command?",
"key": "runRemoveDoneMarkersCommand",
"title": "Run '/Remove time parts from @done() dates' command?",
"key": "runRemoveDoneTimePartsCommand",
"description": "",
"type": "bool",
"default": false,
"required": true
},
{
"title": "Run '/Remove time parts from @done() dates' command?",
"key": "runRemoveDoneTimePartsCommand",
"title": "Run '/Remove empty elements from recent notes' command?",
"key": "runRemoveEmptyElementsFromRecentNotesCommand",
"description": "",
"type": "bool",
"default": false,
"required": true
},
{
"title": "Run '/Remove orphaned blockIDs' command?",
"key": "runRemoveOrphansCommand",
"description": "",
"type": "bool",
"default": false,
Expand Down
Loading
Loading