mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 19:42:56 +01:00
Merge pull request #92 from koto/tt
Added an example of loading Monaco with Trusted Types
This commit is contained in:
commit
ee57c14cc2
1 changed files with 42 additions and 0 deletions
42
browser-amd-trusted-types/index.html
Normal file
42
browser-amd-trusted-types/index.html
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>browser-amd-editor</title>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
<meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script'" />
|
||||
</head>
|
||||
<body>
|
||||
<h2>Monaco Editor with Trusted Types Sample</h2>
|
||||
<div id="container" style="width: 800px; height: 600px; border: 1px solid grey"></div>
|
||||
|
||||
<script src="../node_modules/monaco-editor/min/vs/loader.js"></script>
|
||||
<script>
|
||||
// Allow monaco-editor to load scripts from its own paths only
|
||||
var scriptLoadingPolicy = {
|
||||
createScriptURL: function allowOnlyMonacoPaths(url) {
|
||||
if (
|
||||
url.indexOf('../node_modules/monaco-editor/min/vs/') === 0 &&
|
||||
url.lastIndexOf('..') == 0
|
||||
) {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
};
|
||||
// If browser supports Trusted Types, use them.
|
||||
if (typeof trustedTypes !== 'undefined') {
|
||||
scriptLoadingPolicy = trustedTypes.createPolicy('monaco-editor', scriptLoadingPolicy);
|
||||
}
|
||||
require.config({
|
||||
paths: { vs: '../node_modules/monaco-editor/min/vs' },
|
||||
trustedTypesPolicy: scriptLoadingPolicy
|
||||
});
|
||||
|
||||
require(['vs/editor/editor.main'], function () {
|
||||
var editor = monaco.editor.create(document.getElementById('container'), {
|
||||
value: ['function x() {', '\tconsole.log("Hello world!");', '}'].join('\n'),
|
||||
language: 'javascript'
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue