AmberRack 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +74 -0
- data/.rvmrc +4 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +62 -0
- data/README.md +17 -0
- data/Rakefile +24 -0
- data/amber-rack.gemspec +33 -0
- data/app/amber_app.rb +35 -0
- data/app/javascripts/Benchfib.deploy.js +159 -0
- data/app/javascripts/Benchfib.js +159 -0
- data/app/javascripts/Canvas.deploy.js +1464 -0
- data/app/javascripts/Canvas.js +1464 -0
- data/app/javascripts/Compiler.deploy.js +1587 -0
- data/app/javascripts/Compiler.js +1587 -0
- data/app/javascripts/Examples.deploy.js +800 -0
- data/app/javascripts/Examples.js +800 -0
- data/app/javascripts/IDE.deploy.js +3457 -0
- data/app/javascripts/IDE.js +3457 -0
- data/app/javascripts/IDE.js.bak +3420 -0
- data/app/javascripts/JQuery.deploy.js +898 -0
- data/app/javascripts/JQuery.js +898 -0
- data/app/javascripts/Kernel.deploy.js +6761 -0
- data/app/javascripts/Kernel.js +6761 -0
- data/app/javascripts/Parser.deploy.js +1655 -0
- data/app/javascripts/Parser.js +1655 -0
- data/app/javascripts/Raphael-Core.js +0 -0
- data/app/javascripts/Raphael-Graph.js +0 -0
- data/app/javascripts/SUnit.deploy.js +1059 -0
- data/app/javascripts/SUnit.js +1059 -0
- data/app/javascripts/application.js +2 -0
- data/app/javascripts/boot.js +466 -0
- data/app/javascripts/init.js +2 -0
- data/app/javascripts/jquery-1.4.4.min.js +167 -0
- data/app/javascripts/jquery-ui-1.8.9.custom.min.js +781 -0
- data/app/javascripts/jquery.textarea.js +267 -0
- data/app/javascripts/jtalk.js +78 -0
- data/app/javascripts/lib/CodeMirror/LICENSE +19 -0
- data/app/javascripts/lib/CodeMirror/README.md +6 -0
- data/app/javascripts/lib/CodeMirror/compress.html +92 -0
- data/app/javascripts/lib/CodeMirror/css/baboon.png +0 -0
- data/app/javascripts/lib/CodeMirror/css/baboon_vector.svg +153 -0
- data/app/javascripts/lib/CodeMirror/css/docs.css +154 -0
- data/app/javascripts/lib/CodeMirror/demo/activeline.html +72 -0
- data/app/javascripts/lib/CodeMirror/demo/changemode.html +51 -0
- data/app/javascripts/lib/CodeMirror/demo/complete.html +79 -0
- data/app/javascripts/lib/CodeMirror/demo/complete.js +151 -0
- data/app/javascripts/lib/CodeMirror/demo/fullscreen.html +158 -0
- data/app/javascripts/lib/CodeMirror/demo/marker.html +53 -0
- data/app/javascripts/lib/CodeMirror/demo/mustache.html +57 -0
- data/app/javascripts/lib/CodeMirror/demo/preview.html +75 -0
- data/app/javascripts/lib/CodeMirror/demo/resize.html +44 -0
- data/app/javascripts/lib/CodeMirror/demo/runmode.html +50 -0
- data/app/javascripts/lib/CodeMirror/demo/search.html +106 -0
- data/app/javascripts/lib/CodeMirror/demo/theme.html +53 -0
- data/app/javascripts/lib/CodeMirror/index.html +239 -0
- data/app/javascripts/lib/CodeMirror/internals.html +389 -0
- data/app/javascripts/lib/CodeMirror/lib/codemirror.css +67 -0
- data/app/javascripts/lib/CodeMirror/lib/codemirror.js +2144 -0
- data/app/javascripts/lib/CodeMirror/lib/overlay.js +51 -0
- data/app/javascripts/lib/CodeMirror/lib/runmode.js +27 -0
- data/app/javascripts/lib/CodeMirror/manual.html +854 -0
- data/app/javascripts/lib/CodeMirror/mode/clike/clike.js +247 -0
- data/app/javascripts/lib/CodeMirror/mode/clike/index.html +102 -0
- data/app/javascripts/lib/CodeMirror/mode/css/css.js +124 -0
- data/app/javascripts/lib/CodeMirror/mode/css/index.html +56 -0
- data/app/javascripts/lib/CodeMirror/mode/diff/diff.css +3 -0
- data/app/javascripts/lib/CodeMirror/mode/diff/diff.js +13 -0
- data/app/javascripts/lib/CodeMirror/mode/diff/index.html +99 -0
- data/app/javascripts/lib/CodeMirror/mode/haskell/haskell.js +242 -0
- data/app/javascripts/lib/CodeMirror/mode/haskell/index.html +60 -0
- data/app/javascripts/lib/CodeMirror/mode/htmlmixed/htmlmixed.js +79 -0
- data/app/javascripts/lib/CodeMirror/mode/htmlmixed/index.html +52 -0
- data/app/javascripts/lib/CodeMirror/mode/javascript/index.html +78 -0
- data/app/javascripts/lib/CodeMirror/mode/javascript/javascript.js +348 -0
- data/app/javascripts/lib/CodeMirror/mode/lua/index.html +72 -0
- data/app/javascripts/lib/CodeMirror/mode/lua/lua.js +138 -0
- data/app/javascripts/lib/CodeMirror/mode/php/index.html +49 -0
- data/app/javascripts/lib/CodeMirror/mode/php/php.js +110 -0
- data/app/javascripts/lib/CodeMirror/mode/plsql/index.html +63 -0
- data/app/javascripts/lib/CodeMirror/mode/plsql/plsql.js +217 -0
- data/app/javascripts/lib/CodeMirror/mode/python/LICENSE.txt +21 -0
- data/app/javascripts/lib/CodeMirror/mode/python/index.html +123 -0
- data/app/javascripts/lib/CodeMirror/mode/python/python.js +321 -0
- data/app/javascripts/lib/CodeMirror/mode/rst/index.html +526 -0
- data/app/javascripts/lib/CodeMirror/mode/rst/rst.css +75 -0
- data/app/javascripts/lib/CodeMirror/mode/rst/rst.js +333 -0
- data/app/javascripts/lib/CodeMirror/mode/scheme/index.html +65 -0
- data/app/javascripts/lib/CodeMirror/mode/scheme/scheme.js +181 -0
- data/app/javascripts/lib/CodeMirror/mode/smalltalk/index.html +56 -0
- data/app/javascripts/lib/CodeMirror/mode/smalltalk/smalltalk.js +134 -0
- data/app/javascripts/lib/CodeMirror/mode/sparql/index.html +41 -0
- data/app/javascripts/lib/CodeMirror/mode/sparql/sparql.js +143 -0
- data/app/javascripts/lib/CodeMirror/mode/stex/index.html +96 -0
- data/app/javascripts/lib/CodeMirror/mode/stex/stex.js +167 -0
- data/app/javascripts/lib/CodeMirror/mode/xml/index.html +42 -0
- data/app/javascripts/lib/CodeMirror/mode/xml/xml.js +231 -0
- data/app/javascripts/lib/CodeMirror/mode/yaml/index.html +68 -0
- data/app/javascripts/lib/CodeMirror/mode/yaml/yaml.js +95 -0
- data/app/javascripts/lib/CodeMirror/oldrelease.html +178 -0
- data/app/javascripts/lib/CodeMirror/test/index.html +29 -0
- data/app/javascripts/lib/CodeMirror/test/test.js +249 -0
- data/app/javascripts/lib/CodeMirror/theme/default.css +18 -0
- data/app/javascripts/lib/CodeMirror/theme/elegant.css +9 -0
- data/app/javascripts/lib/CodeMirror/theme/jtalk.css +21 -0
- data/app/javascripts/lib/CodeMirror/theme/neat.css +8 -0
- data/app/javascripts/lib/CodeMirror/theme/night.css +20 -0
- data/app/javascripts/lib/jQuery/jquery-1.4.4.min.js +167 -0
- data/app/javascripts/lib/jQuery/jquery-ui-1.8.9.custom.min.js +781 -0
- data/app/javascripts/lib/jQuery/jquery.textarea.js +267 -0
- data/app/smalltalk/Canvas.st +481 -0
- data/app/smalltalk/IDE.st +1752 -0
- data/config.ru +2 -0
- data/lib/amber-rack.rb +4 -0
- data/lib/amber-rack/version.rb +3 -0
- data/public/CodeMirror/LICENSE +19 -0
- data/public/CodeMirror/README.md +6 -0
- data/public/CodeMirror/compress.html +92 -0
- data/public/CodeMirror/css/baboon.png +0 -0
- data/public/CodeMirror/css/baboon_vector.svg +153 -0
- data/public/CodeMirror/css/docs.css +154 -0
- data/public/CodeMirror/demo/activeline.html +72 -0
- data/public/CodeMirror/demo/changemode.html +51 -0
- data/public/CodeMirror/demo/complete.html +79 -0
- data/public/CodeMirror/demo/complete.js +151 -0
- data/public/CodeMirror/demo/fullscreen.html +158 -0
- data/public/CodeMirror/demo/marker.html +53 -0
- data/public/CodeMirror/demo/mustache.html +57 -0
- data/public/CodeMirror/demo/preview.html +75 -0
- data/public/CodeMirror/demo/resize.html +44 -0
- data/public/CodeMirror/demo/runmode.html +50 -0
- data/public/CodeMirror/demo/search.html +106 -0
- data/public/CodeMirror/demo/theme.html +53 -0
- data/public/CodeMirror/index.html +239 -0
- data/public/CodeMirror/internals.html +389 -0
- data/public/CodeMirror/lib/codemirror.css +67 -0
- data/public/CodeMirror/lib/codemirror.js +2144 -0
- data/public/CodeMirror/lib/overlay.js +51 -0
- data/public/CodeMirror/lib/runmode.js +27 -0
- data/public/CodeMirror/manual.html +854 -0
- data/public/CodeMirror/mode/clike/clike.js +247 -0
- data/public/CodeMirror/mode/clike/index.html +102 -0
- data/public/CodeMirror/mode/css/css.js +124 -0
- data/public/CodeMirror/mode/css/index.html +56 -0
- data/public/CodeMirror/mode/diff/diff.css +3 -0
- data/public/CodeMirror/mode/diff/diff.js +13 -0
- data/public/CodeMirror/mode/diff/index.html +99 -0
- data/public/CodeMirror/mode/haskell/haskell.js +242 -0
- data/public/CodeMirror/mode/haskell/index.html +60 -0
- data/public/CodeMirror/mode/htmlmixed/htmlmixed.js +79 -0
- data/public/CodeMirror/mode/htmlmixed/index.html +52 -0
- data/public/CodeMirror/mode/javascript/index.html +78 -0
- data/public/CodeMirror/mode/javascript/javascript.js +348 -0
- data/public/CodeMirror/mode/lua/index.html +72 -0
- data/public/CodeMirror/mode/lua/lua.js +138 -0
- data/public/CodeMirror/mode/php/index.html +49 -0
- data/public/CodeMirror/mode/php/php.js +110 -0
- data/public/CodeMirror/mode/plsql/index.html +63 -0
- data/public/CodeMirror/mode/plsql/plsql.js +217 -0
- data/public/CodeMirror/mode/python/LICENSE.txt +21 -0
- data/public/CodeMirror/mode/python/index.html +123 -0
- data/public/CodeMirror/mode/python/python.js +321 -0
- data/public/CodeMirror/mode/rst/index.html +526 -0
- data/public/CodeMirror/mode/rst/rst.css +75 -0
- data/public/CodeMirror/mode/rst/rst.js +333 -0
- data/public/CodeMirror/mode/scheme/index.html +65 -0
- data/public/CodeMirror/mode/scheme/scheme.js +181 -0
- data/public/CodeMirror/mode/smalltalk/index.html +56 -0
- data/public/CodeMirror/mode/smalltalk/smalltalk.js +134 -0
- data/public/CodeMirror/mode/sparql/index.html +41 -0
- data/public/CodeMirror/mode/sparql/sparql.js +143 -0
- data/public/CodeMirror/mode/stex/index.html +96 -0
- data/public/CodeMirror/mode/stex/stex.js +167 -0
- data/public/CodeMirror/mode/xml/index.html +42 -0
- data/public/CodeMirror/mode/xml/xml.js +231 -0
- data/public/CodeMirror/mode/yaml/index.html +68 -0
- data/public/CodeMirror/mode/yaml/yaml.js +95 -0
- data/public/CodeMirror/oldrelease.html +178 -0
- data/public/CodeMirror/test/index.html +29 -0
- data/public/CodeMirror/test/test.js +249 -0
- data/public/CodeMirror/theme/default.css +18 -0
- data/public/CodeMirror/theme/elegant.css +9 -0
- data/public/CodeMirror/theme/jtalk.css +21 -0
- data/public/CodeMirror/theme/neat.css +8 -0
- data/public/CodeMirror/theme/night.css +20 -0
- data/public/css/jtalk.css +362 -0
- data/public/css/style.css +456 -0
- data/public/css/sunit.css +66 -0
- data/public/ide/fork_me.png +0 -0
- data/public/ide/screen2.png +0 -0
- data/public/ide/style.css +456 -0
- data/public/ide/syntax.css +61 -0
- data/public/ide/text_header.png +0 -0
- data/public/ide/title_container1.png +0 -0
- data/public/images/background_box.png +0 -0
- data/public/images/background_header.png +0 -0
- data/public/images/balloon_header.png +0 -0
- data/views/index.haml +66 -0
- metadata +341 -0
@@ -0,0 +1,96 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>CodeMirror 2: sTeX mode</title>
|
5
|
+
<link rel="stylesheet" href="../../lib/codemirror.css">
|
6
|
+
<script src="../../lib/codemirror.js"></script>
|
7
|
+
<script src="stex.js"></script>
|
8
|
+
<link rel="stylesheet" href="../../theme/default.css">
|
9
|
+
<style>.CodeMirror {background: #f8f8f8;}</style>
|
10
|
+
<link rel="stylesheet" href="../../css/docs.css">
|
11
|
+
</head>
|
12
|
+
<body>
|
13
|
+
<h1>CodeMirror 2: sTeX mode</h1>
|
14
|
+
<form><textarea id="code" name="code">
|
15
|
+
\begin{module}[id=bbt-size]
|
16
|
+
\importmodule[balanced-binary-trees]{balanced-binary-trees}
|
17
|
+
\importmodule[\KWARCslides{dmath/en/cardinality}]{cardinality}
|
18
|
+
|
19
|
+
\begin{frame}
|
20
|
+
\frametitle{Size Lemma for Balanced Trees}
|
21
|
+
\begin{itemize}
|
22
|
+
\item
|
23
|
+
\begin{assertion}[id=size-lemma,type=lemma]
|
24
|
+
Let $G=\tup{V,E}$ be a \termref[cd=binary-trees]{balanced binary tree}
|
25
|
+
of \termref[cd=graph-depth,name=vertex-depth]{depth}$n>i$, then the set
|
26
|
+
$\defeq{\livar{V}i}{\setst{\inset{v}{V}}{\gdepth{v} = i}}$ of
|
27
|
+
\termref[cd=graphs-intro,name=node]{nodes} at
|
28
|
+
\termref[cd=graph-depth,name=vertex-depth]{depth} $i$ has
|
29
|
+
\termref[cd=cardinality,name=cardinality]{cardinality} $\power2i$.
|
30
|
+
\end{assertion}
|
31
|
+
\item
|
32
|
+
\begin{sproof}[id=size-lemma-pf,proofend=,for=size-lemma]{via induction over the depth $i$.}
|
33
|
+
\begin{spfcases}{We have to consider two cases}
|
34
|
+
\begin{spfcase}{$i=0$}
|
35
|
+
\begin{spfstep}[display=flow]
|
36
|
+
then $\livar{V}i=\set{\livar{v}r}$, where $\livar{v}r$ is the root, so
|
37
|
+
$\eq{\card{\livar{V}0},\card{\set{\livar{v}r}},1,\power20}$.
|
38
|
+
\end{spfstep}
|
39
|
+
\end{spfcase}
|
40
|
+
\begin{spfcase}{$i>0$}
|
41
|
+
\begin{spfstep}[display=flow]
|
42
|
+
then $\livar{V}{i-1}$ contains $\power2{i-1}$ vertexes
|
43
|
+
\begin{justification}[method=byIH](IH)\end{justification}
|
44
|
+
\end{spfstep}
|
45
|
+
\begin{spfstep}
|
46
|
+
By the \begin{justification}[method=byDef]definition of a binary
|
47
|
+
tree\end{justification}, each $\inset{v}{\livar{V}{i-1}}$ is a leaf or has
|
48
|
+
two children that are at depth $i$.
|
49
|
+
\end{spfstep}
|
50
|
+
\begin{spfstep}
|
51
|
+
As $G$ is \termref[cd=balanced-binary-trees,name=balanced-binary-tree]{balanced} and $\gdepth{G}=n>i$, $\livar{V}{i-1}$ cannot contain
|
52
|
+
leaves.
|
53
|
+
\end{spfstep}
|
54
|
+
\begin{spfstep}[type=conclusion]
|
55
|
+
Thus $\eq{\card{\livar{V}i},{\atimes[cdot]{2,\card{\livar{V}{i-1}}}},{\atimes[cdot]{2,\power2{i-1}}},\power2i}$.
|
56
|
+
\end{spfstep}
|
57
|
+
\end{spfcase}
|
58
|
+
\end{spfcases}
|
59
|
+
\end{sproof}
|
60
|
+
\item
|
61
|
+
\begin{assertion}[id=fbbt,type=corollary]
|
62
|
+
A fully balanced tree of depth $d$ has $\power2{d+1}-1$ nodes.
|
63
|
+
\end{assertion}
|
64
|
+
\item
|
65
|
+
\begin{sproof}[for=fbbt,id=fbbt-pf]{}
|
66
|
+
\begin{spfstep}
|
67
|
+
Let $\defeq{G}{\tup{V,E}}$ be a fully balanced tree
|
68
|
+
\end{spfstep}
|
69
|
+
\begin{spfstep}
|
70
|
+
Then $\card{V}=\Sumfromto{i}1d{\power2i}= \power2{d+1}-1$.
|
71
|
+
\end{spfstep}
|
72
|
+
\end{sproof}
|
73
|
+
\end{itemize}
|
74
|
+
\end{frame}
|
75
|
+
\begin{note}
|
76
|
+
\begin{omtext}[type=conclusion,for=binary-tree]
|
77
|
+
This shows that balanced binary trees grow in breadth very quickly, a consequence of
|
78
|
+
this is that they are very shallow (and this compute very fast), which is the essence of
|
79
|
+
the next result.
|
80
|
+
\end{omtext}
|
81
|
+
\end{note}
|
82
|
+
\end{module}
|
83
|
+
|
84
|
+
%%% Local Variables:
|
85
|
+
%%% mode: LaTeX
|
86
|
+
%%% TeX-master: "all"
|
87
|
+
%%% End: \end{document}
|
88
|
+
</textarea></form>
|
89
|
+
<script>
|
90
|
+
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
|
91
|
+
</script>
|
92
|
+
|
93
|
+
<p><strong>MIME types defined:</strong> <code>text/stex</code>.</p>
|
94
|
+
|
95
|
+
</body>
|
96
|
+
</html>
|
@@ -0,0 +1,167 @@
|
|
1
|
+
/*
|
2
|
+
* Author: Constantin Jucovschi (c.jucovschi@jacobs-university.de)
|
3
|
+
* Licence: MIT
|
4
|
+
*/
|
5
|
+
|
6
|
+
CodeMirror.defineMode("stex", function(cmCfg, modeCfg)
|
7
|
+
{
|
8
|
+
function pushCommand(state, command) {
|
9
|
+
state.cmdState.push(command);
|
10
|
+
}
|
11
|
+
|
12
|
+
function peekCommand(state) {
|
13
|
+
if (state.cmdState.length>0)
|
14
|
+
return state.cmdState[state.cmdState.length-1];
|
15
|
+
else
|
16
|
+
return null;
|
17
|
+
}
|
18
|
+
|
19
|
+
function popCommand(state) {
|
20
|
+
if (state.cmdState.length>0) {
|
21
|
+
var plug = state.cmdState.pop();
|
22
|
+
plug.closeBracket();
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
function applyMostPowerful(state) {
|
27
|
+
var context = state.cmdState;
|
28
|
+
for (var i = context.length - 1; i >= 0; i--) {
|
29
|
+
var plug = context[i];
|
30
|
+
if (plug.name=="DEFAULT")
|
31
|
+
continue;
|
32
|
+
return plug.styleIdentifier();
|
33
|
+
}
|
34
|
+
return null;
|
35
|
+
}
|
36
|
+
|
37
|
+
function addPluginPattern(pluginName, cmdStyle, brackets, styles) {
|
38
|
+
return function () {
|
39
|
+
this.name=pluginName;
|
40
|
+
this.bracketNo = 0;
|
41
|
+
this.style=cmdStyle;
|
42
|
+
this.styles = styles;
|
43
|
+
this.brackets = brackets;
|
44
|
+
|
45
|
+
this.styleIdentifier = function(content) {
|
46
|
+
if (this.bracketNo<=this.styles.length)
|
47
|
+
return this.styles[this.bracketNo-1];
|
48
|
+
else
|
49
|
+
return null;
|
50
|
+
};
|
51
|
+
this.openBracket = function(content) {
|
52
|
+
this.bracketNo++;
|
53
|
+
return "bracket";
|
54
|
+
};
|
55
|
+
this.closeBracket = function(content) {
|
56
|
+
};
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
var plugins = new Array();
|
61
|
+
|
62
|
+
plugins["importmodule"] = addPluginPattern("importmodule", "tag", "{[", ["string", "builtin"]);
|
63
|
+
plugins["documentclass"] = addPluginPattern("documentclass", "tag", "{[", ["", "atom"]);
|
64
|
+
plugins["usepackage"] = addPluginPattern("documentclass", "tag", "[", ["atom"]);
|
65
|
+
plugins["begin"] = addPluginPattern("documentclass", "tag", "[", ["atom"]);
|
66
|
+
plugins["end"] = addPluginPattern("documentclass", "tag", "[", ["atom"]);
|
67
|
+
|
68
|
+
plugins["DEFAULT"] = function () {
|
69
|
+
this.name="DEFAULT";
|
70
|
+
this.style="tag";
|
71
|
+
|
72
|
+
this.styleIdentifier = function(content) {
|
73
|
+
};
|
74
|
+
this.openBracket = function(content) {
|
75
|
+
};
|
76
|
+
this.closeBracket = function(content) {
|
77
|
+
};
|
78
|
+
};
|
79
|
+
|
80
|
+
function setState(state, f) {
|
81
|
+
state.f = f;
|
82
|
+
}
|
83
|
+
|
84
|
+
function normal(source, state) {
|
85
|
+
if (source.match(/^\\[a-z]+/)) {
|
86
|
+
var cmdName = source.current();
|
87
|
+
cmdName = cmdName.substr(1, cmdName.length-1);
|
88
|
+
var plug = plugins[cmdName];
|
89
|
+
if (typeof(plug) == 'undefined') {
|
90
|
+
plug = plugins["DEFAULT"];
|
91
|
+
}
|
92
|
+
plug = new plug();
|
93
|
+
pushCommand(state, plug);
|
94
|
+
setState(state, beginParams);
|
95
|
+
return plug.style;
|
96
|
+
}
|
97
|
+
|
98
|
+
var ch = source.next();
|
99
|
+
if (ch == "%") {
|
100
|
+
setState(state, inCComment);
|
101
|
+
return "comment";
|
102
|
+
}
|
103
|
+
else if (ch=='}' || ch==']') {
|
104
|
+
plug = peekCommand(state);
|
105
|
+
if (plug) {
|
106
|
+
plug.closeBracket(ch);
|
107
|
+
setState(state, beginParams);
|
108
|
+
} else
|
109
|
+
return "error";
|
110
|
+
return "bracket";
|
111
|
+
} else if (ch=='{' || ch=='[') {
|
112
|
+
plug = plugins["DEFAULT"];
|
113
|
+
plug = new plug();
|
114
|
+
pushCommand(state, plug);
|
115
|
+
return "bracket";
|
116
|
+
}
|
117
|
+
else if (/\d/.test(ch)) {
|
118
|
+
source.eatWhile(/[\w.%]/);
|
119
|
+
return "atom";
|
120
|
+
}
|
121
|
+
else {
|
122
|
+
source.eatWhile(/[\w-_]/);
|
123
|
+
return applyMostPowerful(state);
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
function inCComment(source, state) {
|
128
|
+
source.skipToEnd();
|
129
|
+
setState(state, normal);
|
130
|
+
return "comment";
|
131
|
+
}
|
132
|
+
|
133
|
+
function beginParams(source, state) {
|
134
|
+
var ch = source.peek();
|
135
|
+
if (ch == '{' || ch == '[') {
|
136
|
+
var lastPlug = peekCommand(state);
|
137
|
+
var style = lastPlug.openBracket(ch);
|
138
|
+
source.eat(ch);
|
139
|
+
setState(state, normal);
|
140
|
+
return "bracket";
|
141
|
+
}
|
142
|
+
if (/[ \t\r]/.test(ch)) {
|
143
|
+
source.eat(ch);
|
144
|
+
return null;
|
145
|
+
}
|
146
|
+
setState(state, normal);
|
147
|
+
lastPlug = peekCommand(state);
|
148
|
+
if (lastPlug) {
|
149
|
+
popCommand(state);
|
150
|
+
}
|
151
|
+
return normal(source, state);
|
152
|
+
}
|
153
|
+
|
154
|
+
return {
|
155
|
+
startState: function() { return { f:normal, cmdState:[] }; },
|
156
|
+
copyState: function(s) { return { f: s.f, cmdState: s.cmdState.slice(0, s.cmdState.length) }; },
|
157
|
+
|
158
|
+
token: function(stream, state) {
|
159
|
+
var t = state.f(stream, state);
|
160
|
+
var w = stream.current();
|
161
|
+
return t;
|
162
|
+
}
|
163
|
+
};
|
164
|
+
});
|
165
|
+
|
166
|
+
|
167
|
+
CodeMirror.defineMIME("text/x-stex", "stex");
|
@@ -0,0 +1,42 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>CodeMirror 2: XML mode</title>
|
5
|
+
<link rel="stylesheet" href="../../lib/codemirror.css">
|
6
|
+
<script src="../../lib/codemirror.js"></script>
|
7
|
+
<script src="xml.js"></script>
|
8
|
+
<link rel="stylesheet" href="../../theme/default.css">
|
9
|
+
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
10
|
+
<link rel="stylesheet" href="../../css/docs.css">
|
11
|
+
</head>
|
12
|
+
<body>
|
13
|
+
<h1>CodeMirror 2: XML mode</h1>
|
14
|
+
<form><textarea id="code" name="code">
|
15
|
+
<html style="color: green">
|
16
|
+
<!-- this is a comment -->
|
17
|
+
<head>
|
18
|
+
<title>HTML Example</title>
|
19
|
+
</head>
|
20
|
+
<body>
|
21
|
+
The indentation tries to be <em>somewhat &quot;do what
|
22
|
+
I mean&quot;</em>... but might not match your style.
|
23
|
+
</body>
|
24
|
+
</html>
|
25
|
+
</textarea></form>
|
26
|
+
<script>
|
27
|
+
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {mode: {name: "xml", htmlMode: true}});
|
28
|
+
</script>
|
29
|
+
<p>The XML mode supports two configuration parameters:</p>
|
30
|
+
<dl>
|
31
|
+
<dt><code>htmlMode (boolean)</code></dt>
|
32
|
+
<dd>This switches the mode to parse HTML instead of XML. This
|
33
|
+
means attributes do not have to be quoted, and some elements
|
34
|
+
(such as <code>br</code>) do not require a closing tag.</dd>
|
35
|
+
<dt><code>alignCDATA (boolean)</code></dt>
|
36
|
+
<dd>Setting this to true will force the opening tag of CDATA
|
37
|
+
blocks to not be indented.</dd>
|
38
|
+
</dl>
|
39
|
+
|
40
|
+
<p><strong>MIME types defined:</strong> <code>application/xml</code>, <code>text/html</code>.</p>
|
41
|
+
</body>
|
42
|
+
</html>
|
@@ -0,0 +1,231 @@
|
|
1
|
+
CodeMirror.defineMode("xml", function(config, parserConfig) {
|
2
|
+
var indentUnit = config.indentUnit;
|
3
|
+
var Kludges = parserConfig.htmlMode ? {
|
4
|
+
autoSelfClosers: {"br": true, "img": true, "hr": true, "link": true, "input": true,
|
5
|
+
"meta": true, "col": true, "frame": true, "base": true, "area": true},
|
6
|
+
doNotIndent: {"pre": true, "!cdata": true},
|
7
|
+
allowUnquoted: true
|
8
|
+
} : {autoSelfClosers: {}, doNotIndent: {"!cdata": true}, allowUnquoted: false};
|
9
|
+
var alignCDATA = parserConfig.alignCDATA;
|
10
|
+
|
11
|
+
// Return variables for tokenizers
|
12
|
+
var tagName, type;
|
13
|
+
|
14
|
+
function inText(stream, state) {
|
15
|
+
function chain(parser) {
|
16
|
+
state.tokenize = parser;
|
17
|
+
return parser(stream, state);
|
18
|
+
}
|
19
|
+
|
20
|
+
var ch = stream.next();
|
21
|
+
if (ch == "<") {
|
22
|
+
if (stream.eat("!")) {
|
23
|
+
if (stream.eat("[")) {
|
24
|
+
if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>"));
|
25
|
+
else return null;
|
26
|
+
}
|
27
|
+
else if (stream.match("--")) return chain(inBlock("comment", "-->"));
|
28
|
+
else if (stream.match("DOCTYPE", true, true)) {
|
29
|
+
stream.eatWhile(/[\w\._\-]/);
|
30
|
+
return chain(inBlock("meta", ">"));
|
31
|
+
}
|
32
|
+
else return null;
|
33
|
+
}
|
34
|
+
else if (stream.eat("?")) {
|
35
|
+
stream.eatWhile(/[\w\._\-]/);
|
36
|
+
state.tokenize = inBlock("meta", "?>");
|
37
|
+
return "meta";
|
38
|
+
}
|
39
|
+
else {
|
40
|
+
type = stream.eat("/") ? "closeTag" : "openTag";
|
41
|
+
stream.eatSpace();
|
42
|
+
tagName = "";
|
43
|
+
var c;
|
44
|
+
while ((c = stream.eat(/[^\s\u00a0=<>\"\'\/?]/))) tagName += c;
|
45
|
+
state.tokenize = inTag;
|
46
|
+
return "tag";
|
47
|
+
}
|
48
|
+
}
|
49
|
+
else if (ch == "&") {
|
50
|
+
stream.eatWhile(/[^;]/);
|
51
|
+
stream.eat(";");
|
52
|
+
return "atom";
|
53
|
+
}
|
54
|
+
else {
|
55
|
+
stream.eatWhile(/[^&<]/);
|
56
|
+
return null;
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
function inTag(stream, state) {
|
61
|
+
var ch = stream.next();
|
62
|
+
if (ch == ">" || (ch == "/" && stream.eat(">"))) {
|
63
|
+
state.tokenize = inText;
|
64
|
+
type = ch == ">" ? "endTag" : "selfcloseTag";
|
65
|
+
return "tag";
|
66
|
+
}
|
67
|
+
else if (ch == "=") {
|
68
|
+
type = "equals";
|
69
|
+
return null;
|
70
|
+
}
|
71
|
+
else if (/[\'\"]/.test(ch)) {
|
72
|
+
state.tokenize = inAttribute(ch);
|
73
|
+
return state.tokenize(stream, state);
|
74
|
+
}
|
75
|
+
else {
|
76
|
+
stream.eatWhile(/[^\s\u00a0=<>\"\'\/?]/);
|
77
|
+
return "word";
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
function inAttribute(quote) {
|
82
|
+
return function(stream, state) {
|
83
|
+
while (!stream.eol()) {
|
84
|
+
if (stream.next() == quote) {
|
85
|
+
state.tokenize = inTag;
|
86
|
+
break;
|
87
|
+
}
|
88
|
+
}
|
89
|
+
return "string";
|
90
|
+
};
|
91
|
+
}
|
92
|
+
|
93
|
+
function inBlock(style, terminator) {
|
94
|
+
return function(stream, state) {
|
95
|
+
while (!stream.eol()) {
|
96
|
+
if (stream.match(terminator)) {
|
97
|
+
state.tokenize = inText;
|
98
|
+
break;
|
99
|
+
}
|
100
|
+
stream.next();
|
101
|
+
}
|
102
|
+
return style;
|
103
|
+
};
|
104
|
+
}
|
105
|
+
|
106
|
+
var curState, setStyle;
|
107
|
+
function pass() {
|
108
|
+
for (var i = arguments.length - 1; i >= 0; i--) curState.cc.push(arguments[i]);
|
109
|
+
}
|
110
|
+
function cont() {
|
111
|
+
pass.apply(null, arguments);
|
112
|
+
return true;
|
113
|
+
}
|
114
|
+
|
115
|
+
function pushContext(tagName, startOfLine) {
|
116
|
+
var noIndent = Kludges.doNotIndent.hasOwnProperty(tagName) || (curState.context && curState.context.noIndent);
|
117
|
+
curState.context = {
|
118
|
+
prev: curState.context,
|
119
|
+
tagName: tagName,
|
120
|
+
indent: curState.indented,
|
121
|
+
startOfLine: startOfLine,
|
122
|
+
noIndent: noIndent
|
123
|
+
};
|
124
|
+
}
|
125
|
+
function popContext() {
|
126
|
+
if (curState.context) curState.context = curState.context.prev;
|
127
|
+
}
|
128
|
+
|
129
|
+
function element(type) {
|
130
|
+
if (type == "openTag") {curState.tagName = tagName; return cont(attributes, endtag(curState.startOfLine));}
|
131
|
+
else if (type == "closeTag") {
|
132
|
+
var err = false;
|
133
|
+
if (curState.context) {
|
134
|
+
err = curState.context.tagName != tagName;
|
135
|
+
popContext();
|
136
|
+
} else {
|
137
|
+
err = true;
|
138
|
+
}
|
139
|
+
if (err) setStyle = "error";
|
140
|
+
return cont(endclosetag(err));
|
141
|
+
}
|
142
|
+
else if (type == "string") {
|
143
|
+
if (!curState.context || curState.context.name != "!cdata") pushContext("!cdata");
|
144
|
+
if (curState.tokenize == inText) popContext();
|
145
|
+
return cont();
|
146
|
+
}
|
147
|
+
else return cont();
|
148
|
+
}
|
149
|
+
function endtag(startOfLine) {
|
150
|
+
return function(type) {
|
151
|
+
if (type == "selfcloseTag" ||
|
152
|
+
(type == "endTag" && Kludges.autoSelfClosers.hasOwnProperty(curState.tagName.toLowerCase())))
|
153
|
+
return cont();
|
154
|
+
if (type == "endTag") {pushContext(curState.tagName, startOfLine); return cont();}
|
155
|
+
return cont();
|
156
|
+
};
|
157
|
+
}
|
158
|
+
function endclosetag(err) {
|
159
|
+
return function(type) {
|
160
|
+
if (err) setStyle = "error";
|
161
|
+
if (type == "endTag") return cont();
|
162
|
+
return pass();
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
function attributes(type) {
|
167
|
+
if (type == "word") {setStyle = "attribute"; return cont(attributes);}
|
168
|
+
if (type == "equals") return cont(attvalue, attributes);
|
169
|
+
return pass();
|
170
|
+
}
|
171
|
+
function attvalue(type) {
|
172
|
+
if (type == "word" && Kludges.allowUnquoted) {setStyle = "string"; return cont();}
|
173
|
+
if (type == "string") return cont(attvaluemaybe);
|
174
|
+
return pass();
|
175
|
+
}
|
176
|
+
function attvaluemaybe(type) {
|
177
|
+
if (type == "string") return cont(attvaluemaybe);
|
178
|
+
else return pass();
|
179
|
+
}
|
180
|
+
|
181
|
+
return {
|
182
|
+
startState: function() {
|
183
|
+
return {tokenize: inText, cc: [], indented: 0, startOfLine: true, tagName: null, context: null};
|
184
|
+
},
|
185
|
+
|
186
|
+
token: function(stream, state) {
|
187
|
+
if (stream.sol()) {
|
188
|
+
state.startOfLine = true;
|
189
|
+
state.indented = stream.indentation();
|
190
|
+
}
|
191
|
+
if (stream.eatSpace()) return null;
|
192
|
+
|
193
|
+
setStyle = type = tagName = null;
|
194
|
+
var style = state.tokenize(stream, state);
|
195
|
+
if ((style || type) && style != "comment") {
|
196
|
+
curState = state;
|
197
|
+
while (true) {
|
198
|
+
var comb = state.cc.pop() || element;
|
199
|
+
if (comb(type || style)) break;
|
200
|
+
}
|
201
|
+
}
|
202
|
+
state.startOfLine = false;
|
203
|
+
return setStyle || style;
|
204
|
+
},
|
205
|
+
|
206
|
+
indent: function(state, textAfter) {
|
207
|
+
var context = state.context;
|
208
|
+
if (context && context.noIndent) return 0;
|
209
|
+
if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
|
210
|
+
if (context && /^<\//.test(textAfter))
|
211
|
+
context = context.prev;
|
212
|
+
while (context && !context.startOfLine)
|
213
|
+
context = context.prev;
|
214
|
+
if (context) return context.indent + indentUnit;
|
215
|
+
else return 0;
|
216
|
+
},
|
217
|
+
|
218
|
+
compareStates: function(a, b) {
|
219
|
+
if (a.indented != b.indented || a.tagName != b.tagName) return false;
|
220
|
+
for (var ca = a.context, cb = b.context; ; ca = ca.prev, cb = cb.prev) {
|
221
|
+
if (!ca || !cb) return ca == cb;
|
222
|
+
if (ca.tagName != cb.tagName) return false;
|
223
|
+
}
|
224
|
+
},
|
225
|
+
|
226
|
+
electricChars: "/"
|
227
|
+
};
|
228
|
+
});
|
229
|
+
|
230
|
+
CodeMirror.defineMIME("application/xml", "xml");
|
231
|
+
CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});
|