mangini / gdocs2md Goto Github PK
View Code? Open in Web Editor NEWConvert a Google Drive Document to the Markdown format, suitable for publishing.
License: Apache License 2.0
Convert a Google Drive Document to the Markdown format, suitable for publishing.
License: Apache License 2.0
As far as I can tell, only the lines between "--- source code" and "---" which
are ALREADY indented by four spaces are getting turned into "pre" code.
[This system didn't like me using anglebrackets around "pre".]
Thus a block of code that has some lines fully exdented and some lines indented
gets turned into paragraphs for the exdented lines and "pre" blocks for the indented
lines, alternating through the block, up to the ---.
I have not tried what happens to normal paragraphs, outside the --- source code
block, that are indented by 4 spaces.
It worked earlier today and I have been getting the script from github each time
I use it so it is likely caused by recent work.
When attempting to export a document with footnotes the following fatal error occurs: "TypeError: Cannot find function getText in object Footnote." Other documents without footnotes work as expected.
Could you detail and explain why this script is requesting so much access and varying types of permissions from google drive?
This script seems like it could be accomplished with far less invasiveness
Getting this error when I run after authenticating.
TypeError: Cannot call method "getActiveSection" of null. (line 2, file "Code")
I also can't see the script in the scripts manager.
Followed all the directions but in Google Apps for Business / Google Drive / Google Docs / My Doc
I do not see the Script Manager option under the Tools menu.
Lists of links don't work. I tracked this back to the declaration of "prefix" on line 184 missing a "var".
I appreciate this script's ability to convert a Docs document to Markdown. It came in very handy.
However, I didn't want the script to email the converted document. The contents of my document were somewhat confidential. I was happier keeping it off the insecure public email system and away from possible eavesdroppers. I preferred to have the script pop up a dialogue box with the converted Markdown text, allowing me to copy the text and paste it into a text editor for further manipulation.
I commented out Lines 71-77, which generate an email message with the converted text attached, and put in the following calls:
var ui = HtmlService.createHtmlOutput("<pre>"+text+"</pre>")
DocumentApp.getUi().showModelessDialog(ui,"Markdown");
This worked fine for my one document one time. It would nice to have this integrated into this script somehow. It would probably be better to offer the option of emailing or putting up a dialogue box, instead of hard-coding one or the other. I don't want to take the time right now to design that, so I am not offering a Pull Request. Maybe this request will encourage someone else to do that work.
Anyone know how I could modify the script to preserve single newlines vs double newlines?
I have some song verses that I would like to use this script on which are of the form:
Verse1 line1
Verse1 line2
Chorus line 1
Chorus line2
Verse2 line1
Verse2 line2
However, this script doesn't preserve this spacing and produces:
Verse1 line1
Verse1 line2
Chorus line 1
Chorus line2
Verse2 line1
Verse2 line2
There are still some bugs in the "--- source code" function:
Example files have been sent by private email.
TypeError: Cannot call method "getActiveSection" of null. (line 14, file "Code")
Child index (13) must be less than the number of child elements (13). (line 111, file "Code")
Hi, I found the Consolas font "cuter" in my google docs and I am using this change to lines 267-268 of the script:
if (!inSrc && (font===font.COURIER_NEW || font=="Consolas")) {
while (i>=1 && txt.getFontFamily(attrs[i-1]) && (txt.getFontFamily(attrs[i-1])===font.COURIER_NEW || txt.getFontFamily(attrs[i-1])=="Consolas")) {
I'm not keen enough to guess what constant is from font.* that will match the Consolas font, but this way works for me. :)
(sorry I am too lazy to make a proper/decent pull request, so the alternative is here for whoever wants to implement to the code)
The script crashes when the document includes a footer.
I have a place in my doc that read:
this format apparently is enough to make this script throw an error
ReferenceError: txt is not defined
(@jacksonicson tagging you here because I actually forked from you, if maybe you can help...)
I get this:
`module ListComprehension`
` def c(comprehension)`
` parts = comprehension.split(' ')`
` if parts[0] == parts[2]`
` eval(comprehension.scan(/\[.*\]/).last)`
` end`
` end`
`end`
But I should get this:
module ListComprehension
def c(comprehension)
parts = comprehension.split(' ')
if parts[0] == parts[2]
eval(comprehension.scan(/\[.*\]/).last)
end
end
end
Here's an example:
[this article](http://www.google.com/url?q=http%3A%2F%2Fwww.stavros.io%2Ftutorials%2Fpython%2F&sa=D&sntz=1&usg=AFQjCNHYROYMTY1rv3hrdYcchdGK4bsc4w)
This should be:
http://www.stavros.io/tutorials/python/
my mistake
After an export, animated gifs are turned into static images: the exported gif files only contain the first frame.
Would be great if the markdown converter preserved bold + italic formatting.
Sigh, over 100 lessons at Code Academy (?) and I can't figure out how to change the code myself; though I am guessing it is very simple.
Basically, MM and PANDOC can read footnotes with the following syntaxis
Tex tex text1.
I can obviously change the text between brackets in line 110, but I can't figure out how to create a loop function that would (a) number each footnote with a different number (continuing numbering preferred, of course) and (b) force a line brake in Markdown before the second 1 with the actual content of the footnote. That would make the final Markdown document capable of being processed by Pandoc easily and beautifully. Would highly appreciate ideas regarding this and would love to check the code after that becaues --as I said-- I am sure it is EASY as HELL. Regards!
empty lines in source code blocks (--- source code / ---) are being removed in generated markdown.
Google Docs prefers to use Unicode quotation marks and apostrophes. However, when brought into markdown they can be parsed as garbled characters when being brought into HTML, for example.
Perhaps using the ASCII equivalents of both would be preferred to avoid this problem. Or maybe escaping them is viable.
Reference table here: http://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html
The script should be applicable to more than one document at a time. Right now one needs to copy and paste the script to every new document one wants to convert. It should be possible to batch convert files from GDrive.
Any time I try to run this script, I'm getting an error:
We're sorry, a server error occurred. Please wait a bit and try again. (line 130, file "")
Is there a problem on my side?
EDIT: Seems there's something too complex with my document for this script - I'll try to track it down.
Sorry not this repo ;-)
TypeError: Cannot find function getTextAttributeIndices in object TableRow.
Not that the script needs to try to do anything fancy with tables, but it probably shouldn't blow up.
The export of ordered list does not work correctly. The exported lists look like:
1. Text1
1. Text2
1. Text3
The numbers should be increasing.
G Suite/Google Doc admins are receiving emails in regards to this script.
Hello Apps Script user,
As a G Suite user, this notification is to alert you of an update to one or more of your Apps Script projects that are attached to Docs, Sheets, and Forms documents with script sharing settings that differ from those of the document.
Starting on or after June 13th, 2017, those script sharing settings will be updated to match those of the documents to which they're attached.
The sharing settings update simplifies sharing settings for documents with attached Apps Script projects by treating them like a single document.
As a result of the sharing settings update, and according to the document access level, some users may:
- Gain or lose access to affected projects
- Change their access levels (for example, owner, editor, reader)
This change will not affect sharing settings for the documents. Only sharing settings of attached Apps Script projects will be updated.
A CSV file attached to this message lists all Apps Script projects where you're the owner and whose sharing settings will change as a result of this migration. Please review these documents and confirm that their sharing settings are also appropriate for their attached Apps Script projects.
If changes are required, for each document where settings need to be changed, use one of these methods:
- In Docs or Sheets, click Share.
- In Forms, click Add Collaborator.
- In Google Drive, click Share.
Sincerely,
The Apps Script Team
Is there a way to save a library function or script that is available in all docs. I don't want to have to go through this whole process for each doc.
(reported by August Mohr)
The GDoc lines:
--- source code
<html data-cast-api-enabled="true">
---
generates this in the MD file:
<pre>
<html data-cast-api-enabled="true">
</pre>
and that gets passed through to the HTML version unchanged.
So of course it does not display desired.
You have mentioned in the readme.md to go to tools -> script manager but there is tools-> script editor not manager
I have this error while running the script:
Paragraph 23 of type PARAGRAPH has an unsupported child: INLINE_DRAWING index=23 (line 155, file "Code")
This line: "throw "Paragraph "+index+" of type "+element.getType()+" has an unsupported child: ""
Unorderd lists in GDrive get a blank line between them in the exported MD file, which renders an empty line between *
, which is unwanted.
This project is awesome.
It would be even more awesome if it detected monospace fonts (e.g. Courier, Roboto Mono) and produced inline markdown surrounded with single backticks (producing a <code>foo</code>
).
This would work if the monospace-styled text is in a paragraph with normal text.
The script worked great for a bunch of docs I converted last month, now I'm getting this error message and don't know how to fix.
I think the script should ignore PageBreak object.
The script stops on throwing error message because PageBreak object doesn't have getText().
I'm getting the following error while parsing a Google Doc.
Paragraph 438 of type PARAGRAPH has an unsupported child: INLINE_DRAWING index=438 (line 155, file "Code")
Hi There,
First off: thanks for providing this code - it has been very helpful for me.
I have made some reasonably big changes - not fixes - but a new mode of operation. I have no idea if you'll be interested in them, but I I just wanted to let you know. Because I have changed the way the script works (not email based any more) it didn't feel like a pull request was suitable.
My requirement was to have the markdown version created in Google Drive alongside the original document (in a "markdown" folder) - instead of being emailed. I also needed to enable hyperlinking from one document to another in the same directory or a sub directory. The code now looks at all links - if these refer to a document in the same directory or a sub directory then the absolute link is replaced by just a relative path name. It will also automatically (recursively) process the file being referenced - thus if you process a top level file and this links to a number of sub-files then all of the files will be processed and markdown versions created - all with suitable internal links. All in all this enables large multi-file documentation packages to be maintained in Google Drive then easily exported to Markdown files.
My version is available here:
https://gist.github.com/bafta-benj/a5c432e5957ba48f98007fb802f48ca4
If this is of interest let me know - I've only just finished it and haven't used it much so there will probably be some tweaks/fixes over the next couple of weeks.
All the best
Ben
Currently throws an exception at ~line 110 if a horizontal rule is encountered.
Suggested fix:
else if (t === DocumentApp.ElementType.HORIZONTAL_RULE) {
textElements.push('* * *\n');
}
A list usually ends up like this:
1. A
2. B
3. C
Which ends up with weird formatting (<p>
elements around the list items) when converting to HTML.
Firstly, thanks for this great script.
1: Did you know you can add a menu very simply?
function onOpen() {
DocumentApp.getUi().createMenu('Markdown Conversion')
.addItem('Convert and email', 'ConvertToMarkdown')
.addToUi();
}
2: Does anyone know a way of adding this script so it's globally available to all docs in my account rather than adding per doc? I've been trawling through https://developers.google.com/apps-script/scripts_containers and sadly it doesn't look like it can be. I hope I'm wrong though.
3: Would you consider adding support for automatically "pushing" the page to a Google Hosted folder so it can be easily published in 2 clicks using something like Markdown-js.
Finally, thanks again!
Would be great if the markdown converter preserved bold + italic formatting.
Hey It doesn't works in 2015 nothing in google docs change, function executes with no error.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.