Okay, I think I’m getting closer very close now.
I tried this.post.save() and it apparently “works” - it seems like the PUT request is going through (using ajax under the hood), but was met with some error with little to no information. But that was before this…
The this.post.save() works. The only problem is the one listed below:
My function is now like this:
@action
async addCodeFences() {
let selectedText = this.selectedText;
let newText = "```" + "\n" + selectedText + "\n" + "```";
let post = this.post;
console.log(this.post.cooked); // Works
let rawPost = post.raw; // Doesn't exist!!
console.log(rawPost); // undefined!
rawPost.replace(selectedText, "\n" + newText + "\n"); // Error, since rawPost is undefined!
await this.post.save({
raw: rawPost,
edit_reason: I18n.t(themePrefix("add_code_fence_edit_reason"))
});
}
For some reason, I cannot get the post’s raw contents, only the cooked. Besides doing an ajax request, is there a way to do it? I can’t seem to find raw as one of the attributes for the post… is there a reason why it isn’t included?
P.S. I’m trying not to turn to Ask Discourse here. I would really appreciate any help!
EDIT: I think each post is based of this API request? And the response doesn’t seem to have raw as one of the JSON keys
.