1

I have a bunch of small books in my Google Drive. I would like to use Google API to format all of them through code. For that purpose, I need the documents to be structured. The idea is very simple. I need to be able to tag different paragraphs and headings.

It's possible in Google Docs to mark a paragraph as header, title, and subtitle. But I can't find an option to mark a paragraph as "quote" for example. Or mark a paragraph as "Formula".

Can I achieve that at all? Does Google Drive support HTML like tagging for extensible classification of a document structure?

1

No, the structure of Google Documents is mostly presentational. See the structure of a document for an overview. The semantic markup is limited: the body of a document can contain

ListItem, Paragraph, Table, and TableOfContents elements.

You can define a special style for a quote, for example (like here):

 var quote = {};
 quote[DocumentApp.Attribute.FONT_FAMILY] = 'Verdana';
 quote[DocumentApp.Attribute.FONT_SIZE] = 15;

and then use it throughout:

 var par = body.appendParagraph('A famous quote.');
 par.setAttributes(quote);

But as you can see, this is presentational, the choice being limited to the set of attributes that a text element may have.

You can generate HTML with Google Apps Script using the HTML Service, but this is really meant for serving HTML to web clients.

One reasonable option is to use a tool that generates Markdown. For example, gdocs2md is an Apps script that produces Markdown from a Google Drive document. Of course, you will need to find something that can work with the type of the source documents you have now.

  • It may be possible to build something like this as an add-on using the NamedRange class, but I'm not sure how usable it would be. – Thedward Jul 30 '15 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.