mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-31 15:18:38 -04:00
First commit, version 0.2.7
This commit is contained in:
parent
61eb11d23c
commit
4b0ca55eb7
1379 changed files with 173000 additions and 0 deletions
218
public/vendor/codemirror/mode/d/d.js
vendored
Executable file
218
public/vendor/codemirror/mode/d/d.js
vendored
Executable file
|
@ -0,0 +1,218 @@
|
|||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
(function(mod) {
|
||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||
mod(require("../../lib/codemirror"));
|
||||
else if (typeof define == "function" && define.amd) // AMD
|
||||
define(["../../lib/codemirror"], mod);
|
||||
else // Plain browser env
|
||||
mod(CodeMirror);
|
||||
})(function(CodeMirror) {
|
||||
"use strict";
|
||||
|
||||
CodeMirror.defineMode("d", function(config, parserConfig) {
|
||||
var indentUnit = config.indentUnit,
|
||||
statementIndentUnit = parserConfig.statementIndentUnit || indentUnit,
|
||||
keywords = parserConfig.keywords || {},
|
||||
builtin = parserConfig.builtin || {},
|
||||
blockKeywords = parserConfig.blockKeywords || {},
|
||||
atoms = parserConfig.atoms || {},
|
||||
hooks = parserConfig.hooks || {},
|
||||
multiLineStrings = parserConfig.multiLineStrings;
|
||||
var isOperatorChar = /[+\-*&%=<>!?|\/]/;
|
||||
|
||||
var curPunc;
|
||||
|
||||
function tokenBase(stream, state) {
|
||||
var ch = stream.next();
|
||||
if (hooks[ch]) {
|
||||
var result = hooks[ch](stream, state);
|
||||
if (result !== false) return result;
|
||||
}
|
||||
if (ch == '"' || ch == "'" || ch == "`") {
|
||||
state.tokenize = tokenString(ch);
|
||||
return state.tokenize(stream, state);
|
||||
}
|
||||
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
|
||||
curPunc = ch;
|
||||
return null;
|
||||
}
|
||||
if (/\d/.test(ch)) {
|
||||
stream.eatWhile(/[\w\.]/);
|
||||
return "number";
|
||||
}
|
||||
if (ch == "/") {
|
||||
if (stream.eat("+")) {
|
||||
state.tokenize = tokenComment;
|
||||
return tokenNestedComment(stream, state);
|
||||
}
|
||||
if (stream.eat("*")) {
|
||||
state.tokenize = tokenComment;
|
||||
return tokenComment(stream, state);
|
||||
}
|
||||
if (stream.eat("/")) {
|
||||
stream.skipToEnd();
|
||||
return "comment";
|
||||
}
|
||||
}
|
||||
if (isOperatorChar.test(ch)) {
|
||||
stream.eatWhile(isOperatorChar);
|
||||
return "operator";
|
||||
}
|
||||
stream.eatWhile(/[\w\$_\xa1-\uffff]/);
|
||||
var cur = stream.current();
|
||||
if (keywords.propertyIsEnumerable(cur)) {
|
||||
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
|
||||
return "keyword";
|
||||
}
|
||||
if (builtin.propertyIsEnumerable(cur)) {
|
||||
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
|
||||
return "builtin";
|
||||
}
|
||||
if (atoms.propertyIsEnumerable(cur)) return "atom";
|
||||
return "variable";
|
||||
}
|
||||
|
||||
function tokenString(quote) {
|
||||
return function(stream, state) {
|
||||
var escaped = false, next, end = false;
|
||||
while ((next = stream.next()) != null) {
|
||||
if (next == quote && !escaped) {end = true; break;}
|
||||
escaped = !escaped && next == "\\";
|
||||
}
|
||||
if (end || !(escaped || multiLineStrings))
|
||||
state.tokenize = null;
|
||||
return "string";
|
||||
};
|
||||
}
|
||||
|
||||
function tokenComment(stream, state) {
|
||||
var maybeEnd = false, ch;
|
||||
while (ch = stream.next()) {
|
||||
if (ch == "/" && maybeEnd) {
|
||||
state.tokenize = null;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (ch == "*");
|
||||
}
|
||||
return "comment";
|
||||
}
|
||||
|
||||
function tokenNestedComment(stream, state) {
|
||||
var maybeEnd = false, ch;
|
||||
while (ch = stream.next()) {
|
||||
if (ch == "/" && maybeEnd) {
|
||||
state.tokenize = null;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (ch == "+");
|
||||
}
|
||||
return "comment";
|
||||
}
|
||||
|
||||
function Context(indented, column, type, align, prev) {
|
||||
this.indented = indented;
|
||||
this.column = column;
|
||||
this.type = type;
|
||||
this.align = align;
|
||||
this.prev = prev;
|
||||
}
|
||||
function pushContext(state, col, type) {
|
||||
var indent = state.indented;
|
||||
if (state.context && state.context.type == "statement")
|
||||
indent = state.context.indented;
|
||||
return state.context = new Context(indent, col, type, null, state.context);
|
||||
}
|
||||
function popContext(state) {
|
||||
var t = state.context.type;
|
||||
if (t == ")" || t == "]" || t == "}")
|
||||
state.indented = state.context.indented;
|
||||
return state.context = state.context.prev;
|
||||
}
|
||||
|
||||
// Interface
|
||||
|
||||
return {
|
||||
startState: function(basecolumn) {
|
||||
return {
|
||||
tokenize: null,
|
||||
context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
|
||||
indented: 0,
|
||||
startOfLine: true
|
||||
};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
var ctx = state.context;
|
||||
if (stream.sol()) {
|
||||
if (ctx.align == null) ctx.align = false;
|
||||
state.indented = stream.indentation();
|
||||
state.startOfLine = true;
|
||||
}
|
||||
if (stream.eatSpace()) return null;
|
||||
curPunc = null;
|
||||
var style = (state.tokenize || tokenBase)(stream, state);
|
||||
if (style == "comment" || style == "meta") return style;
|
||||
if (ctx.align == null) ctx.align = true;
|
||||
|
||||
if ((curPunc == ";" || curPunc == ":" || curPunc == ",") && ctx.type == "statement") popContext(state);
|
||||
else if (curPunc == "{") pushContext(state, stream.column(), "}");
|
||||
else if (curPunc == "[") pushContext(state, stream.column(), "]");
|
||||
else if (curPunc == "(") pushContext(state, stream.column(), ")");
|
||||
else if (curPunc == "}") {
|
||||
while (ctx.type == "statement") ctx = popContext(state);
|
||||
if (ctx.type == "}") ctx = popContext(state);
|
||||
while (ctx.type == "statement") ctx = popContext(state);
|
||||
}
|
||||
else if (curPunc == ctx.type) popContext(state);
|
||||
else if (((ctx.type == "}" || ctx.type == "top") && curPunc != ';') || (ctx.type == "statement" && curPunc == "newstatement"))
|
||||
pushContext(state, stream.column(), "statement");
|
||||
state.startOfLine = false;
|
||||
return style;
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
if (state.tokenize != tokenBase && state.tokenize != null) return CodeMirror.Pass;
|
||||
var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
|
||||
if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
|
||||
var closing = firstChar == ctx.type;
|
||||
if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit);
|
||||
else if (ctx.align) return ctx.column + (closing ? 0 : 1);
|
||||
else return ctx.indented + (closing ? 0 : indentUnit);
|
||||
},
|
||||
|
||||
electricChars: "{}"
|
||||
};
|
||||
});
|
||||
|
||||
function words(str) {
|
||||
var obj = {}, words = str.split(" ");
|
||||
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
||||
return obj;
|
||||
}
|
||||
|
||||
var blockKeywords = "body catch class do else enum for foreach foreach_reverse if in interface mixin " +
|
||||
"out scope struct switch try union unittest version while with";
|
||||
|
||||
CodeMirror.defineMIME("text/x-d", {
|
||||
name: "d",
|
||||
keywords: words("abstract alias align asm assert auto break case cast cdouble cent cfloat const continue " +
|
||||
"debug default delegate delete deprecated export extern final finally function goto immutable " +
|
||||
"import inout invariant is lazy macro module new nothrow override package pragma private " +
|
||||
"protected public pure ref return shared short static super synchronized template this " +
|
||||
"throw typedef typeid typeof volatile __FILE__ __LINE__ __gshared __traits __vector __parameters " +
|
||||
blockKeywords),
|
||||
blockKeywords: words(blockKeywords),
|
||||
builtin: words("bool byte char creal dchar double float idouble ifloat int ireal long real short ubyte " +
|
||||
"ucent uint ulong ushort wchar wstring void size_t sizediff_t"),
|
||||
atoms: words("exit failure success true false null"),
|
||||
hooks: {
|
||||
"@": function(stream, _state) {
|
||||
stream.eatWhile(/[\w\$_]/);
|
||||
return "meta";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
273
public/vendor/codemirror/mode/d/index.html
vendored
Executable file
273
public/vendor/codemirror/mode/d/index.html
vendored
Executable file
|
@ -0,0 +1,273 @@
|
|||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: D mode</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="../../addon/edit/matchbrackets.js"></script>
|
||||
<script src="d.js"></script>
|
||||
<style>.CodeMirror {border: 2px inset #dee;}</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../../index.html">Home</a>
|
||||
<li><a href="../../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/codemirror/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a href="../index.html">Language modes</a>
|
||||
<li><a class=active href="#">D</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>D mode</h2>
|
||||
<form><textarea id="code" name="code">
|
||||
/* D demo code // copied from phobos/sd/metastrings.d */
|
||||
// Written in the D programming language.
|
||||
|
||||
/**
|
||||
Templates with which to do compile-time manipulation of strings.
|
||||
|
||||
Macros:
|
||||
WIKI = Phobos/StdMetastrings
|
||||
|
||||
Copyright: Copyright Digital Mars 2007 - 2009.
|
||||
License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
|
||||
Authors: $(WEB digitalmars.com, Walter Bright),
|
||||
Don Clugston
|
||||
Source: $(PHOBOSSRC std/_metastrings.d)
|
||||
*/
|
||||
/*
|
||||
Copyright Digital Mars 2007 - 2009.
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
module std.metastrings;
|
||||
|
||||
/**
|
||||
Formats constants into a string at compile time. Analogous to $(XREF
|
||||
string,format).
|
||||
|
||||
Parameters:
|
||||
|
||||
A = tuple of constants, which can be strings, characters, or integral
|
||||
values.
|
||||
|
||||
Formats:
|
||||
* The formats supported are %s for strings, and %%
|
||||
* for the % character.
|
||||
Example:
|
||||
---
|
||||
import std.metastrings;
|
||||
import std.stdio;
|
||||
|
||||
void main()
|
||||
{
|
||||
string s = Format!("Arg %s = %s", "foo", 27);
|
||||
writefln(s); // "Arg foo = 27"
|
||||
}
|
||||
* ---
|
||||
*/
|
||||
|
||||
template Format(A...)
|
||||
{
|
||||
static if (A.length == 0)
|
||||
enum Format = "";
|
||||
else static if (is(typeof(A[0]) : const(char)[]))
|
||||
enum Format = FormatString!(A[0], A[1..$]);
|
||||
else
|
||||
enum Format = toStringNow!(A[0]) ~ Format!(A[1..$]);
|
||||
}
|
||||
|
||||
template FormatString(const(char)[] F, A...)
|
||||
{
|
||||
static if (F.length == 0)
|
||||
enum FormatString = Format!(A);
|
||||
else static if (F.length == 1)
|
||||
enum FormatString = F[0] ~ Format!(A);
|
||||
else static if (F[0..2] == "%s")
|
||||
enum FormatString
|
||||
= toStringNow!(A[0]) ~ FormatString!(F[2..$],A[1..$]);
|
||||
else static if (F[0..2] == "%%")
|
||||
enum FormatString = "%" ~ FormatString!(F[2..$],A);
|
||||
else
|
||||
{
|
||||
static assert(F[0] != '%', "unrecognized format %" ~ F[1]);
|
||||
enum FormatString = F[0] ~ FormatString!(F[1..$],A);
|
||||
}
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
auto s = Format!("hel%slo", "world", -138, 'c', true);
|
||||
assert(s == "helworldlo-138ctrue", "[" ~ s ~ "]");
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert constant argument to a string.
|
||||
*/
|
||||
|
||||
template toStringNow(ulong v)
|
||||
{
|
||||
static if (v < 10)
|
||||
enum toStringNow = "" ~ cast(char)(v + '0');
|
||||
else
|
||||
enum toStringNow = toStringNow!(v / 10) ~ toStringNow!(v % 10);
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
static assert(toStringNow!(1uL << 62) == "4611686018427387904");
|
||||
}
|
||||
|
||||
/// ditto
|
||||
template toStringNow(long v)
|
||||
{
|
||||
static if (v < 0)
|
||||
enum toStringNow = "-" ~ toStringNow!(cast(ulong) -v);
|
||||
else
|
||||
enum toStringNow = toStringNow!(cast(ulong) v);
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
static assert(toStringNow!(0x100000000) == "4294967296");
|
||||
static assert(toStringNow!(-138L) == "-138");
|
||||
}
|
||||
|
||||
/// ditto
|
||||
template toStringNow(uint U)
|
||||
{
|
||||
enum toStringNow = toStringNow!(cast(ulong)U);
|
||||
}
|
||||
|
||||
/// ditto
|
||||
template toStringNow(int I)
|
||||
{
|
||||
enum toStringNow = toStringNow!(cast(long)I);
|
||||
}
|
||||
|
||||
/// ditto
|
||||
template toStringNow(bool B)
|
||||
{
|
||||
enum toStringNow = B ? "true" : "false";
|
||||
}
|
||||
|
||||
/// ditto
|
||||
template toStringNow(string S)
|
||||
{
|
||||
enum toStringNow = S;
|
||||
}
|
||||
|
||||
/// ditto
|
||||
template toStringNow(char C)
|
||||
{
|
||||
enum toStringNow = "" ~ C;
|
||||
}
|
||||
|
||||
|
||||
/********
|
||||
* Parse unsigned integer literal from the start of string s.
|
||||
* returns:
|
||||
* .value = the integer literal as a string,
|
||||
* .rest = the string following the integer literal
|
||||
* Otherwise:
|
||||
* .value = null,
|
||||
* .rest = s
|
||||
*/
|
||||
|
||||
template parseUinteger(const(char)[] s)
|
||||
{
|
||||
static if (s.length == 0)
|
||||
{
|
||||
enum value = "";
|
||||
enum rest = "";
|
||||
}
|
||||
else static if (s[0] >= '0' && s[0] <= '9')
|
||||
{
|
||||
enum value = s[0] ~ parseUinteger!(s[1..$]).value;
|
||||
enum rest = parseUinteger!(s[1..$]).rest;
|
||||
}
|
||||
else
|
||||
{
|
||||
enum value = "";
|
||||
enum rest = s;
|
||||
}
|
||||
}
|
||||
|
||||
/********
|
||||
Parse integer literal optionally preceded by $(D '-') from the start
|
||||
of string $(D s).
|
||||
|
||||
Returns:
|
||||
.value = the integer literal as a string,
|
||||
.rest = the string following the integer literal
|
||||
|
||||
Otherwise:
|
||||
.value = null,
|
||||
.rest = s
|
||||
*/
|
||||
|
||||
template parseInteger(const(char)[] s)
|
||||
{
|
||||
static if (s.length == 0)
|
||||
{
|
||||
enum value = "";
|
||||
enum rest = "";
|
||||
}
|
||||
else static if (s[0] >= '0' && s[0] <= '9')
|
||||
{
|
||||
enum value = s[0] ~ parseUinteger!(s[1..$]).value;
|
||||
enum rest = parseUinteger!(s[1..$]).rest;
|
||||
}
|
||||
else static if (s.length >= 2 &&
|
||||
s[0] == '-' && s[1] >= '0' && s[1] <= '9')
|
||||
{
|
||||
enum value = s[0..2] ~ parseUinteger!(s[2..$]).value;
|
||||
enum rest = parseUinteger!(s[2..$]).rest;
|
||||
}
|
||||
else
|
||||
{
|
||||
enum value = "";
|
||||
enum rest = s;
|
||||
}
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
assert(parseUinteger!("1234abc").value == "1234");
|
||||
assert(parseUinteger!("1234abc").rest == "abc");
|
||||
assert(parseInteger!("-1234abc").value == "-1234");
|
||||
assert(parseInteger!("-1234abc").rest == "abc");
|
||||
}
|
||||
|
||||
/**
|
||||
Deprecated aliases held for backward compatibility.
|
||||
*/
|
||||
deprecated alias toStringNow ToString;
|
||||
/// Ditto
|
||||
deprecated alias parseUinteger ParseUinteger;
|
||||
/// Ditto
|
||||
deprecated alias parseUinteger ParseInteger;
|
||||
|
||||
</textarea></form>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
matchBrackets: true,
|
||||
indentUnit: 4,
|
||||
mode: "text/x-d"
|
||||
});
|
||||
</script>
|
||||
|
||||
<p>Simple mode that handle D-Syntax (<a href="http://www.dlang.org">DLang Homepage</a>).</p>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-d</code>
|
||||
.</p>
|
||||
</article>
|
Loading…
Add table
Add a link
Reference in a new issue