mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 12:45:39 +01:00
Extract playground samples from mdoc, add possiblity to run them from source
This commit is contained in:
parent
df6136ea12
commit
5b86272f55
103 changed files with 3126 additions and 21 deletions
|
|
@ -0,0 +1 @@
|
|||
<div id="container" style="height:100%;"></div>
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
function createDependencyProposals() {
|
||||
// returning a static list of proposals, not even looking at the prefix (filtering is done by the Monaco editor),
|
||||
// here you could do a server side lookup
|
||||
return [
|
||||
{
|
||||
label: '"lodash"',
|
||||
kind: monaco.languages.CompletionItemKind.Function,
|
||||
documentation: "The Lodash library exported as Node.js modules.",
|
||||
insertText: '"lodash": "*"'
|
||||
},
|
||||
{
|
||||
label: '"express"',
|
||||
kind: monaco.languages.CompletionItemKind.Function,
|
||||
documentation: "Fast, unopinionated, minimalist web framework",
|
||||
insertText: '"express": "*"'
|
||||
},
|
||||
{
|
||||
label: '"mkdirp"',
|
||||
kind: monaco.languages.CompletionItemKind.Function,
|
||||
documentation: "Recursively mkdir, like <code>mkdir -p</code>",
|
||||
insertText: '"mkdirp": "*"'
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
monaco.languages.registerCompletionItemProvider('json', {
|
||||
provideCompletionItems: function(model, position) {
|
||||
// find out if we are completing a property in the 'dependencies' object.
|
||||
var textUntilPosition = model.getValueInRange({startLineNumber: 1, startColumn: 1, endLineNumber: position.lineNumber, endColumn: position.column});
|
||||
var match = textUntilPosition.match(/"dependencies"\s*:\s*{\s*("[^"]*"\s*:\s*"[^"]*"\s*,\s*)*("[^"]*)?$/); if (match) {
|
||||
return createDependencyProposals();
|
||||
}
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
monaco.editor.create(document.getElementById("container"), {
|
||||
value: "{\n\t\"dependencies\": {\n\t\t\n\t}\n}\n",
|
||||
language: "json"
|
||||
});
|
||||
|
|
@ -0,0 +1 @@
|
|||
<div id="container" style="height:100%;"></div>
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
// Add additonal d.ts files to the JavaScript language service and change.
|
||||
// Also change the default compilation options.
|
||||
// The sample below shows how a class Facts is declared and introduced
|
||||
// to the system and how the compiler is told to use ES6 (target=2).
|
||||
|
||||
// validation settings
|
||||
monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({
|
||||
noSemanticValidation: true,
|
||||
noSyntaxValidation: false
|
||||
});
|
||||
|
||||
// compiler options
|
||||
monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
|
||||
target: monaco.languages.typescript.ScriptTarget.ES6,
|
||||
allowNonTsExtensions: true
|
||||
});
|
||||
|
||||
// extra libraries
|
||||
monaco.languages.typescript.javascriptDefaults.addExtraLib([
|
||||
'declare class Facts {',
|
||||
' /**',
|
||||
' * Returns the next fact',
|
||||
' */',
|
||||
' static next():string',
|
||||
'}',
|
||||
].join('\n'), 'filename/facts.d.ts');
|
||||
|
||||
var jsCode = [
|
||||
'"use strict";',
|
||||
'',
|
||||
"class Chuck {",
|
||||
" greet() {",
|
||||
" return Facts.next();",
|
||||
" }",
|
||||
"}"
|
||||
].join('\n');
|
||||
|
||||
monaco.editor.create(document.getElementById("container"), {
|
||||
value: jsCode,
|
||||
language: "javascript"
|
||||
});
|
||||
|
|
@ -0,0 +1 @@
|
|||
<div id="container" style="height:100%;"></div>
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
// Configures two JSON schemas, with references.
|
||||
|
||||
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
|
||||
schemas: [{
|
||||
uri: "http://myserver/foo-schema.json",
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
p1: {
|
||||
enum: [ "v1", "v2"]
|
||||
},
|
||||
p2: {
|
||||
$ref: "http://myserver/bar-schema.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
},{
|
||||
uri: "http://myserver/bar-schema.json",
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
q1: {
|
||||
enum: [ "x1", "x2"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}]
|
||||
});
|
||||
|
||||
|
||||
var jsonCode = [
|
||||
'{',
|
||||
' "$schema": "http://myserver/foo-schema.json"',
|
||||
"}"
|
||||
].join('\n');
|
||||
|
||||
monaco.editor.create(document.getElementById("container"), {
|
||||
value: jsonCode,
|
||||
language: "json"
|
||||
});
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
.monaco-editor .token.custom-info {
|
||||
color: grey;
|
||||
}
|
||||
.monaco-editor .token.custom-error {
|
||||
color: red;
|
||||
font-weight: bold;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
.monaco-editor .token.custom-notice {
|
||||
color: orange;
|
||||
}
|
||||
|
||||
.monaco-editor .token.custom-date {
|
||||
color: green;
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
<div id="container" style="height:100%;"></div>
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
monaco.languages.register({ id: 'mySpecialLanguage' });
|
||||
|
||||
monaco.languages.setMonarchTokensProvider('mySpecialLanguage', {
|
||||
tokenizer: {
|
||||
root: [
|
||||
[/\[error.*/, "custom-error"],
|
||||
[/\[notice.*/, "custom-notice"],
|
||||
[/\[info.*/, "custom-info"],
|
||||
[/\[[a-zA-Z 0-9:]+\]/, "custom-date"],
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
monaco.languages.registerCompletionItemProvider('mySpecialLanguage', {
|
||||
provideCompletionItems: () => {
|
||||
return [
|
||||
{
|
||||
label: 'simpleText',
|
||||
kind: monaco.languages.CompletionItemKind.Text
|
||||
}, {
|
||||
label: 'testing',
|
||||
kind: monaco.languages.CompletionItemKind.Keyword,
|
||||
insertText:'testing({{condition}})'
|
||||
},
|
||||
{
|
||||
label: 'ifelse',
|
||||
kind: monaco.languages.CompletionItemKind.Snippet,
|
||||
insertText: [
|
||||
'if ({{condition}}) {',
|
||||
'\t{{}}',
|
||||
'} else {',
|
||||
'\t',
|
||||
'}'
|
||||
].join('\n'),
|
||||
documentation: 'If-Else Statement'
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
monaco.editor.create(document.getElementById("container"), {
|
||||
value: getCode(),
|
||||
language: 'mySpecialLanguage'
|
||||
});
|
||||
|
||||
function getCode() {
|
||||
return [
|
||||
'[Sun Mar 7 16:02:00 2004] [notice] Apache/1.3.29 (Unix) configured -- resuming normal operations',
|
||||
'[Sun Mar 7 16:02:00 2004] [info] Server built: Feb 27 2004 13:56:37',
|
||||
'[Sun Mar 7 16:02:00 2004] [notice] Accept mutex: sysvsem (Default: sysvsem)',
|
||||
'[Sun Mar 7 16:05:49 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Sun Mar 7 16:45:56 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Sun Mar 7 17:13:50 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Sun Mar 7 17:21:44 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Sun Mar 7 17:23:53 2004] statistics: Use of uninitialized value in concatenation (.) or string at /home/httpd/twiki/lib/TWiki.pm line 528.',
|
||||
'[Sun Mar 7 17:23:53 2004] statistics: Can\'t create file /home/httpd/twiki/data/Main/WebStatistics.txt - Permission denied',
|
||||
'[Sun Mar 7 17:27:37 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Sun Mar 7 17:31:39 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Sun Mar 7 17:58:00 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Sun Mar 7 18:00:09 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Sun Mar 7 18:10:09 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Sun Mar 7 18:19:01 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Sun Mar 7 18:42:29 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Sun Mar 7 18:52:30 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Sun Mar 7 18:58:52 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Sun Mar 7 19:03:58 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Sun Mar 7 19:08:55 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Sun Mar 7 20:04:35 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Sun Mar 7 20:11:33 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Sun Mar 7 20:12:55 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Sun Mar 7 20:25:31 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Sun Mar 7 20:44:48 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Sun Mar 7 20:58:27 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Sun Mar 7 21:16:17 2004] [error] [client xx.xx.xx.xx] File does not exist: /home/httpd/twiki/view/Main/WebHome',
|
||||
'[Sun Mar 7 21:20:14 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Sun Mar 7 21:31:12 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Sun Mar 7 21:39:55 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Sun Mar 7 21:44:10 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Mon Mar 8 01:35:13 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Mon Mar 8 01:47:06 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Mon Mar 8 01:59:13 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Mon Mar 8 02:12:24 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Mon Mar 8 02:54:54 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Mon Mar 8 03:46:27 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Mon Mar 8 03:48:18 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Mon Mar 8 03:52:17 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Mon Mar 8 03:55:09 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Mon Mar 8 04:22:55 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Mon Mar 8 04:24:47 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Mon Mar 8 04:40:32 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Mon Mar 8 04:55:40 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Mon Mar 8 04:59:13 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Mon Mar 8 05:22:57 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Mon Mar 8 05:24:29 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'[Mon Mar 8 05:31:47 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
|
||||
'<11>httpd[31628]: [error] [client xx.xx.xx.xx] File does not exist: /usr/local/installed/apache/htdocs/squirrelmail/_vti_inf.html in 29-Mar 15:18:20.50 from xx.xx.xx.xx',
|
||||
'<11>httpd[25859]: [error] [client xx.xx.xx.xx] File does not exist: /usr/local/installed/apache/htdocs/squirrelmail/_vti_bin/shtml.exe/_vti_rpc in 29-Mar 15:18:20.54 from xx.xx.xx.xx',
|
||||
].join('\n');;
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
<div id="container" style="height:100%;"></div>
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
|
||||
monaco.languages.register({ id: 'mySpecialLanguage' });
|
||||
|
||||
monaco.languages.registerHoverProvider('mySpecialLanguage', {
|
||||
provideHover: function(model, position) {
|
||||
return xhr('../playground.html').then(function(res) {
|
||||
return {
|
||||
range: new monaco.Range(1, 1, model.getLineCount(), model.getLineMaxColumn(model.getLineCount())),
|
||||
contents: [
|
||||
'**SOURCE**',
|
||||
{ language: 'html', value: res.responseText.substring(0, 200) }
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
monaco.editor.create(document.getElementById("container"), {
|
||||
value: '\n\nHover over this text',
|
||||
language: 'mySpecialLanguage'
|
||||
});
|
||||
|
||||
function xhr(url) {
|
||||
var req = null;
|
||||
return new monaco.Promise(function(c,e,p) {
|
||||
req = new XMLHttpRequest();
|
||||
req.onreadystatechange = function () {
|
||||
if (req._canceled) { return; }
|
||||
|
||||
if (req.readyState === 4) {
|
||||
if ((req.status >= 200 && req.status < 300) || req.status === 1223) {
|
||||
c(req);
|
||||
} else {
|
||||
e(req);
|
||||
}
|
||||
req.onreadystatechange = function () { };
|
||||
} else {
|
||||
p(req);
|
||||
}
|
||||
};
|
||||
|
||||
req.open("GET", url, true );
|
||||
req.responseType = "";
|
||||
|
||||
req.send(null);
|
||||
}, function () {
|
||||
req._canceled = true;
|
||||
req.abort();
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue