npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

google-docs-to-markdown

v2.0.5

Published

Convert Google Docs to Markdown or MDX

Readme

Npm Build Status Coverage Downloads PRs welcome MIT license Sponsor


google-docs-to-markdown converts Google Docs to Markdown or MDX.

It reads the document returned by the Google Docs API and gives back a Markdown string with a frontmatter. It does not call Google: google-docs-sync fetches the documents and writes the files, and it powers gatsby-source-google-docs, astro-loader-google-docs and next-google-docs. The converter works with any static site generator or script.

Google Drive can export a document as Markdown itself, but that export turns code blocks into one-cell tables without line breaks, escapes MDX components, embeds every image as base64 and drops the colors, underlines and inline code. This library keeps all of them.

Features

  • Headings, bold, italic, underline, strikethrough, superscript, subscript, colors and font sizes
  • Bullet and numbered lists, nested ones included
  • Tables, images, footnotes and horizontal rules
  • Code blocks with a language, inline code and quotes
  • A cover, taken from the image of the first page header
  • Links between documents rewritten to your own paths
  • MDX output, to use <ReactComponents /> in your documents

Installation

npm install google-docs-to-markdown

Node 22.12 or later is required. The package is an ES module, which require() loads too, and it comes with its TypeScript types.

Usage

From a document you fetched yourself

import {toMarkdown} from "google-docs-to-markdown"

const markdown = toMarkdown(document, {
  frontmatter: {title: "Home"},
})

document is the response of documents.get.

From a document id

This package does not fetch anything. google-docs-sync fetches the document and authenticates with Google (token generation):

import {fetchDocument} from "google-docs-sync"
import {toMarkdown} from "google-docs-to-markdown"

const document = await fetchDocument(
  "1ebPyAlYlGDpGhf37WbbjA6APqpCLDxKorMBv_mFojV0"
)
const markdown = toMarkdown(document, {mdx: true})

To sync a whole Google Drive folder to Markdown files, use syncGoogleDocs from the same package.

Links between documents

A link to another Google Doc can point to your own page instead:

const markdown = toMarkdown(document, {
  links: {
    "1CgKSrtU6e_a3fSzJNQvwbrIdD7tayUcfVzPZAScwEfo": "/installation",
  },
})

The ids of the linked documents are listed in the related field of the frontmatter.

Cover, images and related documents

GoogleDocument takes the same options as toMarkdown and gives access to what the conversion found:

import {GoogleDocument} from "google-docs-to-markdown"

const googleDocument = new GoogleDocument(document, {links, mdx: true})

googleDocument.cover // {image, title, alt} or null
googleDocument.images // [{id, url, title, alt}], the cover included, in the order of the markdown
googleDocument.related // ["1CgKSrtU6e_a3fSzJNQvwbrIdD7tayUcfVzPZAScwEfo"]
googleDocument.toMarkdown()

Google gives the images new URLs every time a document is fetched, and they expire within hours. The id of an image does not change, so it can name a downloaded file.

Options

| Option | Default | Description | | ------------------ | ------- | -------------------------------------------------------------------------------------------------------------------- | | frontmatter | {} | Fields written in the frontmatter, next to cover and related | | links | {} | Paths to rewrite the links to other Google Docs with, by document id | | mdx | false | Write MDX: colors and font sizes become JSX styles, and the text is escaped for MDX | | escapeMdxSyntax | true | Escape the < and { of the text, on which MDX fails. Set it to false to write live components as text in a doc. | | demoteHeadings | false | Turn h1 into h2, h2 into h3, ... | | keepDefaultStyle | false | Keep the bold, italic, underline, ... of the Google Docs default style | | skipCodes | false | Leave out the code blocks | | skipFootnotes | false | Leave out the footnotes | | skipHeadings | false | Leave out the headings | | skipImages | false | Leave out the images | | skipLists | false | Leave out the lists | | skipQuotes | false | Leave out the quotes | | skipTables | false | Leave out the tables |

Writing in Google Docs

  • Inline code: use the Consolas font.
  • Code blocks: write the code in a table with a single cell, in the Consolas font. The Code Blocks add-on does it for you. Add lang:javascript on the first line to set the language.
  • Quotes: write the quote in a table with a single cell, between smart quotes: “quote”.
  • Cover: add an image in the header of the first page, with Different first page checked.

Support this project