Javascript examples for CodeMirror:Highlight
CodeMirror Highlight only with no editor
<html> <head> <title>Codemirror 2 - use as syntax highlighter</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.js"></script> <script type="text/javascript" src="https://codemirror.net/lib/codemirror.js"></script> <script type="text/javascript" src="https://codemirror.net/mode/javascript/javascript.js"></script> <link rel="stylesheet" type="text/css" href="https://codemirror.net/mode/javascript/javascript.css"> <link rel="stylesheet" type="text/css" href="https://codemirror.net/lib/codemirror.css"> <style id="compiled-css" type="text/css"> .code {// www. ja v a2s . co m margin: 10px 0; } .inline { display: inline-block; margin: 0; } .CodeMirror { height: auto!important; } </style> <script type="text/javascript"> $(function(){ $('.code').each(function() { var $this = $(this), $code = $this.html(), $unescaped = $('<div/>').html($code).text(); $this.empty(); CodeMirror(this, { value: $unescaped, mode: 'javascript', lineNumbers: !$this.is('.inline'), readOnly: true }); }); }); </script> </head> <body> Some code <code class="code inline">function inline() { console.log('inline code') }</code> inside a sentence. <div class="code"> function test() { return false; } </div> <div class="code inline"> <h4>unescape test</h4> </div> </body> </html>