Coder Social home page Coder Social logo

gdocs2md-html's Introduction

gdocs2md-html

A simple Google Apps script to convert a properly formatted Google Drive Document to the markdown (.md) format.

Brief installation

  • Adding this script to your doc (once per doc):
    • Open your Google Drive document (http://drive.google.com)
    • Tools -> Script Editor > Create script for blank project
    • Clear the default Code.gs file and paste the contents of exportmd.gs into the code editor
    • File -> Save (or Ctrl/โŒ˜ + S)
    • When prompted enter new project name for 'Untitled project', e.g. 'gdocs2md'

Note: now needs advanced Drive API enabling in Script Editor on first use (just a few clicks from the menu).

  • Resources menu โ‡ข Advanced Google Services, enable the Drive API by clicking the switch next to its name
  • The link below the API list to the dev console project page for the script you're editing will become clickable
    • At the link, again click the on/off switch on the advanced Drive API setting
  • If the script doesn't refresh automatically at this point, hit Ctrl/Cmd + S to save it, select onInstall from the functions dropdown menu at the top of the page and to the left of that click the play icon to run.
  • If you go back to your document a Markdown menu will be sitting there, with a dropdown to Export markdown > View in browser

Menu added to Google Docs. Note: customisation/comments features work in progress, see script

When you finish writing, the markdown (via the View in browser button) can be pasted straight into a suitable publisher.

  • HTML tags are supported in markdown, but feel free to add your own hooks in the source code, or modify the existing ones.
  • Feel free to change the hooks yourself - e.g. the --- src ... --- fences could demarcate <blockquote> / </blockquote> tags - you're free to edit the script when installing.

Related tips/tricks:

Interpreted formats

  • Text:
    • paragraphs are separated by two newlines
    • text styled as heading 1, 2, 3, etc is converted to Markdown heading: #, ##, ###, etc
    • text formatted with Courier New is backquoted: text
    • links are converted to MD format: [anchortext](url)
    • indented paragraphs are rendered as > (blockquote) blocks
    • sub- and superscript text is tagged appropriately (<sup>/<sub>)
  • Lists:
    • Numbered lists are converted correctly, including nested lists
    • bullet lists are converted to "*" Markdown format appropriately, including nested lists
  • Images:
    • images are correctly extracted and sent as attachments
  • Blocks:
    • Table of contents is replaced by [[TOC]]
    • blocks of text delimited by "--- class whateverclassnameyouwant" and "---" are converted to <pre class="whateverclassnameyouwant"></pre>
    • Source code:
      • UPDATED: blocks of text delimited by "--- source code" or "--- src" and "---" are converted to <pre></pre>
      • NEW: blocks of text delimited by "--- source pretty" or "--- srcp" and "---" are converted to <pre class="prettyprint"></pre>
      • NEW: blocks of text delimited by "--- gloss" and "---" are converted to <pre class="glossary"></pre>
      • NEW: blocks of text delimited by "--- fig-cap" and "---" are converted to <pre class="fig-cap"></pre> (figure captions)
      • (feel free to change these for your own needs)
    • Tables:
      • NEW: Simple <table> processing
  • "--- jsperf <testID>" is replaced by an iframe that shows an interactive chart of a JSPerf test. The <testID> is the last part of the URL of the Browserscope anchor in your JSPerf test. Something like "agt1YS1wcm9maWxlcnINCxIEVGVzdBjlm_EQDA" in the URL http://www.browserscope.org/user/tests/table/agt1YS1wcm9maWxlcnINCxIEVGVzdBjlm_EQDA

CONTRIBUTORS

LICENSE

Use this script at your will, on any document you want and for any purpose, commercial or not. The MarkDown files generated by this script are not considered derivative work and don't require any attribution to the owners of this script.

If you want to modify and redistribute the script (not the converted documents - those are yours), just keep a reference to this repo or to the license info below:

Copyright 2013 Google Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

gdocs2md-html's People

Contributors

clearf avatar lmmx avatar mangini 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

gdocs2md-html's Issues

Global install or per document?

So to clarify does this script need to be set up for ever gdoc or can it be installed once and used on any google doc? I seem to have to run the setupScript function every time I reopen the same doc and I cannot get it to work on any doc other than the one I initially set it up on. Thanks!

export -> markdown/view in browser missing

The README shows a submenu of export -> markdown called "view in browser" but that is not in the code on the master branch. Is there a branch you've perhaps neglected to push to github and/or merge into master?

Thanks.

Add equations parsing

Developer docs page: Equation

An Equation may contain EquationFunction, EquationSymbol, and Text elements.

  • Very basic, smaller than MathJax's vocabulary, doesn't even support bold typefaces
  • Unclear what the output format is. Symbols not given as any sort of enum on developer site, nor in TypeScript docs
  • There's a symbol conversion table to LaTeX here
alpha \alpha
equation symbol \beta
equation symbol \gamma
equation symbol \delta
equation symbol \epsilon
equation symbol \varepsilon
equation symbol \zeta
equation symbol \eta
equation symbol \theta
equation symbol \vartheta
equation symbol \iota
equation symbol \kappa
equation symbol \lambda
equation symbol \mu
equation symbol \nu
equation symbol \xi
equation symbol \pi
equation symbol \varpi
equation symbol \rho
equation symbol \varrho
equation symbol \sigma
equation symbol \varsigma
equation symbol \tau
equation symbol \upsilon
equation symbol \phi
equation symbol \varphi
equation symbol \chi
equation symbol \psi
equation symbol \omega
equation symbol \Gamma
equation symbol \Delta
equation symbol \Theta
equation symbol \Lambda
equation symbol \Xi
equation symbol \Pi
equation symbol \Sigma
equation symbol \Upsilon
equation symbol \Phi
equation symbol \Psi
equation symbol \Omega
equation symbol \times
equation symbol \div
equation symbol \cdot
equation symbol \pm
equation symbol \mp
equation symbol \ast
equation symbol \star
equation symbol \circ
equation symbol \bullet
equation symbol \oplus
equation symbol \ominus
equation symbol \oslash
equation symbol \otimes
equation symbol \odot
equation symbol \dagger
equation symbol \ddagger
equation symbol \vee
equation symbol \wedge
equation symbol \cap
equation symbol \cup
equation symbol \aleph
equation symbol \Re
equation symbol \Im
equation symbol \top
equation symbol \bot
equation symbol \infty
equation symbol \partial
equation symbol \forall
equation symbol \exists
equation symbol \neg
equation symbol \angle
equation symbol \triangle
equation symbol \diamond
equation symbol \leq
equation symbol \geq
equation symbol \prec
equation symbol \succ
equation symbol \preceq
equation symbol \succeq
equation symbol \ll
equation symbol \gg
equation symbol \equiv
equation symbol \sim
equation symbol \simeq
equation symbol \asymp
equation symbol \approx
equation symbol \ne
equation symbol \subset
equation symbol \supset
equation symbol \subseteq
equation symbol \supseteq
equation symbol \in
equation symbol \ni
equation symbol \notin
equation symbol \frac
equation symbol \sum
equation symbol \sqrt
equation symbol \rootof
equation symbol \subsuperscript
equation symbol \subscript
equation symbol \superscript
equation symbol \abs
equation symbol \overline
equation symbol \widehat
equation symbol \tilde
equation symbol \bigcap
equation symbol \bigcup
equation symbol \prod
equation symbol \coprod
equation symbol \int
equation symbol \oint
equation symbol \leftarrow
equation symbol \rightarrow
equation symbol \leftrightarrow
equation symbol \Leftarrow
equation symbol \Rightarrow
equation symbol \Leftrightarrow
equation symbol \uparrow
equation symbol \downarrow
equation symbol \updownarrow
equation symbol \Uparrow
equation symbol \Downarrow
equation symbol \Updownarrow

Lists items should not be indented

This turns my list items into > <sub>* a list item. I can't dedent my lists any further in Google Docs. I would expect list items to be just * a list item.

Getting an error in running the latest version of the script.

Hi
Trying out the script for a document filled with Tables and images and got the following error.

Unfortunately it is not saying which line is at fault in the document for me to fix it or temporarily comment/remove it out.

Thanks
Srihari

Message details
TypeError: Cannot find function getIndentFirstLine in object Table

Tried to install, but got an error

Access Not Configured. The API (Drive API) is not enabled for your project. Please use the Google Developers 

There's a message when you add the service for google drive

These services must also be enabled in the Google Developers Console.

But it's not clear where you do that.

I also have multiple google accounts, one personal, and one google apps.

Thanks for any assistance!

IMG references have an extra /images/ in the URL

When rendering a gdoc with embedded images, the created Google Drive folder structure is:

Markdown/<docname>.md
Markdown/<docname>_images/image_0.png
...

but the image refs in <docname>.md are of the form:

![](/images/<docname>_images/image_0.png)

With an extra _/images/_ prefix. Workaround is just to make an images folder (after downloading and unzipping the gdrive Markdown folder) and moving the <docname>_images into it.

Happy to fix myself and submit a pull request if that will help. Will take me a bit of time to figure out how;-)

Thanks for this cool tool.

ReferenceError

When I try installing I get an error:

ReferenceError: "Drive" is not defined. (line 74, file "")

Install issue

While starting the install script, is get a typeError cannot use property getId of null, line 81:

var doc_id = DocumentApp.getActiveDocument().getId();

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.