Files
luos/gulliver/js/highlight/core/test.html
2011-09-05 12:47:25 -04:00

620 lines
15 KiB
HTML
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<head>
<title>Highlight</title>
<link rel="stylesheet" href="sample.css">
<script type="text/javascript" src="highlight.js"></script>
<script type="text/javascript">
initHighlightingOnLoad('1c', 'axapta', 'cpp', 'delphi', 'xml', 'html', 'css', 'django', 'java', 'javascript', 'perl', 'php', 'python', 'rib', 'rsl', 'ruby', 'smalltalk', 'sql', 'vbscript');
</script>
<body>
<p>Some Python code:
<pre><code>@requires_authorization
def somefunc(param1, param2):
'''A docstring'''
if param1 > param2: # interesting
print 'Gre\'ater'
print ''
return param2 - param1 + 1
class SomeClass:<br> pass
</code></pre>
<p>Short sample of Ruby:
<pre><code># Ruby support for highlight.js
class CategoriesController &lt; ApplicationController
layout "core"
before_filter :login_required
before_filter :xhr_required, :only =&gt; [:create, :update]
before_filter :admin_privileges_required, :except =&gt; [:show]
=begin
This method creates a category. Very difficult to understand, huh?
=end
def create
@category = Category.create(params[:category])
flash[:notice] = "Category #{@category + "..."} was successfully created"
end
end
</code></pre>
<p>A bit of Perl:
<pre><code># loads object
sub load
{
my $c = shift;
my $id = shift;
my $flds = $c-&gt;db_load($id,@_) || do { Carp::carp "Can`t load (class: $c, id: $id): '$!'"; return undef };
my $o = $c-&gt;_perl_new();
$id12 = $id;
$o-&gt;{'ID'} = $id12 + 123;
$o-&gt;{'PAPA'} = $flds-&gt;{'PAPA'};
#$o-&gt;{'SHCUT'} = $flds-&gt;{'SHCUT'};
my $p = $o-&gt;props;
#if($o-&gt;{'SHCUT'})
#{
# $flds = $o-&gt;db_load($o-&gt;{'SHCUT'},@_);
#}
my $vt;
for my $key (keys %$p)
{
if(${$vt.'::property'})
{
$o-&gt;{$key . '_real'} = $flds-&gt;{$key};
tie $o-&gt;{$key}, 'CMSBuilder::Property', $o, $key;
}
else
{
$o-&gt;{$key} = $flds-&gt;{$key};
}
}
$o-&gt;save if delete $o-&gt;{'_save_after_load'};
return $o;
}
</code></pre>
<p>A chunk of PHP:
<pre><code>require_once 'Zend.php';
require_once 'Zend/Uri/Exception.php';
require_once 'Zend/Uri/Http.php';
/**
* Zend_Uri_Mailto
*/
require_once 'Zend/Uri/Mailto.php';
/**
* @category Zend
* @package Zend_Uri
* @copyright Copyright (c) 2006 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Uri
{
/**
* Scheme of this URI (http, ftp, etc.)
* @var string
*/
protected $_scheme = "";
/**
* Return a string representation of this URI.
*
* @see getUri()
* @return string
*/
public function __toString()
{
return $this-&gt;getUri();
}
static public function check($uri)
{
try {
$uri = self::factory($uri);
} catch (Exception $e) {
return false;
}
return $uri-&gt;valid();
}
/**
* Create a new Zend_Uri object for a URI. If building a new URI, then $uri should contain
* only the scheme (http, ftp, etc). Otherwise, supply $uri with the complete URI.
*
* @param string $uri
* @throws Zend_Uri_Exception
* @return Zend_Uri
*/
static public function factory($uri = 'http')
{
/**
* Separate the scheme from the scheme-specific parts
* @link http://www.faqs.org/rfcs/rfc2396.html
*/
$uri = explode(':', $uri, 2);
$scheme = strtolower($uri[0]);
$schemeSpecific = isset($uri[1]) ? $uri[1] : '';
if (!strlen($scheme)) {
throw new Zend_Uri_Exception('An empty string was supplied for the scheme');
}
// 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 supplied, only alphanumeric characters are permitted');
}
}
</code></pre>
<p>A custom XML document:
<pre><code>&lt;?xml version="1.0"?&gt;
&lt;response value="ok"&gt;
&lt;text&gt;Ok&lt;/text&gt;
&lt;comment/&gt;
&lt;description&gt;&lt;![CDATA[
CDATA is &lt;not&gt; magical.
]]&gt;&lt;/description&gt;
&lt;/response&gt;
</code></pre>
<p>Some HTML code:
<pre><code>&lt;head&gt;
&lt;title&gt;Title&lt;/title&gt;
&lt;body&gt;
&lt;p class="something"&gt;Something&lt;/p&gt;
&lt;p class=something&gt;Something&lt;/p&gt;
&lt;!-- comment --&gt;
&lt;p class&gt;Something&lt;/p&gt;
&lt;p class="something" title="p"&gt;Something&lt;/p&gt;
&lt;/body&gt;
</code></pre>
<p>HTML with Django templates:
<pre><code>{% if articles|length %}
{% for article in articles %}
{# Striped table #}
&lt;tr class="{% cycle odd,even %}"&gt;
&lt;td&gt;{{ article|default:"Hi... "|escape }}&lt;/td&gt;
&lt;td&gt;{{ article.date|date:"d.m.Y" }}&lt;/td&gt;
&lt;/tr&gt;
{% endfor %}
{% endif %}
{% comment %}
Comments may be long and
multiline.
{% endcomment %}
</code></pre>
<p>Some CSS code:
<pre><code>body,
html {
font: Tahoma, Arial, san-serif;
}
#content {
width: 100%; /* комментарий */
height: 100%
}
p[lang=ru] {
color: red;
}
</pre></code>
<p>Javascript here too (right from the source, mind you):
<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; i &lt; classes.length; i++) {
if (LANGUAGES[classes[i]]) {
highlightLanguage(block, classes[i]);
return;
}//if
}//for
highlightAuto(block);
}//initHighlight</code></pre>
<p>VBScript
<pre><code>' creating configuration storage and initializing with default values
Set cfg = CreateObject("Scripting.Dictionary")
cfg.add "dest", ""
cfg.add "dest_gz", ""
cfg.add "gzip_exe", ""
cfg.add "perl_exe", ""
cfg.add "uncompressed_postfix", ""
' reading ini file
for i = 0 to ubound(ini_strings)
s = trim(ini_strings(i))
' skipping empty strings and comments
if mid(s, 1, 1) &lt;&gt; "#" 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 "dest" cfg.item("dest") = parts(1)
case "dest_gz" cfg.item("dest_gz") = parts(1)
case "gzip_exe" cfg.item("gzip_exe") = parts(1)
case "perl_exe" cfg.item("perl_exe") = parts(1)
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 if
next</code></pre>
<P>Delphi code
<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&lt;&gt;BufSize;
Log('File '''+InFileName+''' copied'#13#10);
Finally
InFile.Free;
OutFile.Free;
End;{Try}
End;{CopyFile}
</code></pre>
<p>From Java world:
<pre><code>package l2f.gameserver.model;
import java.util.ArrayList;
/**
* Mother class of all character objects of the world (PC, NPC...)&lt;BR&gt;&lt;BR&gt;
*
*/
public abstract class L2Character extends L2Object
{
protected static final Logger _log = Logger.getLogger(L2Character.class.getName());
public static final Short ABNORMAL_EFFECT_BLEEDING = 0x0001; // not sure
public static final Short ABNORMAL_EFFECT_POISON = 0x0002;
/**
* Cancel the AI.&lt;BR&gt;&lt;BR&gt;
*/
public void detachAI()
{
_ai = null;
//jbf = null;
if (1 > 5)
{
return;
}
}
public void moveTo(int x, int y, int z)
{
moveTo(x, y, z, 0);
}
/** Task of AI notification */
@SuppressWarnings( { "nls", "unqualified-field-access", "boxing" })
public class NotifyAITask implements Runnable
{
private final CtrlEvent _evt;
public NotifyAITask(CtrlEvent evt)
{
this._evt = evt;
}
public void run()
{
try
{
getAI().notifyEvent(_evt, null, null);
}
catch (Throwable t)
{
_log.warning("Exception " + t);
t.printStackTrace();
}
}
}
private static final int HP_REGEN_FLAG = 1;
private static final int MP_REGEN_FLAG = 2;
private static final int CP_REGEN_FLAG = 4;
/** The table containing the List of all stacked effect in progress for each Stack group Identifier */
private ConcurrentHashMap&lt;String, Short&gt; _stackedEffects = null;
}
</code></pre>
<p>C++:
<pre><code>#include &lt;iostream&gt;
int main(int argc, char *argv[]) {
/* An annoying "Hello World" example */
for (unsigned i = 0; i &lt; 0xFFFF; i++)
cout &lt;&lt; "Hello, World!" &lt;&lt; endl;
char c = '\n'; // just a test
char *s = "\\\\"; // another test
}
</code></pre>
<p>Bet you didn't expect to see a highlighted RenderMan (both RenderMan
Shading Language and RenderMan Interface Bytestream):</p>
<pre><code>#define TEST_DEFINE 3.14
/* plastic surface shader
*
* Pixie is:
* (c) Copyright 1999-2003 Okan Arikan. All rights reserved.
*/
surface plastic (float Ka = 1, Kd = 0.5, Ks = 0.5, roughness = 0.1;
color specularcolor = 1;) {
normal Nf = faceforward (normalize(N),I);
Ci = Cs * (Ka*ambient() + Kd*diffuse(Nf)) + specularcolor * Ks*specular(Nf,-normalize(I),roughness);
Oi = Os;
Ci *= Oi;
}
</code></pre>
<pre><code>FrameBegin 0
Display "Scene" "framebuffer" "rgb"
Option "searchpath" "shader" "+&:/home/kew"
Option "trace" "int maxdepth" [4]
Attribute "visibility" "trace" [1]
Attribute "irradiance" "maxerror" [0.1]
Attribute "visibility" "transmission" "opaque"
Format 640 480 1.0
ShadingRate 2
PixelFilter "catmull-rom" 1 1
PixelSamples 4 4
Projection "perspective" "fov" 49.5502811377
Scale 1 1 -1
ConcatTransform [-0.105581186712 -0.336664259434 0.935686826706 0.0
0.994097530842 -0.0121211335063 0.107810914516 0.0
-0.0249544940889 0.941546678543 0.335956931114 0.0
0.103667020798 -1.30126297474 -6.22769546509 1.0]
WorldBegin
ReadArchive "/home/qewerty/blends/my/instances/Lamp.002_Light/instance.rib"
Surface "plastic"
ReadArchive "/home/qewerty/blends/my/instances/Cube.004_Mesh/instance.rib"
# ReadArchive "/home/qewerty/blends/my/instances/Sphere.010_Mesh/instance.rib"
# ReadArchive "/home/qewerty/blends/my/instances/Sphere.009_Mesh/instance.rib"
ReadArchive "/home/qewerty/blends/my/instances/Sphere.006_Mesh/instance.rib"
WorldEnd
FrameEnd
</code></pre>
<p>SQL:
<pre><code>BEGIN;
CREATE TABLE "cicero_topic" (
"id" serial NOT NULL PRIMARY KEY,
"forum_id" integer NOT NULL,
"subject" varchar(255) NOT NULL,
"created" timestamp with time zone NOT NULL
);
ALTER TABLE "cicero_topic"
ADD CONSTRAINT forum_id_refs_id_4be56999
FOREIGN KEY ("forum_id")
REFERENCES "cicero_forum" ("id")
DEFERRABLE INITIALLY DEFERRED;
-- Initials
insert into "cicero_forum" ("slug", "name", "group", "ordering") values ('test', 'Тест''овый форум', 'Тест', 0);
-- Indices
CREATE INDEX "cicero_topic_forum_id" ON "cicero_topic" ("forum_id");
-- Test
select count(*) from cicero_forum;
COMMIT;
</code></pre>
<p>Good old classic SmallTalk:
<pre><code>Object>>method: num
"comment 123"
| var1 var2 |
(1 to: num) do: [:i | |var| ^i].
Klass with: var1.
Klass new.
arr := #('123' 123.345 #hello Transcript var $@).
arr := #().
var2 = arr at: 3.
^ self abc
heapExample
"HeapTest new heapExample"
"Create a sorted collection of numbers, remove the elements
sequentially and add new objects randomly.
Note: This is the kind of benchmark a heap is designed for."
| n rnd array time sorted |
n := 5000.
"# of elements to sort"
rnd := Random new.
array := (1 to: n)
collect: [:i | rnd next].
"First, the heap version"
time := Time
millisecondsToRun: [sorted := Heap withAll: array.
1
to: n
do: [:i |
sorted removeFirst.
sorted add: rnd next]].
Transcript cr; show: 'Time for Heap: ' , time printString , ' msecs'.
"The quicksort version"
time := Time
millisecondsToRun: [sorted := SortedCollection withAll: array.
1
to: n
do: [:i |
sorted removeFirst.
sorted add: rnd next]].
Transcript cr; show: 'Time for SortedCollection: ' , time printString , ' msecs'
</code></pre>
<p>Axapta:
<pre><code>class ExchRateLoadBatch extends RunBaseBatch
{
ExchRateLoad rbc;
container currencies;
boolean actual;
boolean overwrite;
date beg;
date end;
#define.CurrentVersion(5)
#localmacro.CurrentList
currencies,
actual,
beg,
end
#endmacro
}
public boolean unpack(container packedClass)
{
container base;
boolean ret;
Integer version = runbase::getVersion(packedClass);
switch (version)
{
case #CurrentVersion:
[version, #CurrentList] = packedClass;
return true;
default:
return false;
}
return ret;
}
</code></pre>
<p>And this is a russian enterpise system "1С":
<pre><code class="1c">
#Если Клиент Тогда
Перем СимвольныйКодКаталога = "ля-ля-ля"; //комментарий
Функция Сообщить(Знач ТекстСообщения, ТекстСообщения2) Экспорт //комментарий к функции
x=ТекстСообщения+ТекстСообщения2+"
|строка1
|строка2
|строка3";
КонецФункции
#КонецЕсли
////////////////////////////////////////////////////////////////////////////////
// ОБРАБОТЧИКИ СОБЫТИЙ
//
// Процедура ПриНачалеРаботыСистемы
//
Процедура ПриНачалеРаботыСистемы()
Обработки.Помощник.ПолучитьФорму("Форма").Открыть();
КонецПроцедуры
</code></pre>
<hr>
<p>Explicit Python highlight:
<pre><code class="python">for x in [1, 2, 3]:
count(x)
</code></pre>
<p>Disabled highlighting:
<pre><code class="no-highlight">&lt;div id="contents"&gt;
&lt;p&gt;Hello, World!
&lt;/div&gt;
</code></pre>