Google文档脚本 - 将HTML粘贴为彩色文本

时间:2015-05-20 13:18:03

标签: javascript jquery css google-docs google-docs-api

我正在尝试构建一个Google文档插件,允许您将代码段粘贴到看起来不错的Google文档中。例如:

enter image description here

我已经创建了附加组件,使用了Javascript语法高亮显示器,我将代码作为带有内联样式的HTML。例如:

<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>

但是如果使用Google Script的addText()方法,它会将其作为纯文本插入。像这样:

enter image description here

有没有办法将HTML转换为富文本或Google Script将以彩色,格式化文本格式插入的内容?

注意:在Google文档中,从某处复制语法突出显示的代码(HTML页面,DOC文件)并粘贴它确保颜色和格式。这正是我想要实现的,来自带有内联CSS的HTML。

0 个答案:

没有答案