@ -33,9 +33,34 @@ require(['vs/editor/editor.main'], function () {
PascalDefinition ,
PythonDefinition ,
RubyDefinition ) {
monaco . languages . register ( { id : 'ace_c_cpp' } ) ;
MonacoAceTokenizer . registerRulesForLanguage ( 'ace_c_cpp' , new c _cppDefinition . default ) ;
monaco . languages . setLanguageConfiguration ( 'ace_c_cpp' , {
var overrideLangauges = [
'cpp' ,
'c' ,
'csharp' ,
'haskell' ,
'java' ,
'javascript' ,
'pascal' ,
'python' ,
'ruby' ,
'markdown'
] ;
monaco . languages . getLanguages ( ) . forEach ( function ( lang ) {
if ( overrideLangauges . includes ( lang . id ) ) {
lang . loader = function ( ) {
return { then : function ( ) { } } ;
} ;
}
} ) ;
var cppAliases = [ 'c' , 'cpp' , 'c++' , 'cxx' , 'cc' ] ;
for ( var i in cppAliases ) {
var alias = cppAliases [ i ] ;
monaco . languages . register ( { id : alias } ) ;
MonacoAceTokenizer . registerRulesForLanguage ( alias , new c _cppDefinition . default ) ;
monaco . languages . setLanguageConfiguration ( alias , {
comments : {
lineComment : '//' ,
blockComment : [ '/*' , '*/' ] ,
@ -66,10 +91,15 @@ require(['vs/editor/editor.main'], function () {
}
}
} ) ;
}
monaco . languages . register ( { id : 'ace_csharp' } ) ;
MonacoAceTokenizer . registerRulesForLanguage ( 'ace_csharp' , new CSharpDefinition . default ) ;
monaco . languages . setLanguageConfiguration ( 'ace_csharp' , {
var csharpAliases = [ 'csharp' , 'cs' , 'c#' ] ;
for ( var i in csharpAliases ) {
var alias = csharpAliases [ i ] ;
monaco . languages . register ( { id : alias } ) ;
MonacoAceTokenizer . registerRulesForLanguage ( alias , new CSharpDefinition . default ) ;
monaco . languages . setLanguageConfiguration ( alias , {
wordPattern : /(-?\d*\.\d\w*)|([^\`\~\!\#\$\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g ,
comments : {
lineComment : '//' ,
@ -102,10 +132,11 @@ require(['vs/editor/editor.main'], function () {
}
}
} ) ;
}
monaco . languages . register ( { id : 'ace_ haskell' } ) ;
MonacoAceTokenizer . registerRulesForLanguage ( 'ace_ haskell' , new HaskellDefinition . default ) ;
monaco . languages . setLanguageConfiguration ( 'ace_ haskell' , {
monaco . languages . register ( { id : 'haskell' } ) ;
MonacoAceTokenizer . registerRulesForLanguage ( 'haskell' , new HaskellDefinition . default ) ;
monaco . languages . setLanguageConfiguration ( 'haskell' , {
comments : {
lineComment : '--' ,
blockComment : [ '{-' , '-}' ]
@ -136,9 +167,9 @@ require(['vs/editor/editor.main'], function () {
}
} ) ;
monaco . languages . register ( { id : 'ace_ java' } ) ;
MonacoAceTokenizer . registerRulesForLanguage ( 'ace_ java' , new JavaDefinition . default ) ;
monaco . languages . setLanguageConfiguration ( 'ace_ java' , {
monaco . languages . register ( { id : 'java' } ) ;
MonacoAceTokenizer . registerRulesForLanguage ( 'java' , new JavaDefinition . default ) ;
monaco . languages . setLanguageConfiguration ( 'java' , {
// the default separators except `@$`
wordPattern : /(-?\d*\.\d\w*)|([^\`\~\!\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g ,
comments : {
@ -173,9 +204,12 @@ require(['vs/editor/editor.main'], function () {
}
} ) ;
monaco . languages . register ( { id : 'ace_javascript' } ) ;
MonacoAceTokenizer . registerRulesForLanguage ( 'ace_javascript' , new JavaScriptDefinition . default ) ;
monaco . languages . setLanguageConfiguration ( 'ace_javascript' , {
var javascriptAliases = [ 'javascript' , 'js' ] ;
for ( var i in javascriptAliases ) {
var alias = javascriptAliases [ i ] ;
monaco . languages . register ( { id : alias } ) ;
MonacoAceTokenizer . registerRulesForLanguage ( alias , new JavaScriptDefinition . default ) ;
monaco . languages . setLanguageConfiguration ( alias , {
wordPattern : /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g ,
comments : {
lineComment : '//' ,
@ -225,10 +259,15 @@ require(['vs/editor/editor.main'], function () {
}
}
} ) ;
}
monaco . languages . register ( { id : 'ace_pascal' } ) ;
MonacoAceTokenizer . registerRulesForLanguage ( 'ace_pascal' , new PascalDefinition . default ) ;
monaco . languages . setLanguageConfiguration ( 'ace_pascal' , {
var pascalAliases = [ 'pascal' , 'pas' ] ;
for ( var i in pascalAliases ) {
var alias = pascalAliases [ i ] ;
monaco . languages . register ( { id : alias } ) ;
MonacoAceTokenizer . registerRulesForLanguage ( alias , new PascalDefinition . default ) ;
monaco . languages . setLanguageConfiguration ( alias , {
// the default separators except `@$`
wordPattern : /(-?\d*\.\d\w*)|([^\`\~\!\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g ,
comments : {
@ -262,10 +301,15 @@ require(['vs/editor/editor.main'], function () {
}
}
} ) ;
}
var pythonAliases = [ 'python' , 'python2' , 'python3' , 'py' , 'py2' , 'py3' ] ;
for ( var i in pythonAliases ) {
var alias = pythonAliases [ i ] ;
monaco . languages . register ( { id : 'ace_python' } ) ;
MonacoAceTokenizer . registerRulesForLanguage ( 'ace_python' , new PythonDefinition . default ) ;
monaco . languages . setLanguageConfiguration ( 'ace_python' , {
monaco . languages . register ( { id : alias } ) ;
MonacoAceTokenizer . registerRulesForLanguage ( alias , new PythonDefinition . default ) ;
monaco . languages . setLanguageConfiguration ( alias , {
comments : {
lineComment : '#' ,
blockComment : [ '\'\'\'' , '\'\'\'' ] ,
@ -303,10 +347,11 @@ require(['vs/editor/editor.main'], function () {
}
}
} ) ;
}
monaco . languages . register ( { id : 'ace_ ruby' } ) ;
MonacoAceTokenizer . registerRulesForLanguage ( 'ace_ ruby' , new RubyDefinition . default ) ;
monaco . languages . setLanguageConfiguration ( 'ace_ ruby' , {
monaco . languages . register ( { id : 'ruby' } ) ;
MonacoAceTokenizer . registerRulesForLanguage ( 'ruby' , new RubyDefinition . default ) ;
monaco . languages . setLanguageConfiguration ( 'ruby' , {
comments : {
lineComment : '#' ,
blockComment : [ '=begin' , '=end' ] ,
@ -336,9 +381,212 @@ require(['vs/editor/editor.main'], function () {
}
} ) ;
var markdownAliases = [ 'markdown' , 'md' ] ;
for ( var i in markdownAliases ) {
var alias = markdownAliases [ i ] ;
monaco . languages . register ( { id : alias } ) ;
monaco . languages . setLanguageConfiguration ( alias , {
comments : {
blockComment : [ '<!--' , '-->' , ]
} ,
brackets : [
[ '{' , '}' ] ,
[ '[' , ']' ] ,
[ '(' , ')' ]
] ,
autoClosingPairs : [
{ open : '{' , close : '}' } ,
{ open : '[' , close : ']' } ,
{ open : '(' , close : ')' } ,
{ open : '<' , close : '>' , notIn : [ 'string' ] }
] ,
surroundingPairs : [
{ open : '(' , close : ')' } ,
{ open : '[' , close : ']' } ,
{ open : '`' , close : '`' } ,
] ,
folding : {
markers : {
start : new RegExp ( "^\\s*<!--\\s*#?region\\b.*-->" ) ,
end : new RegExp ( "^\\s*<!--\\s*#?endregion\\b.*-->" )
}
}
} ) ;
monaco . languages . setMonarchTokensProvider ( alias , {
defaultToken : '' ,
tokenPostfix : '.md' ,
// escape codes
control : /[\\`*_\[\]{}()#+\-\.!\$]/ ,
noncontrol : /[^\\`*_\[\]{}()#+\-\.!\$]/ ,
escapes : /\\(?:@control)/ ,
// escape codes for javascript/CSS strings
jsescapes : /\\(?:[btnfr\\"']|[0-7][0-7]?|[0-3][0-7]{2})/ ,
// non matched elements
empty : [
'area' , 'base' , 'basefont' , 'br' , 'col' , 'frame' ,
'hr' , 'img' , 'input' , 'isindex' , 'link' , 'meta' , 'param'
] ,
tokenizer : {
root : [
// headers (with #)
[ /^(\s{0,3})(#+)((?:[^\\#]|@escapes)+)((?:#+)?)/ , [ 'white' , 'keyword' , 'keyword' , 'keyword' ] ] ,
// headers (with =)
[ /^\s*(=+|\-+)\s*$/ , 'keyword' ] ,
// headers (with ***)
[ /^\s*((\*[ ]?)+)\s*$/ , 'meta.separator' ] ,
// quote
[ /^\s*>+/ , 'comment' ] ,
// list (starting with * or number)
[ /^\s*([\*\-+:]|\d+\.)\s/ , 'keyword' ] ,
// code block (4 spaces indent)
[ /^(\t|[ ]{4})[^ ].*$/ , 'string' ] ,
// code block (3 tilde)
[ /^\s*~~~\s*((?:\w|[\/\-#])+)?\s*$/ , { token : 'string' , next : '@codeblock' } ] ,
// display math
[ /\$\$/ , { token : 'string' , next : '@displaymath' } ] ,
// github style code blocks (with backticks and language)
[ /^\s*```\s*((?:\w|[\/\-#\+])+)\s*$/ , { token : 'string' , next : '@codeblockgh' , nextEmbedded : '$1' } ] ,
// github style code blocks (with backticks but no language)
[ /^\s*```\s*$/ , { token : 'string' , next : '@codeblock' } ] ,
// markup within lines
{ include : '@linecontent' } ,
] ,
displaymath : [
[ /\\\$/ , 'variable.source' ] ,
[ /\$\$/ , { token : 'string' , next : '@pop' } ] ,
[ /./ , 'variable.source' ]
] ,
codeblock : [
[ /^\s*~~~\s*$/ , { token : 'string' , next : '@pop' } ] ,
[ /^\s*```\s*$/ , { token : 'string' , next : '@pop' } ] ,
[ /.*$/ , 'variable.source' ] ,
] ,
// github style code blocks
codeblockgh : [
[ /```\s*$/ , { token : 'variable.source' , next : '@pop' , nextEmbedded : '@pop' } ] ,
[ /[^`]+/ , 'variable.source' ] ,
] ,
linecontent : [
// inline math
[ /\$/ , { token : 'string' , next : '@inlinemath' } ] ,
// escapes
[ /&\w+;/ , 'string.escape' ] ,
[ /@escapes/ , 'escape' ] ,
// various markup
[ /\b__([^\\_]|@escapes|_(?!_))+__\b/ , 'strong' ] ,
[ /\*\*([^\\*]|@escapes|\*(?!\*))+\*\*/ , 'strong' ] ,
[ /\b_[^_]+_\b/ , 'emphasis' ] ,
[ /\*([^\\*]|@escapes)+\*/ , 'emphasis' ] ,
[ /`([^\\`]|@escapes)+`/ , 'variable' ] ,
// links
[ /\{+[^}]+\}+/ , 'string.target' ] ,
[ /(!?\[)((?:[^\]\\]|@escapes)*)(\]\([^\)]+\))/ , [ 'string.link' , '' , 'string.link' ] ] ,
[ /(!?\[)((?:[^\]\\]|@escapes)*)(\])/ , 'string.link' ] ,
// or html
{ include : 'html' } ,
] ,
inlinemath : [
[ /\\\$/ , 'variable.source' ] ,
[ /\$/ , { token : 'string' , next : '@pop' } ] ,
[ /./ , 'variable.source' ]
] ,
// Note: it is tempting to rather switch to the real HTML mode instead of building our own here
// but currently there is a limitation in Monarch that prevents us from doing it: The opening
// '<' would start the HTML mode, however there is no way to jump 1 character back to let the
// HTML mode also tokenize the opening angle bracket. Thus, even though we could jump to HTML,
// we cannot correctly tokenize it in that mode yet.
html : [
// html tags
[ /<(\w+)\/>/ , 'tag' ] ,
[ /<(\w+)/ , {
cases : {
'@empty' : { token : 'tag' , next : '@tag.$1' } ,
'@default' : { token : 'tag' , next : '@tag.$1' }
}
} ] ,
[ /<\/(\w+)\s*>/ , { token : 'tag' } ] ,
[ /<!--/ , 'comment' , '@comment' ]
] ,
comment : [
[ /[^<\-]+/ , 'comment.content' ] ,
[ /-->/ , 'comment' , '@pop' ] ,
[ /<!--/ , 'comment.content.invalid' ] ,
[ /[<\-]/ , 'comment.content' ]
] ,
// Almost full HTML tag matching, complete with embedded scripts & styles
tag : [
[ /[ \t\r\n]+/ , 'white' ] ,
[ /(type)(\s*=\s*)(")([^"]+)(")/ , [ 'attribute.name.html' , 'delimiter.html' , 'string.html' ,
{ token : 'string.html' , switchTo : '@tag.$S2.$4' } ,
'string.html' ] ] ,
[ /(type)(\s*=\s*)(')([^']+)(')/ , [ 'attribute.name.html' , 'delimiter.html' , 'string.html' ,
{ token : 'string.html' , switchTo : '@tag.$S2.$4' } ,
'string.html' ] ] ,
[ /(\w+)(\s*=\s*)("[^"]*"|'[^']*')/ , [ 'attribute.name.html' , 'delimiter.html' , 'string.html' ] ] ,
[ /\w+/ , 'attribute.name.html' ] ,
[ /\/>/ , 'tag' , '@pop' ] ,
[ />/ , {
cases : {
'$S2==style' : { token : 'tag' , switchTo : 'embeddedStyle' , nextEmbedded : 'text/css' } ,
'$S2==script' : {
cases : {
'$S3' : { token : 'tag' , switchTo : 'embeddedScript' , nextEmbedded : '$S3' } ,
'@default' : { token : 'tag' , switchTo : 'embeddedScript' , nextEmbedded : 'text/javascript' }
}
} ,
'@default' : { token : 'tag' , next : '@pop' }
}
} ] ,
] ,
embeddedStyle : [
[ /[^<]+/ , '' ] ,
[ /<\/style\s*>/ , { token : '@rematch' , next : '@pop' , nextEmbedded : '@pop' } ] ,
[ /</ , '' ]
] ,
embeddedScript : [
[ /[^<]+/ , '' ] ,
[ /<\/script\s*>/ , { token : '@rematch' , next : '@pop' , nextEmbedded : '@pop' } ] ,
[ /</ , '' ]
] ,
}
} ) ;
}
$ . getScript ( window . pathSelfLib + "monaco-editor-tomorrow.js" , function ( ) {
window . createEditor = function ( editorElement , langauge , content ) {
window . createCodeEditor = function ( editorElement , langauge , content ) {
editorElement . innerHTML = '' ;
return monaco . editor . create ( editorElement , {
value : content ,
language : langauge ,
@ -347,12 +595,62 @@ require(['vs/editor/editor.main'], function () {
theme : 'tomorrow' ,
lineHeight : 22 ,
fontSize : 14 ,
fontFamily : "'Fira Mono', 'Bitstream Vera Sans Mono', 'Menlo', 'Consolas', 'Lucida Console', monospace" ,
fontFamily : "'Fira Mono', 'Bitstream Vera Sans Mono', 'Menlo', 'Consolas', 'Lucida Console', 'Source Han Sans SC', 'Noto Sans CJK SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft Yahei', monospace" ,
lineNumbersMinChars : 4 ,
glyphMargin : false
glyphMargin : false ,
renderFinalNewline : true ,
scrollbar : {
useShadows : false ,
verticalScrollbarSize : 0 ,
vertical : 'hidden'
} ,
overviewRulerBorder : false ,
hideCursorInOverviewRuler : true
} ) ;
} ;
window . createMarkdownEditor = function ( editorElement , content , input ) {
editorElement . innerHTML = '' ;
var editor = monaco . editor . create ( editorElement , {
value : content ,
language : 'markdown' ,
multicursorModifier : 'ctrlCmd' ,
cursorWidth : 1 ,
theme : 'tomorrow' ,
fontSize : 14 ,
fontFamily : "'Fira Mono', 'Source Han Sans SC', 'Noto Sans CJK SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft Yahei', monospace" ,
lineNumbersMinChars : 4 ,
glyphMargin : false ,
lineNumbers : false ,
folding : false ,
minimap : {
enabled : false
} ,
hover : {
enabled : false
} ,
wordWrap : "on" ,
renderIndentGuides : false ,
renderFinalNewline : false ,
wordBasedSuggestions : false ,
renderLineHighlight : false ,
occurrencesHighlight : false ,
scrollbar : {
useShadows : false ,
vertical : 'auto' ,
verticalScrollbarSize : 10
} ,
overviewRulerBorder : false ,
hideCursorInOverviewRuler : true
} ) ;
input . form . addEventListener ( 'submit' , function ( ) {
input . value = editor . getValue ( ) ;
} ) ;
return editor ;
} ;
window . editorLoaded = true ;
for ( var i in window . editorLoadedHandles ) {
window . editorLoadedHandles [ i ] ( ) ;