📄 test.html
字号:
<!DOCTYPE html><head> <title>Highlight</title> <meta charset="utf-8"> <link rel="stylesheet" title="Default" href="styles/default.css"> <link rel="alternate stylesheet" title="Dark" href="styles/dark.css"> <link rel="alternate stylesheet" title="FAR" href="styles/far.css"> <link rel="alternate stylesheet" title="IDEA" href="styles/idea.css"> <link rel="alternate stylesheet" title="Sunburst" href="styles/sunburst.css"> <link rel="alternate stylesheet" title="Zenburn" href="styles/zenburn.css"> <link rel="alternate stylesheet" title="Visual Studio" href="styles/vs.css"> <link rel="alternate stylesheet" title="Ascetic" href="styles/ascetic.css"> <style> h2 { font: bold 100% Arial, sans-serif; margin-top: 2em; margin-bottom: 0.5em; } table { width: 100%; } th { width: 10em; font-weight: normal; } td, th { vertical-align: top; text-align: left; } pre { margin-top: 0; } ul#switch { padding: 0; margin: 0 0 0 -0.5em; } ul#switch li { border-bottom: 1px dashed blue; display: inline; padding: 0; margin: 0.5em; cursor: pointer; } ul#switch li.current { border-bottom: none; cursor: default; } </style> <!-- Don't include languages as individual files in production environment. Instead use <script src="highlight.pack.js"></src> with highlight.pack.js containing all the languages you've chosen when downloading the library --> <script src="highlight.js"></script> <script src="languages/cs.js"></script> <script src="languages/python.js"></script> <script src="languages/mel.js"></script> <script src="languages/perl.js"></script> <script src="languages/axapta.js"></script> <script src="languages/cpp.js"></script> <script src="languages/sql.js"></script> <script src="languages/smalltalk.js"></script> <script src="languages/profile.js"></script> <script src="languages/bash.js"></script> <script src="languages/html-xml.js"></script> <script src="languages/renderman.js"></script> <script src="languages/1c.js"></script> <script src="languages/delphi.js"></script> <script src="languages/dos.js"></script> <script src="languages/django.js"></script> <script src="languages/vbscript.js"></script> <script src="languages/ini.js"></script> <script src="languages/ruby.js"></script> <script src="languages/css.js"></script> <script src="languages/lisp.js"></script> <script src="languages/java.js"></script> <script src="languages/javascript.js"></script> <script src="languages/php.js"></script> <script src="languages/diff.js"></script> <script>hljs.initHighlightingOnLoad();</script> <script> // A stylesheet switcher for the test page. Not part of the highlight.js itself // (c) Vladimir Epifanov <voldmar@voldmar.ru> (function(container_id) { if (window.addEventListener) { var attach = function(el, ev, handler) { el.addEventListener(ev, handler, false); } } else if (window.attachEvent) { var attach = function(el, ev, handler) { el.attachEvent('on' + ev, handler); } } else { var attach = function(el, ev, handler) { ev['on' + ev] = handler; } } attach(window, 'load', function() { var current = null; var info = {}; var links = document.getElementsByTagName('link'); var ul = document.createElement('ul') for (var i = 0; (link = links[i]); i++) { if (link.getAttribute('rel').indexOf('style') != -1 && link.title) { var title = link.title; info[title] = { 'link': link, 'li': document.createElement('li') } ul.appendChild(info[title].li) info[title].li.title = title; info[title].link.disabled = true; info[title].li.appendChild(document.createTextNode(title)); attach(info[title].li, 'click', (function (el) { return function() { current.li.className = ''; current.link.disabled = true; current = el; current.li.className = 'current'; current.link.disabled = false; }})(info[title])); } } current = info['Default'] current.li.className = 'current'; current.link.disabled = false; ul.id = 'switch'; container = document.getElementById(container_id); container.appendChild(ul); }); })('styleswitcher'); </script><body><p>This page is a demo/test showing all languages supported by <a href="http://softwaremaniacs.org/soft/highlight/">highlight.js</a>.Most of the code doesn't work :-).<p>You can see this page in several different styles bundled with the library orwrite your own (and contribute it back!)<div id="styleswitcher"></div><h2>Automatically detected languages</h2><table> <tr> <th>Python <td><pre><code>@requires_authorizationdef somefunc(param1, param2): r'''A docstring''' if param1 > param2: # interesting print 'Gre\'ater' print '' return (param2 - param1 + 1) or Noneclass SomeClass:<br> pass</code></pre> <tr> <th>Python's profiler output <td><pre><code> 261917242 function calls in 686.251 CPU seconds ncalls tottime filename:lineno(function) 152824 513.894 {method 'sort' of 'list' objects} 129590630 83.894 rrule.py:842(__cmp__) 129590630 82.439 {cmp} 153900 1.296 rrule.py:399(_iter)304393/151570 0.963 rrule.py:102(_iter_cached)</code></pre> <tr> <th>Ruby <td><pre><code>class CategoriesController < App::ApplicationController layout "core" before_filter :login_required before_filter :xhr_required, :only => [:create, :update] before_filter :admin_privileges_required, :except => [:show]=begin This method creates a category. Very difficult to understand, huh?=end def create # create! @category = Category.create(params[:category]) flash[:notice] = "Category #{@category + "..."} was successfully created" endend</code></pre> <tr> <th>Perl <td><pre><code># loads objectsub load{ my $flds = $c->db_load($id,@_) || do { Carp::carp "Can`t load (class: $c, id: $id): '$!'"; return undef }; my $o = $c->_perl_new(); $id12 = $id; $o->{'ID'} = $id12 + 123; $o->{'PAPA'} = $flds->{'PAPA'}; #$o->{'SHCUT'} = $flds->{'SHCUT'}; my $p = $o->props; my $vt; $string =~ m/^sought_text$/; for my $key (keys %$p) { if(${$vt.'::property'}) { $o->{$key . '_real'} = $flds->{$key}; tie $o->{$key}, 'CMSBuilder::Property', $o, $key; } else { $o->{$key} = $flds->{$key}; } } $o->save if delete $o->{'_save_after_load'}; return $o;}</code></pre> <tr> <th>PHP <td><pre><code>require_once 'Zend.php';require_once 'Zend/Uri/Exception.php';require_once 'Zend/Uri/Http.php';require_once 'Zend/Uri/Mailto.php';abstract class Zend_Uri{ /** * Return a string representation of this URI. * * @see getUri() * @return string */ public function __toString() { return $this->getUri(); } static public function factory($uri = 'http') { $uri = explode(':', $uri, 2); $scheme = strtolower($uri[0]); $schemeSpecific = isset($uri[1]) ? $uri[1] : ''; // Security check: $scheme is used to load a class file, // so only alphanumerics are allowed. if (!ctype_alnum($scheme)) { throw new Zend_Uri_Exception('Illegal scheme'); } }}</code></pre> <tr> <th>XML <td><pre><code><?xml version="1.0"?><response value="ok" xml:lang="en"> <text>Ok</text> <comment/> <ns:description><![CDATA[ CDATA is <not> magical. ]]></ns:description></response></code></pre> <tr> <th>HTML (with inline css and javascript) <td><pre><code><head> <title>Title</title> <style> body { width: 500px; } </style> <script> function someFunction() { return true; } </script><body> <p class="something" id='12'>Something</p> <p class=something>Something</p> <!-- comment --> <p class>Something</p> <p class="something" title="p">Something</p></body></code></pre> <tr> <th>Django templates <td><pre><code>{% if articles|length %}{% for article in articles %}{# Striped table #}<tr class="{% cycle odd,even %}"> <td>{{ article|default:"Hi... "|escape }}</td> <td>{{ article.date|date:"d.m.Y" }}</td></tr>{% endfor %}{% endif %}{% comment %}Comments may be long andmultiline.{% endcomment %}</code></pre> <tr> <th>CSS <td><pre><code>body,html { font: Tahoma, Arial, san-serif; background: url('hatch.png');}#content { width: 100%; /* wide enough */ height: 100%}p[lang=ru] { color: #F0F0F0; background: white;}</code></pre> <tr> <th>Javascript <td><pre><code>function $initHighlight(block) { if (block.className.search(/\bno\-highlight\b/) != -1) return false; try { blockText(block); } catch (e) { if (e == 'Complex markup') return; }//try var classes = block.className.split(/\s+/); for (var i = 0 / 2; i < classes.length; i++) { // "0 / 2" should not be parsed as regexp start if (LANGUAGES[classes[i]]) { highlightLanguage(block, classes[i]); return; }//if }//for highlightAuto(block);}//initHighlight</code></pre> <tr> <th>VBScript <td><pre><code>' creating configuration storage and initializing with default valuesSet cfg = CreateObject("Scripting.Dictionary")' reading ini filefor i = 0 to ubound(ini_strings) s = trim(ini_strings(i)) ' skipping empty strings and comments if mid(s, 1, 1) <> "#" and len(s) > 0 then ' obtaining key and value parts = split(s, "=", -1, 1) if ubound(parts)+1 = 2 then parts(0) = trim(parts(0)) parts(1) = trim(parts(1)) ' reading configuration and filenames select case lcase(parts(0)) case "uncompressed_postfix" cfg.item("uncompressed_postfix") = parts(1) case "f" options = split(parts(1), "|", -1, 1) if ubound(options)+1 = 2 then ' 0: filename, 1: options ff.add trim(options(0)), trim(options(1)) end if end select end if end ifnext</code></pre> <tr> <th>Delphi <td><pre><code>TList=Class(TObject)Private Some: String;Public Procedure Inside;End;{TList}Procedure CopyFile(InFileName,var OutFileName:String);Const BufSize=4096; (* Huh? *)Var InFile,OutFile:TStream; Buffer:Array[1..BufSize] Of Byte; ReadBufSize:Integer;Begin InFile:=Nil; OutFile:=Nil; Try InFile:=TFileStream.Create(InFileName,fmOpenRead); OutFile:=TFileStream.Create(OutFileName,fmCreate); Repeat ReadBufSize:=InFile.Read(Buffer,BufSize); OutFile.Write(Buffer,ReadBufSize); Until ReadBufSize<>BufSize; Log('File '''+InFileName+''' copied'#13#10); Finally InFile.Free; OutFile.Free; End;{Try}End;{CopyFile}</code></pre> <tr> <th>Java <td><pre><code>package l2f.gameserver.model;import java.util.ArrayList;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -