mathe00 / obsidian-plugin-python-bridge

Develop Obsidian plugins in Python! 🐍 Interact with your notes, retrieve frontmatter, send notifications, and much more – all through simple Python scripts. Cut the complexity of writing JavaScript plugins and dive into creating your Obsidian workflows with Python!
MIT License
42 stars 1 forks source link

Return Type of get_active_note_content: Dictionary of Lines vs. Full String #7

Open mathe00 opened 1 month ago

mathe00 commented 1 month ago

Problem Statement

When retrieving the content of a note using get_active_note_content, we need to decide what type of data the function should return. This decision affects both performance and ease of use. There are two main return types to consider:

  1. Option 1: Dictionary of Lines

    • Structure: Return the note's content as a dictionary, where each element represents a single line of the note.
    • Advantages:
      • Efficient for large files: Handling content line-by-line minimizes memory usage and processing overhead.
      • Easy manipulation: Developers can work with specific lines or sections of the note, simplifying tasks like editing specific parts.
      • Error handling: By processing each line individually, identifying and fixing errors is more straightforward.
    • Disadvantages:
      • Additional complexity: Developers would need to join lines if they want to work with the entire note as one block.
      • Unnecessary for small notes: For simple scripts or small notes, splitting content into lines adds unneeded complexity.
  2. Option 2: Full String

    • Structure: Return the entire content of the note as a single string, including all newline characters.
    • Advantages:
      • Simpler for full content operations: Developers can work with the entire note in one go, useful for large-scale transformations.
      • Less overhead: No need to worry about line breaks, making it more intuitive for scripts that don’t care about individual lines.
    • Disadvantages:
      • Risky for large notes: Storing and processing the entire note as a string can lead to performance issues, especially with large files.
      • Difficult to work with parts: For scripts requiring line-by-line manipulation, splitting the content into lines would need to be done manually.

Possible Solution: Parameter for Return Type

To accommodate different use cases, we could introduce a parameter that allows developers to choose the return type they prefer when calling get_active_note_content. For instance:

This approach would give developers flexibility, allowing them to pick the return type that best suits their needs:

Request for Feedback

We need input from developers on:

By allowing developers to select their preferred format, we hope to cover all bases while minimizing any performance or usability issues. Looking forward to hearing your thoughts!