SemanticScuttle/includes/js/dojox/highlight/tests/test_highlight.html

328 lines
8 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<head>
<title>dojox.highlight - syntax highlighting | The Dojo Toolkit</title>
<style type="text/css">
@import "../../../dijit/tests/css/dijitTests.css";
/* a sample set of definitions to use as a foundation to color your code */
@import "../resources/highlight.css";
/* additional styling for this test case */
pre code[class]:after {
content: 'highlight: ' attr(class);
display: block; text-align: right;
font-size: smaller;
color: #CCC; background: white;
border-top: solid 1px;
padding-top: 0.5em;
}
pre code {
display: block;
}
code {
background: #F0F0F0;
}
pre code,
.ruby .subst {
color: black;
}
</style>
<script type="text/javascript" djConfig="parseOnLoad: true, isDebug: true" src="../../../dojo/dojo.js"></script>
<script type="text/javascript" src="../_base.js"></script>
<script type="text/javascript">
// initHighlightOnLoad is deprecated.
// if parseOnLoad==true, the onLoad init stuff is run.
// if parseOnLoad==false, you can call dojox.highlight.init(domNode)
//
// utilizing the dojo build system, the dojox.highlight engine
// will "do it's best" based on the language maps available
// at the time of construction.
//
dojo.require("dojox.highlight");
// several layer-like files have been provided grouping
// similar langauges, and a catch all language module
// dojox.highlight.languages._all is available for "best results"
// we need some language definitions:
dojo.require("dojox.highlight.languages._all");
//dojo.require("dojox.highlight.languages._static");
//dojo.require("dojox.highlight.languages._dynamic");
//dojo.require("dojox.highlight.languages._www");
var lazyCode = function(){
dojo.query("code").forEach(dojox.highlight.init);
dojo.xhrGet({
url: "../../../dojo/_base.js",
load: function(data){
var n = dojo.byId("foobar"),
c = document.createElement('div'),
e = n.parentNode.parentNode;
c.innerHTML = '<pre><code class="javascript">' + data.replace(/\</gi,"&lt;") + '</code></pre>';
e.replaceChild(c.firstChild, n.parentNode);
dojo.query("pre > code", e).forEach(dojox.highlight.init);
}
});
};
dojo.addOnLoad(lazyCode);
</script>
</head>
<body>
<h1 class="testTitle">dojox.highlight</h1>
<p>client-side syntax highlighting for a number of languages.</p>
<p><em>NOTE:</em> All languages listed here have working language definitions, though
not all exist in the release or dojo subversion. The missing packs are not publically available.
<span style="display:none">based on</span>
</p>
<h2>Examples:</h2>
<p>Some Python code:</p>
<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:</p>
FIXME: example needed
-->
<!--
<p>A bit of Perl:</p>
FIXME: example needed
-->
<p>A chunk of PHP: </p>
<pre><code class="php">
$opAr = array ( "-a|--append", // a or append toggle, nothing extra
"-i|--input:", // i or input with next input being needed
"-l|--list:", // l with input needed
//"--foo", // broken
"-f:", // f with no input
"--wot:" // wot with input, no short
);
$op = bgetop($opAr);
if (is_array($op)) { print_r($op); }
/* here is the code: */
function bgetop($opAr=array(),$unknown=true) {
$argv = $_SERVER['argv'];
$argc = $_SERVER['argc'];
$argPos = 1; // zero is program running
// foreach arg
while ($argPos&lt;$argc) {
$arg = $argv[$argPos];
if ($arg{0}=="-") {
if ($arg{1}=="-") {
$var = substr($arg,2,strlen($arg));
} else { $var = $arg{1}; }
foreach ($opAr as $opk => $opv) {
if (!isset($return[$var])) {
if (strpos($opv,$arg) !== FALSE) {
// this is where the -f -foo fix needs to be,
// the partial string exists in this record,
// but we need to determine if it's accurate
// somehow (i'm thinking: eregi?)
if ($accurate=1) {
// we foudn the key
if (strpos($opv,':') !== FALSE) {
// next value is the one to use,
// then skip it in the parser.
if (isset($argv[$argPos+1])) {
$return[$var] = $argv[++$argPos];
} else {
$return[$var] = FALSE;
}
} else {
// just set the toggle
$return[$var] = TRUE;
}
// don't check this opAr value again
unset($opAr[$opk]);
}
} // if accurate
} // !isset already
} // foreach opAr
} else { // we weren't expecting a non-hyphened argument, possibly just a filename, or whatnot
if ($unknown) { $return['unknown'][]=$arg; }
}
$argPos++;
} // while argPos < argc
if (is_array($return)) {
return $return;
} else { return 0; }
} // end function bgetop
</code></pre>
<p>A custom XML document:</p>
<pre><code>&lt;?xml version="1.0"?&gt;
&lt;response value="ok"&gt;
&lt;text&gt;Ok&lt;/text&gt;
&lt;comment/&gt;
&lt;ns:description&gt;&lt;![CDATA[
CDATA is &lt;not&gt; magical.
]]&gt;&lt;/ns:description&gt;
&lt;/response&gt;
</code></pre>
<p>Some HTML code:</p>
<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:</p>
<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:</p>
<pre><code>body,
html {
font: Tahoma, Arial, san-serif;
}
#content {
width: 100%; /* css comment */
height: 100%
}
p[lang=ru] {
color: red;
}
</pre></code>
<p>Explicit Python highlight:</p>
<pre><code class="python">for x in [1, 2, 3]:
count(x)
</code></pre>
<p>Disabled highlighting:</p>
<pre><code class="no-highlight">&lt;div id="contents"&gt;
&lt;p&gt;Hello, World!
&lt;/div&gt;
</code></pre>
<p>Normal dojo-looking code</p>
<pre><code>
dojo.provide("some.object");
dojo.declare("some.object",null,{
param: "value",
_myMethod: function(/* Event */e){
this.inherited(arguments);
},
// comments
_another: function(){
dojo.addClass("foo","hovered");
}
});
dojo.addOnLoad(function(){
//
// comments with &lt;HTML&gt; inline
var d = dojo;
d.mixin(d,{
foo: function(e){
d.bar(e);
},
bar: function(e){
alert(e);
}
});
});
</code></pre>
<p>Lazy, xhr'd code:</p>
<pre><code id="foobar"></code></pre>
<hr>
<p>Text with inlined JavaScript code: <code class="javascript">dojo.forEach(a, function(x){ console.log(x); });</code> &mdash; that was the inlined sample.</p>
<hr>
<p>Markuped code (python), no language was specified:</p>
<pre><code dojoType="dojo.highlight.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>Markuped code, "python" was specified:</p>
<pre><code dojoType="dojo.highlight.Code" class="python">@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>
</body><html>