From b89a7ee8b956c96a1dcee995ea840feddc5d4b27 Mon Sep 17 00:00:00 2001 From: Pierre Frisch Date: Thu, 22 Dec 2011 07:25:50 -0800 Subject: First commit of Ninja to ninja-internal Signed-off-by: Valerio Virgillito --- js/codemirror/mode/rst/index.html | 526 ++++++++++++++++++++++++++++++++++++++ js/codemirror/mode/rst/rst.css | 75 ++++++ js/codemirror/mode/rst/rst.js | 333 ++++++++++++++++++++++++ 3 files changed, 934 insertions(+) create mode 100644 js/codemirror/mode/rst/index.html create mode 100644 js/codemirror/mode/rst/rst.css create mode 100644 js/codemirror/mode/rst/rst.js (limited to 'js/codemirror/mode/rst') diff --git a/js/codemirror/mode/rst/index.html b/js/codemirror/mode/rst/index.html new file mode 100644 index 00000000..0831dff4 --- /dev/null +++ b/js/codemirror/mode/rst/index.html @@ -0,0 +1,526 @@ + + + + CodeMirror 2: reStructuredText mode + + + + + + + + +

CodeMirror 2: reStructuredText mode

+ +
+ + +

The reStructuredText mode supports one configuration parameter:

+
+
verbatim (string)
+
A name or MIME type of a mode that will be used for highlighting + verbatim blocks. By default, reStructuredText mode uses uniform color + for whole block of verbatim text if no mode is given.
+
+

