Skip to content

Feature request: Optional Parameter for get_active_note_content to Exclude Frontmatter #6

@mathe00

Description

@mathe00

Issue: Optional Parameter for get_active_note_content to Exclude Frontmatter

Description

When retrieving the content of the active note using the get_active_note_content function, it would be beneficial to introduce an optional parameter that allows users to choose whether they want to retrieve the entire note's content (including frontmatter) or just the content after the frontmatter.

Many notes in Obsidian use YAML frontmatter to store metadata like tags, dates, and other properties. Modifying the note content without isolating the frontmatter can lead to accidental corruption of these properties. Since there will likely be dedicated functions to manipulate frontmatter or properties in the future, the ability to retrieve only the note's core content (ignoring the frontmatter) would avoid potential issues.

Expected Behavior

  • Introduce an optional parameter to the get_active_note_content function:
    • include_frontmatter=True (default) to retrieve the entire note, including frontmatter.
    • include_frontmatter=False to retrieve only the content after the second occurrence of a line equal to "---" (which marks the end of the frontmatter).

Example Use Cases

  1. Include Entire Note (Default):

    content = obsidian.get_active_note_content(include_frontmatter=True)

    This would return the entire content, frontmatter included.

  2. Exclude Frontmatter:

    content = obsidian.get_active_note_content(include_frontmatter=False)

    This would return only the content after the frontmatter, starting from the second "---" line.

Additional Considerations

  • Ensure that if the frontmatter is absent or incomplete (i.e., less than two "---" lines), the function behaves safely and returns the whole note as default.
  • Provide comprehensive error handling to avoid conflicts when manipulating or retrieving notes with unusual formats.

This feature would give developers more control over how they interact with note content and prevent unintentional modification of critical metadata stored in the frontmatter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions