# האם יש דרך להמיר תוכן מבושל חזרה ל-Markdown?

**URL:** https://meta.discourse.org/t/is-there-a-way-to-convert-cooked-content-back-to-markdown/322279
**Category:** Support
**Tags:** markdown
**Created:** [19 באוגוסט,‏ 2024,‏ 2:57pm UTC](https://meta.discourse.org/t/is-there-a-way-to-convert-cooked-content-back-to-markdown/322279 "2024-08-19T14:57:03Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![U4EA](https://avatars.discourse-cdn.com/v4/letter/u/4bbf92/32.png) [@U4EA](https://meta.discourse.org/u/U4EA)
#### Post date: [19 באוגוסט,‏ 2024,‏ 2:57pm UTC](https://meta.discourse.org/t/is-there-a-way-to-convert-cooked-content-back-to-markdown/322279/1 "2024-08-19T14:57:03Z")

</div>

**EDIT: mistake in my original post. I meant to refer to the _cooked_ field, not the _raw_ field (CORRECTED).**

I recently acquired some JSON data from a discourse forum, where the post data is in the “cooked” form. I was wondering if there is anyway to convert this back to the Markdown? I am new to Discourse and have searched but can’t find a way to do this. Seeing as the cooked data appears to be used to create the HTML, I am guessing an alternative route would be to use the function that converts cooked to HTML then convert the HTML to Markdown.

Any help greatly appreciated.

Thanks.

---

<div class="post-metadata">

### Author: ![wal](https://avatars.discourse-cdn.com/v4/letter/w/d6d6ee/32.png) [@wal](https://meta.discourse.org/u/wal)
#### Post date: [19 באוגוסט,‏ 2024,‏ 3:00pm UTC](https://meta.discourse.org/t/is-there-a-way-to-convert-cooked-content-back-to-markdown/322279/2 "2024-08-19T15:00:00Z")

</div>

there are a lot of options on Google but my first choice for these things is usually `pandoc` [https://stackoverflow.com/questions/16248986/how-to-convert-html-to-markdown-while-retaining-non-markdown-html-tags](https://stackoverflow.com/questions/16248986/how-to-convert-html-to-markdown-while-retaining-non-markdown-html-tags)

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [19 באוגוסט,‏ 2024,‏ 3:01pm UTC](https://meta.discourse.org/t/is-there-a-way-to-convert-cooked-content-back-to-markdown/322279/3 "2024-08-19T15:01:04Z")

</div>

Try this. Simples

> [@Export document with all content from one topic?](https://meta.discourse.org/t/export-document-with-all-content-from-one-topic/256411/7):
>
> Thanks. For anyone else who wants to do this, here is an example set of commands that worked for me: mkdir md-dl; cd md-dl wget https://discuss.criticalfallibilism.com/raw/464\?page\={1..3} cat 464\* \> combined.md Downloading extra pages is OK; they just end up blank. But I think the pages will end up out of order if there are more than 9 because, in alphabetical order, 10 comes before 2.

---

<div class="post-metadata">

### Author: ![U4EA](https://avatars.discourse-cdn.com/v4/letter/u/4bbf92/32.png) [@U4EA](https://meta.discourse.org/u/U4EA)
#### Post date: [19 באוגוסט,‏ 2024,‏ 3:06pm UTC](https://meta.discourse.org/t/is-there-a-way-to-convert-cooked-content-back-to-markdown/322279/4 "2024-08-19T15:06:40Z")

</div>

I already have the data, I can’t grab it again. It was from a forum that was taken down, I am trying to clean the data so it can be revived.

What exactly format is the “raw” data?

---

<div class="post-metadata">

### Author: ![leonardo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leonardo/32/228634_2.png) [@leonardo](https://meta.discourse.org/u/leonardo)
#### Post date: [19 באוגוסט,‏ 2024,‏ 3:14pm UTC](https://meta.discourse.org/t/is-there-a-way-to-convert-cooked-content-back-to-markdown/322279/5 "2024-08-19T15:14:25Z")

</div>

Markdown!

If by raw you mean a field called `raw`, then you’re looking at the actual Markdown source that we store. For an example, [this](https://meta.discourse.org/t/is-there-a-way-to-convert-raw-data-back-to-markdown/322279/4.json) is the JSON endpoint for you last post just now.

The `raw` field there is the actual text you composed in the Markdown editor, and we store it as-is so it doesn’t get more pure than that.

Instead, if you generally mean “the raw HTML” as scraped without using JSON endpoints, then you can turn that HTML into Markdown externally with pandoc as suggested above, or any other software.

---

<div class="post-metadata">

### Author: ![U4EA](https://avatars.discourse-cdn.com/v4/letter/u/4bbf92/32.png) [@U4EA](https://meta.discourse.org/u/U4EA)
#### Post date: [19 באוגוסט,‏ 2024,‏ 3:20pm UTC](https://meta.discourse.org/t/is-there-a-way-to-convert-cooked-content-back-to-markdown/322279/6 "2024-08-19T15:20:15Z")

</div>

Please accept my apologies, I made a mistake in my first post (since corrected). I meant to refer to the _cooked_ data as opposed to the _raw_ data (it’s been a long day…).

What form is the cooked data in and is there any way to convert it to Markdown or HTML? Thanks.

---

<div class="post-metadata">

### Author: ![U4EA](https://avatars.discourse-cdn.com/v4/letter/u/4bbf92/32.png) [@U4EA](https://meta.discourse.org/u/U4EA)
#### Post date: [19 באוגוסט,‏ 2024,‏ 3:20pm UTC](https://meta.discourse.org/t/is-there-a-way-to-convert-cooked-content-back-to-markdown/322279/7 "2024-08-19T15:20:48Z")

</div>

I made a mistake in my first post, since corrected. My apologies.

---

<div class="post-metadata">

### Author: ![leonardo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leonardo/32/228634_2.png) [@leonardo](https://meta.discourse.org/u/leonardo)
#### Post date: [19 באוגוסט,‏ 2024,‏ 3:28pm UTC](https://meta.discourse.org/t/is-there-a-way-to-convert-cooked-content-back-to-markdown/322279/8 "2024-08-19T15:28:33Z")

</div>

Ah, that makes more sense. The `cooked` field is the HTML rendered from Markdown.

You can simply run that through pandoc to get Markdown; you won’t get full fidelity to the corresponding `raw` because there are some non-standard Markdown tags like `[quote]` which get rendered to certain HTML patterns, but if you simply need the content as Markdown, pandoc should work well enough.

---

<div class="post-metadata">

### Author: ![U4EA](https://avatars.discourse-cdn.com/v4/letter/u/4bbf92/32.png) [@U4EA](https://meta.discourse.org/u/U4EA)
#### Post date: [19 באוגוסט,‏ 2024,‏ 4:19pm UTC](https://meta.discourse.org/t/is-there-a-way-to-convert-cooked-content-back-to-markdown/322279/9 "2024-08-19T16:19:13Z")

</div>

Thank you very much. I will get on to that now.

I assume the post data (content) is actually stored in the DB as Markdown?

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [19 באוגוסט,‏ 2024,‏ 4:38pm UTC](https://meta.discourse.org/t/is-there-a-way-to-convert-cooked-content-back-to-markdown/322279/10 "2024-08-19T16:38:15Z")

</div>

Both, here’s an example:

```plaintext
 #<Post:0x00007fbb78416f50
 id: 2203,
 user_id: -4,
 topic_id: 590,
 post_number: 6,
 raw: "@merefield, it looks like @eloy has mentioned that their favourite colour is red!",
 cooked:
  "<p><a class=\"mention\" href=\"/u/merefield\">@merefield</a>, it looks like <a class=\"mention\" href=\"/u/eloy\">@eloy</a> has mentioned that their favourite colour is red!</p>",
 created_at: Sun, 18 Aug 2024 11:15:32.487912000 UTC +00:00,
 updated_at: Sun, 18 Aug 2024 11:15:32.487912000 UTC +00:00,

```
