Help me understand: the post cooking process

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:
https://github.com/discourse/discourse/blob/956d15d13fd8056cbf60ca64ebbd1edca00d0125/lib/cooked_post_processor.rb
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 https://github.com/discourse/discourse/tree/f9608c0af5f7b1109117a5aba979acb00c28cf9a/app/assets/javascripts/pretty-text
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:

https://github.com/discourse/discourse/blob/d9a02d1336dd86e7fff4f14735fb0f1970555abd/app/models/post.rb#L643

which calls the cook method of the postanalyzer:

https://github.com/discourse/discourse/blob/9bff0882c3df594850de68ade2697407c84dcd7b/app/models/post_analyzer.rb#L24

this function runs the javascript markdown conversion in the backend
https://github.com/discourse/discourse/blob/9bff0882c3df594850de68ade2697407c84dcd7b/lib/pretty_text.rb#L135

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! :smiley:
Spirobel

6 Likes

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.

3 Likes

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.

1 Like