I'm trying to build a Google Docs Add-on that allows you to pasted Code Snippets into Google Docs that look good. Ex:
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"><?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:
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.