Skip to content

Latest commit

 

History

History
93 lines (70 loc) · 5.27 KB

README.md

File metadata and controls

93 lines (70 loc) · 5.27 KB

gdocs2Rmd

A simple Google Apps script to convert a properly formatted Google Drive Document to the Rmarkdown (.Rmd) format. Fork of the gdocs2md repository — there've been many (180 at time of writing!), and some collation of changes between them could be valuable.

To consider:

  • Would this actually be best outputting md or Rmd format?
  • What value would code/YAML serve?
    • programmatic access through Google Apps script to write YAML headers based on user input would be a nice way to make Rmarkdown more user-friendly, and perhaps help guide the construction of more elaborate custom knit setups (see post on modular workbooks, linked below).

Related directions:

To-do list

See the rOpenSci wishlist page

Usage

  • 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 exportRmd.gs into the code editor
    • File -> Save (or Ctrl/ + S)
    • When prompted enter new project name for 'Untitled project', e.g. 'gdocs2Rmd'
  • Running the script:

    • Select setupScript from the script editor's dropdown menu and the play symbol button (on the left of the dropdown) to run it
    • Likewise for the convertSingleDoc function, or for batch processing on a folder use the convertFolder function.
    • The first run will require you to authorize the app.
    • Converted doc will be saved in the Markdown sub-directory, images below that (/assets/images).

NB I'm testing UI etc. in a markdown/HTML equivalent before adding changes here. Check that repo out if this interests you. HTML below is from previous implementations and will get taken out of the Rmd-generating script.

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)
  • 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 ~~~ chunkparameters and ~~~ become fenced as in Rmarkdown, with ``` {chunkparameters} and ```. Note the {} brackets are added automatically.
    • 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>
    • 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.