איך לקשט פוסט לפני שהוא מבושל?

סיכום מבוסס בינה מלאכותית

The discussion revolves around modifying a post’s content before it is cooked in Discourse, specifically for a theme component. Heddson seeks a way to alter the uncooked post text before it is displayed, aiming to preserve the original text for editing purposes. Spirobel explains that the only option for themes is to use composerBeforeSave, which affects the saved text and would appear when editing. Spirobel suggests that undoing changes upon editing could work but notes that client-side re-cooking is not ideal. He also recommends a plugin as a better solution. Heddson acknowledges the plugin route but decides to modify the cooked post instead, despite initially wanting to avoid that.

I’m writing a theme component and would like to decorate/change the posts just before they’re cooked. How can I get ahold of the uncooked post/text (for the post that’s about to be cooked/shown)?

I read the “Developer’s guide to Discourse Themes” and found that I could modify the cooked post by using the pluginAPI methods decorateCooked/decorateCookedElement and addPostTransformCallback, but didn’t find how to get it before it was cooked.

I also looked at the controllers and components, but without any luck.

you need to use this function:

which will overwrite this:

so you can change the post before its saved.
peace out. :smiley:

Thanks for your reply! But I don’t want to save the text modifications, I want to change it after it’s saved but before it’s shown (and before it’s cooked).

The reason is that I want the original text to pop-up if the user edits the post. I suspect that if I would use composerBeforeSave, the changed text would appear when editing (?).

if you want to do this as a theme this will be your only choice. userinput (markdown)-> server side cooking in ruby → (html) retrieval by other users and possible decoration. This is the promise that will be called before hitting the save/reply button. This will not show up in drafts, but you are right it would show up if you were to edit the post. if you want to get around this you need to undo the changes that you do on save when the composer opens/switches to the post you modified before. I could go into further detail or you could just read the code and do your own experiments.
cheers! :smiley:
EDIT: I just thought about this. theoretically you could also recook on the client side. But I think thats a bad idea for performance and other reasons. Or just do a plugin: (Superseded) Plugin Tutorial #1 - How to manipulate the text in the composer?

Will read up on plugins! But probably I will just modify the cooked post instead (exactly what I said I didn’t want to :smile:).

Thanks again!