client-side syntax highlighting for a number of languages.
NOTE: 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.
Some Python code:
@requires_authorization
def somefunc(param1, param2):
'''A docstring'''
if param1 > param2: # interesting
print 'Gre\'ater'
print ''
return param2 - param1 + 1
class SomeClass:
pass
A chunk of 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<$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
A custom XML document:
<?xml version="1.0"?>
<response value="ok">
<text>Ok</text>
<comment/>
<ns:description><![CDATA[
CDATA is <not> magical.
]]></ns:description>
</response>
Some HTML code:
<head>
<title>Title</title>
<body>
<p class="something">Something</p>
<p class=something>Something</p>
<!-- comment -->
<p class>Something</p>
<p class="something" title="p">Something</p>
</body>
HTML with Django templates:
{% 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 and
multiline.
{% endcomment %}
Some CSS code:
body,
html {
font: Tahoma, Arial, san-serif;
}
#content {
width: 100%; /* css comment */
height: 100%
}
p[lang=ru] {
color: red;
}
Explicit Python highlight:
for x in [1, 2, 3]:
count(x)
Disabled highlighting:
<div id="contents">
<p>Hello, World!
</div>
Normal dojo-looking 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 <HTML> inline
var d = dojo;
d.mixin(d,{
foo: function(e){
d.bar(e);
},
bar: function(e){
alert(e);
}
});
});
Lazy, xhr'd code:
/*
Copyright (c) 2004-2016, The JS Foundation All Rights Reserved.
Available via Academic Free License >= 2.1 OR the modified BSD license.
see: http://dojotoolkit.org/license for details
*/
//>>built
define("dojo/aspect",[],function(){"use strict";var _1;function _2(_3,_4,_5,_6){var _7=_3[_4];var _8=_4=="around";var _9;if(_8){var _a=_5(function(){return _7.advice(this,arguments);});_9={remove:function(){if(_a){_a=_3=_5=null;}},advice:function(_b,_c){return _a?_a.apply(_b,_c):_7.advice(_b,_c);}};}else{_9={remove:function(){if(_9.advice){var _d=_9.previous;var _e=_9.next;if(!_e&&!_d){delete _3[_4];}else{if(_d){_d.next=_e;}else{_3[_4]=_e;}if(_e){_e.previous=_d;}}_3=_5=_9.advice=null;}},id:_3.nextId++,advice:_5,receiveArguments:_6};}if(_7&&!_8){if(_4=="after"){while(_7.next&&(_7=_7.next)){}_7.next=_9;_9.previous=_7;}else{if(_4=="before"){_3[_4]=_9;_9.next=_7;_7.previous=_9;}}}else{_3[_4]=_9;}return _9;};function _f(_10){return function(_11,_12,_13,_14){var _15=_11[_12],_16;if(!_15||_15.target!=_11){_11[_12]=_16=function(){var _17=_16.nextId;var _18=arguments;var _19=_16.before;while(_19){if(_19.advice){_18=_19.advice.apply(this,_18)||_18;}_19=_19.next;}if(_16.around){var _1a=_16.around.advice(this,_18);}var _1b=_16.after;while(_1b&&_1b.id<_17){if(_1b.advice){if(_1b.receiveArguments){var _1c=_1b.advice.apply(this,_18);_1a=_1c===_1?_1a:_1c;}else{_1a=_1b.advice.call(this,_1a,_18);}}_1b=_1b.next;}return _1a;};if(_15){_16.around={advice:function(_1d,_1e){return _15.apply(_1d,_1e);}};}_16.target=_11;_16.nextId=_16.nextId||0;}var _1f=_2((_16||_15),_10,_13,_14);_13=null;return _1f;};};var _20=_f("after");var _21=_f("before");var _22=_f("around");return {before:_21,around:_22,after:_20};});
Text with inlined JavaScript code: dojo.forEach(a, function(x){ console.log(x); });
— that was the inlined sample.
Markuped code (python), no language was specified:
@requires_authorization
def somefunc(param1, param2):
'''A docstring'''
if param1 > param2: # interesting
print 'Gre\'ater'
print ''
return param2 - param1 + 1
class SomeClass:<br> pass
Markuped code, "python" was specified:
@requires_authorization
def somefunc(param1, param2):
'''A docstring'''
if param1 > param2: # interesting
print 'Gre\'ater'
print ''
return param2 - param1 + 1
class SomeClass:<br> pass
Some XQuery code:
declare variable $my:entityName as xs:string external;
declare variable $databaseURI := concat('jdbc://getCreditDefaultSwapsByEntityName?cd%&', $my:entityName);
declare variable $creditDefaultSwaps := collection($databaseURI);
(: This is a comment :)
(: This is a multi-line
comment :)
declare function local:equityRows($root) {
for $equity in $root//equity
let $referenceEntity := $creditDefaultSwaps//fpml:referenceEntity
where $equity/name = $referenceEntity/fpml:entityName
return
<tr xmlns="http://www.w3.org/1999/xhtml">
<td>{ $equity/*:symbol/text() }</td>
<td>{ $equity/*:name/text() }</td>
<td>{ $equity/*:high/text() }</td>
<td>{ $equity/*:currency/text() }</td>
</tr>
};
<table border="1">
<tr>
<th>Ticker Symbol</th>
<th>Company Name</th>
<th>High</th>
<th>Currency</th>
</tr>
{ local:equityRows(/) }
</table>
Some Java code:
import java.io.*;
public final class DOHRobot extends Applet{
// The last reported mouse x,y.
// If this is different from the real one, something's up.
private int lastMouseX;
private int lastMouseY;
JSObject dohrobot = null;
final private class onvisible extends ComponentAdapter{
public void componentShown(ComponentEvent evt){
/* sets the security manager to fix a bug *
* in liveconnect in Safari on Mac */
if(key != -1){ return; }
Thread thread = new Thread(){
public void run(){
window = (JSObject) JSObject.getWindow(applet());
AccessController.doPrivileged(new PrivilegedAction(){
public Object run(){
log("> init Robot");
try{
SecurityManager oldsecurity = System.getSecurityManager();
boolean needsSecurityManager = applet().getParameter("needsSecurityManager").equals("true");
log("Socket connections managed? "+needsSecurityManager);
try{
securitymanager.checkTopLevelWindow(null);
// xdomain
if(charMap == null){
if(!confirm("DOH has detected that the current Web page is attempting to access DOH,\n"+
"but belongs to a different domain than the one you agreed to let DOH automate.")){
return null;
}
}
}catch(Exception e){
e.printStackTrace();
securitymanager = new RobotSecurityManager(needsSecurityManager,
oldsecurity);
System.setSecurityManager(securitymanager);
}
// instantiate the Robot
robot = new Robot();
robot.setAutoWaitForIdle(true);
}catch(Exception e){
key = -2;
e.printStackTrace();
}
return null;
}
});
if(key == -2){
// applet not trusted
// start the test without it
window.eval("doh.robot._appletDead=true;doh.run();");
}
}
};
thread.start();
}
}
}
A Groovy fragment:
/*
* A comment test block
*
* ?debug
* ?nodebug
*
*/
def settings = [
debug: false,
compress: true,
console: false,
ping: false,
testing: false,
profile: false
];
// function calls
init(settings);
render(settings);
def render(settings) {
request.header = settings;
render();
}
def init(settings) {
// Default parameter handling.
settings.each { key, value ->
def onkey = "${key}";
def offkey = "no${key}";
if (foo("/request/params/${onkey}",null) != null) {
settings[key] = true;
}
else if (foo("/request/params/${offkey}",null) != null) {
settings[key] = false;
}
}
return settings;
}