简体   繁体   English

iFrame中带有语法高亮显示的HTML编辑器

[英]HTML Editor in an iFrame with Syntax Highlighting

I'm new to HTML, css etc. but I've been working on a project to learn something. 我是HTML,css等的新手,但是我一直在从事一个项目以学习一些东西。

I'm trying to make a HTML Editor embedded in an iFrame object. 我正在尝试将HTML编辑器嵌入到iFrame对象中。 So far its working, but now I saw an editor using syntax highlighting which looks pretty awesome to me. 到目前为止,它的工作正常,但现在我看到了一个使用语法突出显示的编辑器,这对我来说真是太棒了。

So how am I able to do that? 那我该怎么做呢?

Here is my (!relevant!) code so far: 到目前为止,这是我的代码!

    <div> 
        <div id="button">
        <input onclick="runCode();" type="button" value="Speichern und Abschicken">
    </div>
    <td> 
        <form>
            <textarea name="sourceCode" id="sourceCode">
                <strong> Change me! </strong>
            </textarea>
        </form>
    </td>
    <iframe name="targetCode" id="targetCode"></iframe> 
</tr>

Edit : forgot the JS 编辑 :忘记了JS

function runCode()
{
    var content = document.getElementById('sourceCode').value;
    var iframe = document.getElementById('targetCode');
    iframe = (iframe.contentWindow) ? iframe.contentWindow : (iframe.contentDocument.document) ? iframe.contentDocument.document : iframe.contentDocument;
    iframe.document.open();
    iframe.document.write(content);
    iframe.document.close();
    return false;
}
runCode();

Let me know if I'm doing something wrong here, I've tried to make it as its described. 如果我在这里做错了,请告诉我,我已经尝试按照说明进行操作。

I am not sure how you can add the syntax highlighting in your existing editors. 我不确定如何在现有编辑器中添加语法突出显示。

But, here are some open source syntax highlighting editors: 但是,这里有一些开源语法突出显示编辑器:

  1. https://codemirror.net/mode/index.html https://codemirror.net/mode/index.html
  2. https://ace.c9.io https://ace.c9.io

Here is the link to Wiki for more open source editors: Comparison of JavaScript-based source code editors 这是更多开放源代码编辑器的Wiki链接: 基于JavaScript的源代码编辑器的比较

Try them once. 尝试一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM