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
51 changes: 51 additions & 0 deletions extract-todos/extract-todos.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import QtQml 2.0
import QOwnNotesTypes 1.0

Script {
property string subFolder;
property variant settingsVariables: [
{
"identifier": "subFolder",
"name": "TODO Subfolder",
"description": "Restrict search for TODOs to this note subfolder.",
"type": "string",
"default": "",
}
];

function init() {
script.registerLabel("extract todos")
extractTodos()
}

function extractTodos() {

const path = script.currentNoteFolderPath() + "/" + subFolder;
const findResult = script.startSynchronousProcess("find", ["\(", "-name", "*.md", "-or", "-name", "*.txt", "\)", "-printf", "%P\n"], "", path);
const files = findResult.toString().split("\n");

const todoRegex = /^\s*- \[ \]\s*/;
var output = "<h1>Open TODOs</h1>\n";

for (const i in files) {
const file = files[i];
const text = script.startSynchronousProcess("cat", [ file ], "", path);
const todos = text.toString()
.split("\n")
.filter(s => s.match(todoRegex))
.map(s => s.replace(todoRegex, ""));
if (todos.length > 0) {
output += "<h3>" + file + "</h3><ul>\n";
for (const j in todos) {
output += "<p>" + todos[j] + "</p>\n";
}
output += "</ul>\n";
}
}

script.setLabelText("extract todos", output);
}

function onNoteStored(note) { extractTodos() }
}

11 changes: 11 additions & 0 deletions extract-todos/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "Extract TODOs",
"identifier": "extract-todos",
"script": "extract-todos.qml",
"authors": ["@jaschop-1k5o"],
"platforms": ["linux"],
"version": "1.0",
"minAppVersion": "24.5.1",
"description" : "Continuously scan your note folder for open TODOs, and display them in the scripting panel.\n\nTODOs are identified according to Markdown syntax, by lines starting with `- [ ]`\nScanning can be restricted to a subfolder.\n(Note: Script uses `find` and `grep` in the background.)"
}