DEV Community


Posted on • Updated on

How to view the raw markdown of a post

Sometimes on, you might come across an article that uses some interesting markdown or liquid tags and wonder how it was created. Well, wonder no more! is built on top of the forem software, which has a well-documented API. Each path is resolved relative to, so to get information about an article, all you need to do is add /api/articles in front of the pathname (username and slug).

For example, information about this article can be found here:

The raw markdown can be found under the body_markdown field.

Alternatively, here’s a browser console-friendly snippet:

;(async () => {
    const url = new URL(window.location)
    url.pathname = '/api/articles' + url.pathname

    const res = await fetch(url)
    const { body_markdown } = await res.json()

Enter fullscreen mode Exit fullscreen mode

Top comments (3)

lionelrowe profile image

One-liner version

console.log((await (await fetch(((url) => (Object.assign(url, { pathname: `/api/articles${url.pathname}` })))(new URL(window.location.href)).href)).json()).body_markdown)
Enter fullscreen mode Exit fullscreen mode
farskid profile image
Farzad YZ

Great post. thanks

shapeshapa profile image

Thank you so much, this is very useful