Giter Club home page Giter Club logo

docs-markdown's Introduction

๐Ÿ“ Docs Markdown

Convert a Google Docs file (API response) to Markdown

Node CI Travis CI Coverage Dependencies License Vulnerabilities Based on Node.ts npm type definitions npm package npm downloads Contributors semantic-release

npm

๐Ÿ’ก Usage

Install the package from npm:

npm install docs-markdown

API

The fetchGoogleDocsFiles helper can download a document from Google Docs and save it as a markdown file:

import { fetchGoogleDocsFiles } from "docs-markdown";

// Google Docs document ID
await fetchGoogleDocsFiles(["1UEUrJ98RXu9BNcFj3pMgiUALQpjIb8Y-gNu-YhlYvFQ"]);

// Google Docs document ID and file name
await fetchGoogleDocsFiles(["1UEUrJ98RXu9BNcFj3pMgiUALQpjIb8Y-gNu-YhlYvFQ:filename.md"]);

// Multiple Google Docs documents (comma-separated string)
await fetchGoogleDocsFiles(["documentId1", "documentId2", "documentId3"]);

You can also use the googleDocsToMarkdown function to manually convert documents:

import { googleDocsToMarkdown } from "docs-markdown";
import { google } from "googleapis";
import { writeFileSync } from "fs";
const oauth2Client = new google.auth.OAuth2(); // Authenticate

const docs = google.docs("v1");
const file = await docs.documents.get({
  documentId: "Google Docs document ID",
  auth: oauth2Client,
});

const markdown = googleDocsToMarkdown(file.data);
writeFileSync("file.md", markdown);

CLI

Fetch files and save them as markdown:

# Google Docs document ID
docs-markdown fetch "1UEUrJ98RXu9BNcFj3pMgiUALQpjIb8Y-gNu-YhlYvFQ"

# Google Docs document ID with file name
docs-markdown fetch "1UEUrJ98RXu9BNcFj3pMgiUALQpjIb8Y-gNu-YhlYvFQ:filename.md"

# Multiple Google Docs documents
docs-markdown fetch "documentId1, documentId2, documentId3"

# Convert a JSON document to markdown
docs-markdown convert "path/to/file.json"

Authentication

The following environment variables are required to fetch files from Google Docs. They are not required when converting JSON documents to markdown:

  • GOOGLE_DOCS_CLIENT_ID
  • GOOGLE_DOCS_CLIENT_SECRET
  • GOOGLE_DOCS_ACCESS
  • GOOGLE_DOCS_REFRESH

To learn how to create a client ID and secret, read the article Using OAuth 2.0 to Access Google APIs. Once you've created them, create an access token and a refresh token, use the OAuth 2.0 Playground with your client ID and secret.

โญ๏ธ Features

  • Paragraphs
  • Headings, titles, subtitles
  • Bold, italic
  • Lists
  • Links
  • Images
  • Tables
  • Header, footer

๐Ÿณ Recipes

GitHub Actions + Google Docs CI

If you want to sync your Google Docs documents as markdown files to a GitHub repository, you can use this GitHub Actions workflow that runs every day, fetches your documents, and commit them to your repo. Make sure you have all the required environment variables stored as GitHub Secrets:

name: Google Docs
on:
  schedule:
    - cron: "0 0 * * *"
jobs:
  release:
    name: Fetch Google Docs
    runs-on: ubuntu-18.04
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup Node.js
        uses: actions/setup-node@v1
        with:
          node-version: 12
      - name: Download files
        run: npx docs-markdown fetch "1UEUrJ98RXu9BNcFj3pMgiUALQpjIb8Y-gNu-YhlYvFQ"
        env:
          GOOGLE_DOCS_ACCESS: ${{ secrets.GOOGLE_DOCS_ACCESS }}
          GOOGLE_DOCS_REFRESH: ${{ secrets.GOOGLE_DOCS_REFRESH }}
          GOOGLE_DOCS_CLIENT_ID: ${{ secrets.GOOGLE_DOCS_CLIENT_ID }}
          GOOGLE_DOCS_CLIENT_SECRET: ${{ secrets.GOOGLE_DOCS_CLIENT_SECRET }}
      - name: Commit new data
        uses: stefanzweifel/[email protected]
        with:
          commit_message: "Update Google Docs file"
          commit_user_name: GitHub Actions
          commit_user_email: [email protected]
          commit_author: GitHub Actions <[email protected]>

๐Ÿ‘ฉโ€๐Ÿ’ป Development

Build TypeScript:

npm run build

๐Ÿ“„ License

MIT ยฉ Anand Chowdhary

docs-markdown's People

Contributors

anandchowdhary avatar harshita-mindfire avatar peltomaa avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.