0.0.9 • Published 5 years ago
medium-paragraphs-to-markdown v0.0.9
medium-paragraphs-to-markdown
Converts
paragraphsarray received from Medium'sgraphqlinto valid markdown format.
Example of such an array you can find in sample.json file (data.post.content.body.paragraphs property).
Raw paragraphs received from graphql endpoint will be transformed into valid markdown format.
Installation
npm i -S medium-paragraphs-to-markdownUsage
Basic usage (with defaults).
import convert from 'medium-paragraphs-to-markdown'
import json from './sample.json'
const paragraphs = json.data.post.content.body.paragraphs
const parse = async () => {
const { markdown, images } = await convert(paragraphs)
// Do something with markdown and images
}
parse()Or using promises:
import convert from 'medium-paragraphs-to-markdown'
import json from './sample.json'
const paragraphs = json.data.post.content.body.paragraphs
convert(paragraphs).then(({ markdown, images }) => {
// Do something with markdown and images
})If withImages option is false, then only markdown string will be returned:
import convert from 'medium-paragraphs-to-markdown'
import json from './sample.json'
const paragraphs = json.data.post.content.body.paragraphs
const options = {
withImages: false,
title: true,
}
const parse = async () => {
const markdown = await convert(paragraphs, options)
// Do something with markdown
}
parse()Options
withImages-boolean- Returns urls for all images in the article as separateimagesarray. Defaulttrue.title-boolean- Whentrue, returns article heading inmarkdown(as# {title}). Defaultfalse.