Giter Site home page Giter Site logo

Comments (2)

Gelio avatar Gelio commented on June 23, 2024 1

Hey @ivan-lednev, thanks for providing a list of steps to do, as well as code to consume. That is really helpful!

So far I have noticed that updating the task in the file after moving it in the timeline is done with the following function

private updateTaskInFileContents(contents: string, task: Task) {
return contents
.split("\n")
.map((line, index) => {
if (index === task.location?.line) {
return (
line.substring(0, task.location.position.start.col) +
task.firstLineText
);
}
return line;
})
.join("\n");
}

which uses plain string manipulation. Moreover, as far as I can tell, mdast-util-from-markdown is not used in the project so far.

I believe the place I should modify to the very basic case of updating a single file when moving tasks inside of it, is:

const editPromises = Object.keys(pathToEditedTasksLookup).map(
async (path) =>
await this.obsidianFacade.editFile(path, (contents) =>
pathToEditedTasksLookup[path].reduce(
(result, current) => this.updateTaskInFileContents(result, current),
contents,
),
),
);
return Promise.all(editPromises);

I will see what I can do. I believe it will take me some time to experiment with modifying the file on the AST level. I'll share updates when I make more progress. Feel free to take over this feature if you feel like you can get it done soon

from obsidian-day-planner.

ivan-lednev avatar ivan-lednev commented on June 23, 2024

Hello, @Gelio,

To sort tasks you'll need to update src/service/plan-editor.ts. After every write to the plan, we need to

  1. grab the first block under the planner heading
  2. parse it with mdast-util-from-markdown. An abstract tree is easier to manipulate than an array of lines, and we can have subtasks, so we need this
  3. re-order top-level list items
  4. serialize it back to markdown and replace document contents

mdast-util-from-markdown handles Obsidian-flavored markdown well, but to convert it back, you can grab this utility that fixes some format discrepancies: src/mdast/mdast.ts.

Let me know if you have any other questions!

from obsidian-day-planner.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.