Skip to content

charliewilco/draft-as-markdown

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

draft-to-markdown

draft-to-markdown.now.sh/ is the micro service version of the really awesome markdown-draft-js module. Submitting a POST request to this endpoint will send back a stream of a blob of your EditorState as a formatted markdown file with simple front matter.

Usage

POST / render markdown text

{
    content: '<RawContent>', // from draft-js
    title: '<DocumentTitle>' // string
}

Example

import { saveAs } from 'file-saver'
import { EditorState, convertToRaw } from 'draft-js'

const body = {
  title: 'Something Detailed Post'
  content: convertToRaw(EditorState.getCurrentContent())
}

const exportMD = async (body: Object) => {
  const res = await fetch('https://draft-to-markdown.now.sh/', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(body)
  })

  const blob = await res.blob()

  saveAs(blob, `${body.title.replace(/\s+/g, '-').toLowerCase()}.md`)
}