index.html 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>browser-amd-editor</title>
  5. <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  6. <meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script'" />
  7. </head>
  8. <body>
  9. <h2>Monaco Editor with Trusted Types Sample</h2>
  10. <div id="container" style="width: 800px; height: 600px; border: 1px solid grey"></div>
  11. <script src="../node_modules/monaco-editor/min/vs/loader.js"></script>
  12. <script>
  13. // Allow monaco-editor to load scripts from its own paths only
  14. var scriptLoadingPolicy = {
  15. createScriptURL: function allowOnlyMonacoPaths(url) {
  16. if (
  17. url.indexOf('../node_modules/monaco-editor/min/vs/') === 0 &&
  18. url.lastIndexOf('..') == 0
  19. ) {
  20. return url;
  21. }
  22. }
  23. };
  24. // If browser supports Trusted Types, use them.
  25. if (typeof trustedTypes !== 'undefined') {
  26. scriptLoadingPolicy = trustedTypes.createPolicy('monaco-editor', scriptLoadingPolicy);
  27. }
  28. require.config({
  29. paths: { vs: '../node_modules/monaco-editor/min/vs' },
  30. trustedTypesPolicy: scriptLoadingPolicy
  31. });
  32. require(['vs/editor/editor.main'], function () {
  33. var editor = monaco.editor.create(document.getElementById('container'), {
  34. value: ['function x() {', '\tconsole.log("Hello world!");', '}'].join('\n'),
  35. language: 'javascript'
  36. });
  37. });
  38. </script>
  39. </body>
  40. </html>