# Help me understand: the post cooking process

**URL:** https://meta.discourse.org/t/help-me-understand-the-post-cooking-process/153206
**Category:** Development
**Created:** [May 29, 2020, 9:51am UTC](https://meta.discourse.org/t/help-me-understand-the-post-cooking-process/153206 "2020-05-29T09:51:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![spirobel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/spirobel/32/170908_2.png) [@spirobel](https://meta.discourse.org/u/spirobel)
#### Post date: [May 29, 2020, 9:51am UTC](https://meta.discourse.org/t/help-me-understand-the-post-cooking-process/153206/1 "2020-05-29T09:51:25Z")

</div>

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 [discourse/app/assets/javascripts/pretty-text at f9608c0af5f7b1109117a5aba979acb00c28cf9a · discourse/discourse · GitHub](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

```plaintext
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

---

<div class="post-metadata">

### Author: ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)
#### Post date: [July 2, 2020, 4:26pm UTC](https://meta.discourse.org/t/help-me-understand-the-post-cooking-process/153206/2 "2020-07-02T16:26:54Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![spirobel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/spirobel/32/170908_2.png) [@spirobel](https://meta.discourse.org/u/spirobel)
#### Post date: [July 3, 2020, 3:18pm UTC](https://meta.discourse.org/t/help-me-understand-the-post-cooking-process/153206/3 "2020-07-03T15:18:12Z")

</div>

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.
