coddingtonbear / obsidian-local-rest-api

Unlock your automation needs by interacting with your notes in Obsidian over a secure REST API.
MIT License
607 stars 56 forks source link

POST /active/ append method always create extra paragraph #120

Closed LuiZzz-Menezes closed 2 months ago

LuiZzz-Menezes commented 2 months ago

The POST /active/ method is creating a extra paragraph before the data. For example, when i try to send a frontmatter like "---/ntags: /n---", the plugin render this:


tags:

coddingtonbear commented 2 months ago

I'm afraid that's not a bug, but understand that it might be inconvenient for your usecase. The POST method is intended to be used for appending to an existing file, and we do ensure that your existing file ends in a newline so as to prevent folks from needing to first GET a file and then POST to it to make sure that a newline exists at the end of whatever content you're appending to (see also: https://github.com/coddingtonbear/obsidian-local-rest-api/blame/7a8b26e78cee62122f3fb6223928ade722292485/src/requestHandler.ts#L447)

Luckily, though, in your case, there's an easier option: if you're trying to write frontmatter via your request, then, as you know, that frontmatter must be the absolute first item in the document: so you should just use PUT (replace file contents) instead of POST (append to existing file contents) so as to avoid this behavior.

Good luck!