微软开源代码编辑器monaco-editor

  

  官网上给出:”The Monaco Editor is the code editor that powers VS Code. A good page describing the code editor‘s features is here.

  It is licensed under the MIT License and supports IE 9/10/11, Edge, Chrome, Firefox, Safari and Opera.“

Monaco Editor 展现还是非常牛的,直接上图:

https://microsoft.github.io/monaco-editor/

下面给出一个入门教程:

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <meta http-equiv="X-UA-Compatible" content="IE=edge" />
 5     <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
 6 </head>
 7 <body>
 8
 9 <div id="container" style="width:800px;height:600px;border:1px solid grey"></div>
10 <div id="container2" style="width:800px;height:600px;border:1px solid grey"></div>
11 <script src="min/vs/loader.js"></script>
12 <script>
13     require.config({ paths: { ‘vs‘: ‘min/vs‘ }});
14     require([‘vs/editor/editor.main‘], function() {
15         var editor = monaco.editor.create(document.getElementById(‘container‘), {
16             value: [
17                 ‘function x() {‘,
18                 ‘\tconsole.log("Hello world!");‘,
19                 ‘}‘
20             ].join(‘\n‘),
21             language: ‘javascript‘
22         });
23
24          var editor2 = monaco.editor.create(document.getElementById(‘container2‘), {
25             value: [
26                 ‘function x() {‘,
27                 ‘\tconsole.log("Hello world!");‘,
28                 ‘}‘
29             ].join(‘\n‘),
30             language: ‘csharp‘,
31             theme:‘vs-dark‘
32         });
33
34
35     });
36
37     function changeTheme(theme) {
38         var newTheme = (theme === 1 ? ‘vs-dark‘ : ( theme === 0 ? ‘vs‘ : ‘hc-black‘ ));
39         if (editor) {
40             editor.updateOptions({ ‘theme‘ : newTheme });
41         }
42         if (diffEditor) {
43             diffEditor.updateOptions({ ‘theme‘: newTheme });
44         }
45     }
46 </script>
47 </body>
48 </html>

