Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PATCH /vault/* support for inserting content relative to block references #26

Open
coddingtonbear opened this issue Oct 12, 2022 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@coddingtonbear
Copy link
Owner

coddingtonbear commented Oct 12, 2022

The patch method supports inserting content relative to a header if you send a request like:

PATCH /path/to/some/file.md HTTP/1.1
Content-Type: text/markdown
Heading: Some heading in your document
Content-Insertion-Position: end|beginning

Obsidian also supports block references, and those references are available via the CachedMetadata API. These would require slightly different headers, though:

  • Block-Reference-Id: The ID of the block reference to insert content relative to.
  • Content-Insertion-Position: Valid values before, on, after. The values after and on differ from one another in that that on will insert text immediately before the block reference marker on the same line as it, whereas after will insert on the next line.

Use of Heading and Block-Reference-Id in the same request or using a Content-Insertion-Position invalid for the provided reference (either Heading or Block-Reference-Id) will result in a 400 error.

@coddingtonbear coddingtonbear added the enhancement New feature or request label Oct 12, 2022
@coddingtonbear coddingtonbear self-assigned this Oct 12, 2022
@coddingtonbear coddingtonbear changed the title Support for inserting content relative to block references PATCH support for inserting content relative to block references Oct 12, 2022
@coddingtonbear coddingtonbear changed the title PATCH support for inserting content relative to block references PATCH /vault/* support for inserting content relative to block references Oct 24, 2022
coddingtonbear added a commit that referenced this issue Nov 6, 2022
- Right now, it will insert either on the line before or after the block
  reference.  Idealy we'd:
  - Make 'before' insert at the beginning of the line of the block
    reference instead of on the preceding line.  If folks want to insert
    on the preceding line, they can just add a new line at the end of
    their content.
  - Add a new 'on' position that inserts at the end of the line of the
    block reference, but before the block reference ID itself.  This
    should become the default.
  - Leave 'after' as-is.
- There's a weird behavior right now where it doesn't appear that the
  CachedMetadata object is being updated when I make file changes.  This
  means that repeated REST requests will possibly insert on the wrong
  line.  I don't know what's causing this and _assume_ it's an Obsidian
  bug, but it might be something else.  I do believe that the
  CachedMetadata object is updated when I PATCH relative to a heading, at
  least.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant