mirror of
https://github.com/lizard-heart/obsidian-to-omnifocus.git
synced 2026-07-22 07:30:26 +00:00
feat: Move Markdown links from task name to notes
This commit is contained in:
parent
cb97c91a8b
commit
dbb0d06391
3 changed files with 27 additions and 6 deletions
|
|
@ -1,3 +1,7 @@
|
|||
## 1.2.0 (July 2024)
|
||||
|
||||
- Strips out Markdown links from task name and provides URLs in task notes
|
||||
|
||||
## 1.1.0 (July 2024)
|
||||
|
||||
- Fixes issue with vault names containing spaces (#4). Thanks to shabegom.
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "tasks-to-omnifocus",
|
||||
"name": "Send Tasks to OmniFocus",
|
||||
"version": "1.1.0",
|
||||
"version": "1.2.0",
|
||||
"minAppVersion": "0.12.0",
|
||||
"description": "An Obsidian plugin will extract tasks from the current note and create them in OmniFocus.",
|
||||
"author": "Henry Gustafson",
|
||||
|
|
|
|||
27
src/main.ts
27
src/main.ts
|
|
@ -49,17 +49,34 @@ export default class TasksToOmnifocus extends Plugin {
|
|||
for (const task of tasks) {
|
||||
let taskName = task.replace(/[-*] \[ \] /, "");
|
||||
// check if taskName has "//" followed by a date, and if so extract the date for later use and remove it from taskName
|
||||
const dateMatch = taskName.match(/(\/\/\s*)(\d{4}-\d{2}-\d{2})/);
|
||||
const dateMatch = taskName.match(/(\/\/\s*)(\d{4}-\d{2}-\d{2})\s?/);
|
||||
let taskDate = "";
|
||||
if (dateMatch) {
|
||||
taskDate = dateMatch[2];
|
||||
taskName = taskName.replace(dateMatch[0], "");
|
||||
}
|
||||
const taskNameEncoded = encodeURIComponent(taskName);
|
||||
const noteURL = view.file.path.replace(/ /g, "%20").replace(/\//g, "%2F");
|
||||
const vaultName = this.app.vault.getName().replace(/\s/g, "%20");
|
||||
const taskNoteEncoded = encodeURIComponent("obsidian://open?=" + vaultName + "&file=" + noteURL);
|
||||
|
||||
// Build a URL back to the original Obisdian page -- this will go in the task note
|
||||
const fileURL = view.file.path.replace(/ /g, "%20").replace(/\//g, "%2F");
|
||||
const vaultName = this.app.vault.getName().replace(/\s/g, "%20");
|
||||
const obsidianURL = `obsidian://open?=${vaultName}&file=${fileURL}`;
|
||||
|
||||
// taskName may contain Markdown links -- if so, strip it out of taskName but save it to taskNote
|
||||
let taskNote = obsidianURL;
|
||||
const links = taskName.match(/\[([^\]]*)\]\(([^)]*)\)/g);
|
||||
if (links) {
|
||||
taskName = taskName.replace(/\[([^\]]*)\]\(([^)]*)\)/g, "$1");
|
||||
taskNote += "\n\n";
|
||||
for (const link of links) {
|
||||
taskNote += link.replace(/\[([^\]]*)\]\(([^)]*)\)/g, "$1: $2") + "\n";
|
||||
}
|
||||
}
|
||||
// Also check taskName for [[wikilinks]], but just remove these from taskName
|
||||
taskName = taskName.replace(/\[\[([^\]]*)\]\]/g, "$1");
|
||||
|
||||
// Encode the taskName and task and send to OmniFocus
|
||||
const taskNameEncoded = encodeURIComponent(taskName);
|
||||
const taskNoteEncoded = encodeURIComponent(taskNote);
|
||||
window.open(
|
||||
`omnifocus:///add?name=${taskNameEncoded}¬e=${taskNoteEncoded}&due=${taskDate}`
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue