# Converting links from raw markdown to HTML

**URL:** <https://meta.discourse.org/t/converting-links-from-raw-markdown-to-html/102422>\
**Category:** Development\
**Created:** [November 20, 2018, 9:16pm UTC](https://meta.discourse.org/t/converting-links-from-raw-markdown-to-html/102422 "2018-11-20T21:16:49Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![hellekin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hellekin/32/51636_2.png) [@hellekin](https://meta.discourse.org/u/hellekin)\
**Post date:** [November 20, 2018, 9:16pm UTC](https://meta.discourse.org/t/converting-links-from-raw-markdown-to-html/102422/1 "2018-11-20T21:16:50Z")

</div>

## Context

I’m trying to retrieve specific posts to turn them into a single corpus (e.g., a book) to be processed elsewhere (e.g., with [Pandoc](https://pandoc.org/)).

## ‘Simple’ Approach

Discourse provides two readily accessible ways to download specific posts:

1. Appending `.json` to an URL will give its JSON representation that includes the `cooked` HTML version
2. Using the `topic/post` numbers from the original URL and replacing the prefix with `/raw` gives the original Markdown version, e.g., from `https://discourse.example/t/some-topic/123/4` to `https://discourse.example/raw/123/4`

Using the second approach, I’m listing topic numbers in a file and get the Markdown input. It works fine if there’s no hyperlink or attached files.

## API Approach?

Two problems to solve:

- relative links must be turned into absolute links if we want them clickable outside Discourse
- `upload://` links must be converted to absolute links as well, or to relative links if the assets are downloaded.

The JSON file produced in (1) does not seem to allow this conversion (at least not obviously, maybe there’s a way to re-parse the Markdown input and loop against the links list) so I’m wondering if the API can do that, retrieving the original Markdown but with externally usable URLs. In fact I wonder if such a view could be made available in the way `raw` is. This would immensely simplify reusing contents outside Discourse, or import contents into another Discourse instance (think [fediverse]).

I could go for the HTML and work from there, but it seems much cleaner to process the Markdown files (also since other sources might use Markdown that we want to compose with). Any suggestions as to the ways to approach this problem and eventual courses of action to understand this issue better or make it work in future versions is welcome!

---

_[View the full topic](https://meta.discourse.org/t/converting-links-from-raw-markdown-to-html/102422)._
