In a Dev category thread titled “Help me understand: the post cooking process,” spirobel seeks to understand Discourse’s post cooking workflow, particularly why post processing occurs after the post is already cooked. They reference key code files including cooked_post_processor.rb, pretty-text, and post.rb#rebake, noting that some processing is done in JavaScript (e.g., markdown conversion), while other parts involve both JavaScript and Ruby (e.g., CookedPostProcessor). spirobel questions this split and wonders if it’s for avoiding code duplication or due to historical reasons. fzngagan advises examining the frontend network tab to see what data is sent to the Rails API, pointing out the raw and cooked columns in the posts table as indicators of unprocessed vs. processed content. spirobel acknowledges the complexity and suspects the architecture evolved historically rather than being designed from first principles, deciding to explore it incrementally. The thread highlights the interplay between frontend JavaScript and backend Ruby in rendering and processing posts, and invites clarification on architectural choices and potential feature additions like oneboxes or user-specific quotes.
Hi,
I would be very glad if someone could help me understand how the post cooking process works. Especially I am interested in this part:
why does post processing happen after the post got cooked already?
Maybe we can go through the process of what would need to be done to add a feature like oneboxes or “quotes of specific users” if it wouldnt exist yet. So I came accross Prettytext discourse/app/assets/javascripts/pretty-text at f9608c0af5f7b1109117a5aba979acb00c28cf9a · discourse/discourse · GitHub
which handles to- and from- markdown conversion and the rendering of the preview box. I also found the rebake function in the post model in the backend:
which calls the cook method of the postanalyzer:
this function runs the javascript markdown conversion in the backend
my thought was, that it is done this way so there is less code duplication, but then I discovered the
CookedPostProcessor
that I linked at the top. It seems like some processing is done in javascript only, while some of it is done in javascript and ruby as well in the CookedPostProcessor. So to summarize: 1.You need to have to and from markdown conversion rules (seems like its in javascript only) 2.you need to have some code to create the html(some of it javascript but some of it also ruby) I am interested to know why (2.) is done partly in javascript and partly in ruby. Maybe you can give me an example. I would also be very happy if you can correct false assumptions I made in this post.
Thaaaanks!
Spirobel
To begin with, just see the js console network tab, to know what is captured on the frontend and passed to the server when a post is created. Which means that all of the data sent to the rails api are processed further by rails. Then in the posts table, you will see raw and cooked columns which tells you the unprocessed and processed form of the post.
Okay, thanks for your answer. I think I will just explore this piece by piece. I think maybe this “reason about it from first principles”-approach that I took does not work because this grew out of historical reasons.