对Javascript语言是有智能提示的,如上图所示。

  1 <!DOCTYPE html>
  2 <html>
  3 <head>
  4     <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  5     <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
  6 </head>
  7 <body>
  8
  9 <div id="diff-editor" style="width:800px;height:600px;border:1px solid grey"></div>
 10     <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js" integrity="sha256-wS9gmOZBqsqWxgIVgA8Y9WcQOa7PgSIX+rPA0VL2rbQ=" crossorigin="anonymous"></script>
 11 <script src="min/vs/loader.js"></script>
 12 <script>
 13
 14 // $(document).ready(function() {
 15 //     require.config({ paths: { ‘vs‘: ‘min/vs‘ }});
 16 //     require([‘vs/editor/editor.main‘], function() {
 17
 18
 19 //          var editor = monaco.editor.create(document.getElementById(‘container‘), {
 20 //             value: [
 21 //                 ‘function x() {‘,
 22 //                 ‘\tconsole.log("Hello world!");‘,
 23 //                 ‘}‘
 24 //             ].join(‘\n‘),
 25 //             language: ‘csharp‘,
 26 //             theme:‘vs-dark‘
 27 //         });
 28
 29
 30 //     });
 31
 32 //     window.onresize = function () {
 33 //         if (editor) {
 34 //             editor.layout();
 35 //         }
 36 //         if (diffEditor) {
 37 //             diffEditor.layout();
 38 //         }
 39 //     };
 40 // });
 41 var preloaded = {};
 42
 43
 44 function xhr(url, cb) {
 45     if (preloaded[url]) {
 46         return cb(null, preloaded[url]);
 47     }
 48     $.ajax({
 49         type: ‘GET‘,
 50         url: url,
 51         dataType: ‘text‘,
 52         error: function () {
 53             cb(this, null);
 54         }
 55     }).done(function(data) {
 56         cb(null, data);
 57     });
 58 }
 59 function loadDiffSample() {
 60
 61     var onError = function() {
 62         // $(‘.loading.diff-editor‘).fadeOut({ duration: 200 });
 63         // $(‘#diff-editor‘).append(‘<p class="alert alert-error">Failed to load diff editor sample</p>‘);
 64     };
 65
 66
 67
 68     var lhsData = null, rhsData = null, jsMode = null;
 69
 70     xhr(‘txt/diff.lhs.txt‘, function(err, data) {
 71         if (err) {
 72             return onError();
 73         }
 74         lhsData = data;
 75         onProgress();
 76     })
 77     xhr(‘txt/diff.rhs.txt‘, function(err, data) {
 78         if (err) {
 79             return onError();
 80         }
 81         rhsData = data;
 82         onProgress();
 83     })
 84
 85     function onProgress() {
 86         if (lhsData && rhsData) {
 87             require.config({ paths: { ‘vs‘: ‘min/vs‘ }});
 88             require([‘vs/editor/editor.main‘], function() {
 89                 diffEditor = monaco.editor.createDiffEditor(document.getElementById(‘diff-editor‘), {
 90                     enableSplitViewResizing: false
 91                 });
 92
 93                 var lhsModel = monaco.editor.createModel(lhsData, ‘text/javascript‘);
 94                 var rhsModel = monaco.editor.createModel(rhsData, ‘text/javascript‘);
 95
 96                 diffEditor.setModel({
 97                     original: lhsModel,
 98                     modified: rhsModel
 99                 });
100             });
101             //$(‘.loading.diff-editor‘).fadeOut({ duration: 300 });
102         }
103     }
104 }
105     function changeTheme(theme) {
106         var newTheme = (theme === 1 ? ‘vs-dark‘ : ( theme === 0 ? ‘vs‘ : ‘hc-black‘ ));
107         if (editor) {
108             editor.updateOptions({ ‘theme‘ : newTheme });
109         }
110         if (diffEditor) {
111             diffEditor.updateOptions({ ‘theme‘: newTheme });
112         }
113     }
114
115     loadDiffSample();
116 </script>
117 </body>
118 </html>

时间: 2024-08-07 16:42:46

微软开源代码编辑器monaco-editor的相关文章

4个最流行的Linux平台开源代码编辑器

正在寻找 Linux平台最棒的代码编辑器 ?如果你询问那些很早就玩Linux的人,他们会回答是Vi, Vim, Emacs, Nano等.但是,我今天不讨论那些.我将谈论一些新时代尖端.漂亮.时髦而且十分强大, 功能丰富的 最好的Linux平台开源代码编辑器 ,它们将会提升你的编程经验. Linux平台最时髦的开源代码编辑器 我使用Ubuntu作为我的主桌面,所以我提供的安装说明是基于Ubuntu的发行版.但是这并不意味着本文列表就是 Ubuntu最好的文本编辑器 ,因为本列表是适用于任何Lin

秒杀Sublime Text的微软开源代码编辑工具Visual Studio Code

1. 下载链接: https://code.visualstudio.com/ 2. 秒开一个ASP.NET网站源码 3.编辑CSS颜色支持 4.Git支持 5.常用快捷键 Ctrl+Shift+P 命令面板 Ctrl+Shift+N 打开一个新窗口 Ctrl+Shift+W 关闭窗口 Ctrl+N 新建文件 Ctrl+Tab 文件之间切换 Shift+Alt+F 代码格式化 Ctrl+End 移动到文件结尾 Ctrl+Home 移动到文件开头 Ctrl+F 查找 Ctrl+H 查找替换 Ctr

Monaco Editor 使用入门

以前项目是用ace编辑器的,但是总有些不敬人意的地方.前端事件看见的VS Code编辑器Monaco Editor准备更换下,下面介绍一些使用中遇到的一点问题.代码提示 1.项目引用 import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'; 项目中引用了editor.api.js,但是这个文件不包含一些默认的语言和插件,所以在使用的时候,还需要我们自己import import 'monaco-editor/esm/vs/

