0.0.9 • Published 4 years ago

medium-paragraphs-to-markdown v0.0.9

Weekly downloads
-
License
-
Repository
-
Last release
4 years ago

medium-paragraphs-to-markdown

Converts paragraphs array received from Medium's graphql into 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-markdown

Usage

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 separate images array. Default true.

  • title - boolean - When true, returns article heading in markdown (as # {title}). Default false.

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago