1

I'm trying to build a Google Docs Add-on that allows you to pasted Code Snippets into Google Docs that look good. Ex:

enter image description here

I've created the add-on, used a Javascript syntax highlighter and I got the code as HTML with inlined styles. For example:

<pre style="background:#fff;color:#000">&lt;?php
<span style="color:#ff7800">class</span> <span style="color:#3b5bb5">CrudController</span> <span style="color:#ff7800">extends</span> <span style="color:#3b5bb5;font-style:italic">Controller</span> {

<span style="color:#ff7800">public</span> $crud <span style="color:#ff7800">=</span> <span style="color:#3b5bb5">array</span>(
                    <span style="color:#409b1c">"model"</span> <span style="color:#ff7800">=></span> <span style="color:#409b1c">"\App\Models\Entity"</span>,
                    <span style="color:#409b1c">"entity_name"</span> <span style="color:#ff7800">=></span> <span style="color:#409b1c">"entry"</span>,
                    <span style="color:#409b1c">"entity_name_plural"</span> <span style="color:#ff7800">=></span> <span style="color:#409b1c">"entries"</span>,
                    );

<span style="color:#ff7800">public </span><span style="color:#ff7800">function</span> <span style="color:#3b5bb5">__construct</span>()
{
    $this<span style="color:#ff7800">-></span>data[<span style="color:#409b1c">'crud'</span>] <span style="color:#ff7800">=</span> $this<span style="color:#ff7800">-></span>crud;

    <span style="color:#8c868f">// Check for the right roles to access these pages</span> </pre>

But if use Google Script's addText() method, it will insert it as plain text. Like so:

enter image description here

Is there a way to convert HTML to rich text or something that Google Script will insert as colored, formatted, text?

Note: In Google Docs, copying syntax highlighted code from somewhere (HTML page, DOC file) and pasting it DOES keep colors and some formatting. That's exactly what I want to achieve, from HTML with inline CSS.

tabacitu
  • 6,047
  • 1
  • 23
  • 37
  • Did you ever solve this? I asked the same question yesterday myself before I saw your question. my question is here with sample code: http://stackoverflow.com/questions/38518984/how-can-i-insert-html-into-a-google-doc-using-app-script – Will Kessler Jul 22 '16 at 17:13
  • and this seemed relevant but didn't help me http://stackoverflow.com/questions/35688581/importing-a-html-table-into-a-google-doc-using-google-app-script?rq=1 – Will Kessler Jul 22 '16 at 17:14
  • I did not... sorry... – tabacitu Jul 25 '16 at 11:34

0 Answers0