If python mode is available (not a part of CodeMirror 2 yet), + it will be used for highlighting blocks containing Python/IPython terminal + sessions (blocks starting with >>> (for Python) or + In [num]: (for IPython). + +

MIME types defined: text/x-rst.

+ + + diff --git a/js/codemirror/mode/rst/rst.css b/js/codemirror/mode/rst/rst.css new file mode 100644 index 00000000..235a5d83 --- /dev/null +++ b/js/codemirror/mode/rst/rst.css @@ -0,0 +1,75 @@ +.cm-s-default span.cm-emphasis { + font-style: italic; +} + +.cm-s-default span.cm-strong { + font-weight: bold; +} + +.cm-s-default span.cm-interpreted { + color: #33cc66; +} + +.cm-s-default span.cm-inline { + color: #3399cc; +} + +.cm-s-default span.cm-role { + color: #666699; +} + +.cm-s-default span.cm-list { + color: #cc0099; + font-weight: bold; +} + +.cm-s-default span.cm-body { + color: #6699cc; +} + +.cm-s-default span.cm-verbatim { + color: #3366ff; +} + +.cm-s-default span.cm-comment { + color: #aa7700; +} + +.cm-s-default span.cm-directive { + font-weight: bold; + color: #3399ff; +} + +.cm-s-default span.cm-hyperlink { + font-weight: bold; + color: #3366ff; +} + +.cm-s-default span.cm-footnote { + font-weight: bold; + color: #3333ff; +} + +.cm-s-default span.cm-citation { + font-weight: bold; + color: #3300ff; +} + +.cm-s-default span.cm-replacement { + color: #9933cc; +} + +.cm-s-default span.cm-section { + font-weight: bold; + color: #cc0099; +} + +.cm-s-default span.cm-directive-marker { + font-weight: bold; + color: #3399ff; +} + +.cm-s-default span.cm-verbatim-marker { + font-weight: bold; + color: #9900ff; +} diff --git a/js/codemirror/mode/rst/rst.js b/js/codemirror/mode/rst/rst.js new file mode 100644 index 00000000..eecc5bea --- /dev/null +++ b/js/codemirror/mode/rst/rst.js @@ -0,0 +1,333 @@ +CodeMirror.defineMode('rst', function(config, options) { + function setState(state, fn, ctx) { + state.fn = fn; + setCtx(state, ctx); + } + + function setCtx(state, ctx) { + state.ctx = ctx || {}; + } + + function setNormal(state, ch) { + if (ch && (typeof ch !== 'string')) { + var str = ch.current(); + ch = str[str.length-1]; + } + + setState(state, normal, {back: ch}); + } + + function hasMode(mode) { + if (mode) { + var modes = CodeMirror.listModes(); + + for (var i in modes) { + if (modes[i] == mode) { + return true; + } + } + } + + return false; + } + + function getMode(mode) { + if (hasMode(mode)) { + return CodeMirror.getMode(config, mode); + } else { + return null; + } + } + + var verbatimMode = getMode(options.verbatim); + var pythonMode = getMode('python'); + + var reSection = /^[!"#$%&'()*+,-./:;<=>?@[\\\]^_`{|}~]/; + var reDirective = /^\s*\w([-:.\w]*\w)?::(\s|$)/; + var reHyperlink = /^\s*_[\w-]+:(\s|$)/; + var reFootnote = /^\s*\[(\d+|#)\](\s|$)/; + var reCitation = /^\s*\[[A-Za-z][\w-]*\](\s|$)/; + var reFootnoteRef = /^\[(\d+|#)\]_/; + var reCitationRef = /^\[[A-Za-z][\w-]*\]_/; + var reDirectiveMarker = /^\.\.(\s|$)/; + var reVerbatimMarker = /^::\s*$/; + var rePreInline = /^[-\s"([{/:.,;!?\\_]/; + var reEnumeratedList = /^\s*((\d+|[A-Za-z#])[.)]|\((\d+|[A-Z-a-z#])\))\s/; + var reBulletedList = /^\s*[-\+\*]\s/; + var reExamples = /^\s+(>>>|In \[\d+\]:)\s/; + + function normal(stream, state) { + var ch, sol, i; + + if (stream.eat(/\\/)) { + ch = stream.next(); + setNormal(state, ch); + return null; + } + + sol = stream.sol(); + + if (sol && (ch = stream.eat(reSection))) { + for (i = 0; stream.eat(ch); i++); + + if (i >= 3 && stream.match(/^\s*$/)) { + setNormal(state, null); + return 'section'; + } else { + stream.backUp(i + 1); + } + } + + if (sol && stream.match(reDirectiveMarker)) { + if (!stream.eol()) { + setState(state, directive); + } + + return 'directive-marker'; + } + + if (stream.match(reVerbatimMarker)) { + if (!verbatimMode) { + setState(state, verbatim); + } else { + var mode = verbatimMode; + + setState(state, verbatim, { + mode: mode, + local: mode.startState() + }); + } + + return 'verbatim-marker'; + } + + if (sol && stream.match(reExamples, false)) { + if (!pythonMode) { + setState(state, verbatim); + return 'verbatim-marker'; + } else { + var mode = pythonMode; + + setState(state, verbatim, { + mode: mode, + local: mode.startState() + }); + + return null; + } + } + + if (sol && (stream.match(reEnumeratedList) || + stream.match(reBulletedList))) { + setNormal(state, stream); + return 'list'; + } + + function testBackward(re) { + return sol || !state.ctx.back || re.test(state.ctx.back); + } + + function testForward(re) { + return stream.eol() || stream.match(re, false); + } + + function testInline(re) { + return stream.match(re) && testBackward(/\W/) && testForward(/\W/); + } + + if (testInline(reFootnoteRef)) { + setNormal(state, stream); + return 'footnote'; + } + + if (testInline(reCitationRef)) { + setNormal(state, stream); + return 'citation'; + } + + ch = stream.next(); + + if (testBackward(rePreInline)) { + if ((ch === ':' || ch === '|') && stream.eat(/\S/)) { + var token; + + if (ch === ':') { + token = 'role'; + } else { + token = 'replacement'; + } + + setState(state, inline, { + ch: ch, + wide: false, + prev: null, + token: token + }); + + return token; + } + + if (ch === '*' || ch === '`') { + var orig = ch, + wide = false; + + ch = stream.next(); + + if (ch == orig) { + wide = true; + ch = stream.next(); + } + + if (ch && !/\s/.test(ch)) { + var token; + + if (orig === '*') { + token = wide ? 'strong' : 'emphasis'; + } else { + token = wide ? 'inline' : 'interpreted'; + } + + setState(state, inline, { + ch: orig, // inline() has to know what to search for + wide: wide, // are we looking for `ch` or `chch` + prev: null, // terminator must not be preceeded with whitespace + token: token // I don't want to recompute this all the time + }); + + return token; + } + } + } + + setNormal(state, ch); + return null; + } + + function inline(stream, state) { + var ch = stream.next(), + token = state.ctx.token; + + function finish(ch) { + state.ctx.prev = ch; + return token; + } + + if (ch != state.ctx.ch) { + return finish(ch); + } + + if (/\s/.test(state.ctx.prev)) { + return finish(ch); + } + + if (state.ctx.wide) { + ch = stream.next(); + + if (ch != state.ctx.ch) { + return finish(ch); + } + } + + if (!stream.eol() && !rePostInline.test(stream.peek())) { + if (state.ctx.wide) { + stream.backUp(1); + } + + return finish(ch); + } + + setState(state, normal); + setNormal(state, ch); + + return token; + } + + function directive(stream, state) { + var token = null; + + if (stream.match(reDirective)) { + token = 'directive'; + } else if (stream.match(reHyperlink)) { + token = 'hyperlink'; + } else if (stream.match(reFootnote)) { + token = 'footnote'; + } else if (stream.match(reCitation)) { + token = 'citation'; + } else { + stream.eatSpace(); + + if (stream.eol()) { + setNormal(state, stream); + return null; + } else { + stream.skipToEnd(); + setState(state, comment); + return 'comment'; + } + } + + setState(state, body, {start: true}); + return token; + } + + function body(stream, state) { + var token = 'body'; + + if (!state.ctx.start || stream.sol()) { + return block(stream, state, token); + } + + stream.skipToEnd(); + setCtx(state); + + return token; + } + + function comment(stream, state) { + return block(stream, state, 'comment'); + } + + function verbatim(stream, state) { + if (!verbatimMode) { + return block(stream, state, 'verbatim'); + } else { + if (stream.sol()) { + if (!stream.eatSpace()) { + setNormal(state, stream); + } + + return null; + } + + return verbatimMode.token(stream, state.ctx.local); + } + } + + function block(stream, state, token) { + if (stream.eol() || stream.eatSpace()) { + stream.skipToEnd(); + return token; + } else { + setNormal(state, stream); + return null; + } + } + + return { + startState: function() { + return {fn: normal, ctx: {}}; + }, + + copyState: function(state) { + return {fn: state.fn, ctx: state.ctx}; + }, + + token: function(stream, state) { + var token = state.fn(stream, state); + return token; + } + }; +}); + +CodeMirror.defineMIME("text/x-rst", "rst"); -- cgit v1.2.3