Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nightwing committed Sep 27, 2024
1 parent 92db310 commit c0cdd76
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 60 deletions.
34 changes: 34 additions & 0 deletions demo/csp-simple.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="Content-Security-Policy" content="
style-src 'self' ;
img-src 'self' data: ;
script-src 'self' 'nonce-bootstrap-script' https://mkslanc.github.io;
worker-src 'self' blob:
">
<title>Editor</title>
</head>
<body>
<pre id="editor"></pre>

<script src="../build/src-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>

<script nonce="bootstrap-script">

var editor = ace.edit("editor", {
theme: "ace/theme/tomorrow_night_eighties",
mode: "ace/mode/html",
maxLines: 30,
wrap: true,
autoScrollEditorIntoView: true
});

</script>

<script src="./show_own_source.js"></script>

</body>
</html>
2 changes: 1 addition & 1 deletion demo/csp.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta http-equiv="Content-Security-Policy" content="
style-src 'self' ;
img-src 'self' ;
script-src 'self' 'nonce-bootstrap-script';
script-src 'self' 'nonce-bootstrap-script' https://mkslanc.github.io;
worker-src 'self' blob:
">
<title>Editor</title>
Expand Down
25 changes: 24 additions & 1 deletion src/lib/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,38 @@ function importCssString(cssText, id, target) {
if (id)
cssText += "\n/*# sourceURL=ace/css/" + id + " */";

if (!USE_STYLE_TAG) {
try {
var stylesheet = styles[id];
if (!stylesheet) {
stylesheet = styles[id] = new CSSStyleSheet();
stylesheet.replaceSync(cssText);
}
container.adoptedStyleSheets.push(stylesheet);
USE_STYLE_TAG = false;
return;
} catch(e) {
if (USE_STYLE_TAG === null) {
USE_STYLE_TAG = true;
} else {
setTimeout(function() {
throw e
});
}
}
}

var style = exports.createElement("style");
style.appendChild(doc.createTextNode(cssText));
if (id)
style.id = id;

if (container == doc)
container = exports.getDocumentHead(doc);
container.insertBefore(style, container.firstChild);
}
var USE_STYLE_TAG = null;
var styles = Object.create(null);

exports.importCssString = importCssString;

/**
Expand Down
106 changes: 53 additions & 53 deletions src/mode/lua_highlight_rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,60 +84,60 @@ var LuaHighlightRules = function() {
]
},

{
token : "comment",
regex : "\\-\\-.*$"
},
{
stateName: "bracketedString",
onMatch2 : function(value, scope){
return scope.get(this.next, value.length - 2).get("string.start");
},
regex : /\[=*\[/,
next : [
{
onMatch2 : function(value, scope) {
if (scope == "bracketedString" && value.length == scope.data) {
return scope.parent.get("string.end");
} else {
return scope.get("string.end");
}
},

regex : /\]=*\]/,
}, {
defaultToken : "string"
}
]
{
token : "comment",
regex : "\\-\\-.*$"
},
{
stateName: "bracketedString",
onMatch2 : function(value, scope){
return scope.get(this.next, value.length - 2).get("string.start");
},
{
token : "string", // " string
regex : '"(?:[^\\\\]|\\\\.)*?"'
}, {
token : "string", // ' string
regex : "'(?:[^\\\\]|\\\\.)*?'"
}, {
token : "constant.numeric", // float
regex : floatNumber
}, {
token : "constant.numeric", // integer
regex : integer + "\\b"
}, {
token : keywordMapper,
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
}, {
token : "keyword.operator",
regex : "\\+|\\-|\\*|\\/|%|\\#|\\^|~|<|>|<=|=>|==|~=|=|\\:|\\.\\.\\.|\\.\\."
}, {
token : "paren.lparen",
regex : "[\\[\\(\\{]"
}, {
token : "paren.rparen",
regex : "[\\]\\)\\}]"
}, {
token : "text",
regex : "\\s+|\\w+"
} ]
regex : /\[=*\[/,
next : [
{
onMatch2 : function(value, scope) {
if (scope == "bracketedString" && value.length == scope.data) {
return scope.parent.get("string.end");
} else {
return scope.get("string.end");
}
},

regex : /\]=*\]/,
}, {
defaultToken : "string"
}
]
},
{
token : "string", // " string
regex : '"(?:[^\\\\]|\\\\.)*?"'
}, {
token : "string", // ' string
regex : "'(?:[^\\\\]|\\\\.)*?'"
}, {
token : "constant.numeric", // float
regex : floatNumber
}, {
token : "constant.numeric", // integer
regex : integer + "\\b"
}, {
token : keywordMapper,
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
}, {
token : "keyword.operator",
regex : "\\+|\\-|\\*|\\/|%|\\#|\\^|~|<|>|<=|=>|==|~=|=|\\:|\\.\\.\\.|\\.\\."
}, {
token : "paren.lparen",
regex : "[\\[\\(\\{]"
}, {
token : "paren.rparen",
regex : "[\\]\\)\\}]"
}, {
token : "text",
regex : "\\s+|\\w+"
} ]
};

this.normalizeRules();
Expand Down
7 changes: 2 additions & 5 deletions src/mode/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ Mode = function() {
this.getTokenizer = function() {
if (!this.$tokenizer) {
this.$highlightRules = this.$highlightRules || new this.HighlightRules(this.$highlightRuleConfig);
var modeName;
var modeName = "root";
if (this.$id) {
modeName = this.$id.split('/').pop();
}
else {
modeName = "root";
modeName = this.$id.split("/").pop();
}
this.$tokenizer = new Tokenizer(this.$highlightRules.getRules(), modeName);
}
Expand Down

0 comments on commit c0cdd76

Please sign in to comment.