微软良心之作——Visual Studio Code 开源免费跨平台代码编辑器

微软良心之作--Visual Studio Code 开源免费跨平台代码编辑器 在 Build 2015 大会上,微软除了发布了 Microsoft Edge 浏览器和新的 Windows 10 预览版外,最大的惊喜莫过于宣布推出免费跨平台的 Visual Studio Code 编辑器了! Visual Studio Code (简称 VS Code / VSC) 是一款免费开源的现代化轻量级代码编辑器,支持语法高亮.智能代码补全.自定义热键.括号匹配.代码片段.代码对比 Diff.GIT 等

微软代码编辑器Visual Studio Code 1.35.0中文版

Visual Studio Code for Mac是微软旗下的一款代码编辑器,允许您使用大量编程语言,并集成调试和Git支持.Visual Studio Code可以帮助您能够在结构良好的环境中处理软件项目,该环境集成了基本代码编辑功能.而且可以为开发Node.js和ASP.NET应用程序提供支持,并提供超过30种编程语言的语法支持.在Visual Studio代码应用程序中,您可以选择打开单个文件,也可以链接Git存储库文件夹并访问所有相关文档.后一个选项更可取,因为您可以查看项目的结构并监

Brackets - 强大免费的开源跨平台Web前端开发工具IDE (HTML/CSS/Javascript代码编辑器)

Brackets 是一个免费.开源且跨平台的 HTML/CSS/JavaScript 前端 WEB 集成开发环境 (IDE工具).该项目由 Adobe 创建和维护,根据MIT许可证发布,支持 Windows.Linux 以及 OS X 平台. Brackets 的特点是简约.优雅.快捷!它没有很多的视图或者面板,也没太多花哨的功能,它的核心目标是减少在开发过程中那些效率低下的重复性工作,例如浏览器刷新,修改元素的样式,搜索功能等等.和 Sublime Text.Everedit 等通用代码编辑器

Vim - 文本/代码编辑器之中最为优秀经典的上古神器!强大、高效、免费开源且跨平台!

Vim 是 Linux 系统上的最著名的文本/代码编辑器,也是早年的 Vi 编辑器的加强版,而 gVim 则是其 Windows 版.它的最大特色是完全使用键盘命令进行编辑,脱离了鼠标操作虽然使得入门变得困难,但上手之后键盘流的各种巧妙组合操作却能带来极为大幅的效率提升. 因此 Vim 和现代的编辑器(如 Sublime Text)有着非常巨大的差异,而且入门学习曲线陡峭,需要记住很多按键组合和命令,如今被看作是高手.Geek们专用的编辑器.尽管 Vim 已经是古董级的软件,但还是有无数新人迎着

代码编辑器横评:为什么 VS Code 能拔得头筹

摘要: 为什么 VS Code 这么火... Fundebug经授权转载,版权归原作者所有. 2015 年 4 月 29 日的 Build 大会上,微软发布了 Visual Studio Code 第一个预览版本.短短四年时间里,VS Code 高速成长. 根据 2019 年 2 月的 PYPL Top IDE index 的排名,VS Code 的涨势迅猛,在所有编辑器与 IDE 中排名第六,领先于其他主流的代码编辑器:Sublime.Atom 和 Vim.可以说是已经在代码编辑器中拔得头筹.

最大开源代码sourceforge 简介 及视音频方面常用的开源代码

所有的音视频凯源代码在这里:http://sourceforge.net/directory/audio-video/os:windows/,你可以下载分析,视频不懂请发邮件给我,帮你分析. 0.视频项目 0.1  VLC media player VLC 多媒体播放器(最初为VideoLAN Client,是VideoLAN计划的开放源代码多媒体播放器.)支援众多音讯与视讯解码器及档案格式,并支援DVD影音光碟,VCD影音光碟及各类串流协定.它也能作为单播 或 多播的串流服务器在IPv4 或I