From fc0658c79f8e45e8bb3cddc0db817edf9ebb3c5e Mon Sep 17 00:00:00 2001 From: Legend Sabbir <123853512+legendSabbir@users.noreply.github.com> Date: Wed, 26 Jul 2023 22:14:33 +0600 Subject: [PATCH 1/7] Add files via upload --- src/astro.js | 21 ++++++++ src/astro_highlight_rules.js | 100 +++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 src/astro.js create mode 100644 src/astro_highlight_rules.js diff --git a/src/astro.js b/src/astro.js new file mode 100644 index 00000000000..c1924892037 --- /dev/null +++ b/src/astro.js @@ -0,0 +1,21 @@ +"use strict"; + +var oop = require("../lib/oop"); +var HtmlMode = require("./html").Mode; +var AstroHighlightRules = require("./astro_highlight_rules").AstroHighlightRules; +var HtmlBehaviour = require("./behaviour/html").HtmlBehaviour; +var HtmlFoldMode = require("./folding/html").FoldMode; + +var Mode = function() { + HtmlMode.call(this); + this.HighlightRules = AstroHighlightRules; + this.$behaviour = new HtmlBehaviour(); +}; + +oop.inherits(Mode, HtmlMode); + +(function() { + this.$id = "ace/mode/astro"; +}).call(Mode.prototype); + +exports.Mode = Mode; \ No newline at end of file diff --git a/src/astro_highlight_rules.js b/src/astro_highlight_rules.js new file mode 100644 index 00000000000..90622083577 --- /dev/null +++ b/src/astro_highlight_rules.js @@ -0,0 +1,100 @@ +"use strict"; + +var oop = require("../lib/oop"); +var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules; +var JavascriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules; + +var AstroHighlightRules = function () { + HtmlHighlightRules.call(this); + + var astro = { + token: "paren.quasi.start.astro.level3", + regex: /{/, + next: "inline-js-start" + }; + + for (var key in this.$rules) { + if (key.startsWith("js") || key.startsWith("css") || key.startsWith("comment")) continue; + this.$rules[key].unshift(astro); + } + + this.$rules.start.unshift({ + token: "comment", + regex: "---", + onMatch: function (value, state, stack) { + stack.splice(0) + return this.token + }, + next: "js-start" + }) + + this.embedRules(JavascriptHighlightRules, "js-", [{ + regex: "---", + token: "comment", + next: "start", + onMatch: function (value, state, stack) { + stack.splice(0); + return this.token + } + }]); + + this.embedRules(JavascriptHighlightRules, "inline-js-", [{ + regex: /}/, + token: "paren.quasi.end.astro.level3", + onMatch: function (value, state, stack) { + if (stack.length) { + if (stack.includes("inline-js-start")) { + stack.shift() + this.next = stack.shift() + if (this.next.indexOf("string") !== -1) return "paren.quasi.end" + return "paren.rparen" + } else { + if (stack.includes("string.attribute-value.xml0")) { + this.next = "string.attribute-value.xml0" + } + else if (stack.includes("tag_stuff")) { + this.next = "tag_stuff" + } + return this.token + } + } else { + this.next = this.nextState + return this.token + } + }, + nextState: "start" + }, { + regex: /{/, + token: "paren.lparen", + push: "inline-js-start" + }]); + + var overwriteJSXendRule = function (prefix) { + for (var index in this.$rules[prefix + "jsxAttributes"]) { + if (this.$rules[prefix + "jsxAttributes"][index].token === "meta.tag.punctuation.tag-close.xml") { + this.$rules[prefix + "jsxAttributes"][index].onMatch = function (value, currentState, stack) { + if (currentState == stack[0]) + stack.shift(); + if (value.length == 2) { + if (stack[0] == this.nextState) + stack[1]--; + if (!stack[1] || stack[1] < 0) { + stack.splice(0, 2); + } + } + this.next = stack[0] || prefix + "start"; + return [{ type: this.token, value: value }]; + } + break; + } + } + } + + overwriteJSXendRule.call(this, "js-") + overwriteJSXendRule.call(this, "inline-js-") + + this.normalizeRules(); +}; + +oop.inherits(AstroHighlightRules, HtmlHighlightRules); +exports.AstroHighlightRules = AstroHighlightRules; \ No newline at end of file From e10ff7453ea087e9c5066fcb75cb424aae21e4b5 Mon Sep 17 00:00:00 2001 From: Legend Sabbir Date: Thu, 27 Jul 2023 12:23:06 +0000 Subject: [PATCH 2/7] added astro mode --- demo/kitchen-sink/docs/astro.astro | 9 +++ src/ext/modelist.js | 1 + src/mode/astro.js | 21 ++++++ src/mode/astro_highlight_rules.js | 100 +++++++++++++++++++++++++++++ 4 files changed, 131 insertions(+) create mode 100644 demo/kitchen-sink/docs/astro.astro create mode 100644 src/mode/astro.js create mode 100644 src/mode/astro_highlight_rules.js diff --git a/demo/kitchen-sink/docs/astro.astro b/demo/kitchen-sink/docs/astro.astro new file mode 100644 index 00000000000..7e5437e6029 --- /dev/null +++ b/demo/kitchen-sink/docs/astro.astro @@ -0,0 +1,9 @@ +--- +const visible = true; +const name = "Legend Sabbir" +--- +{visible &&

Show me!

} + +{visible ?

Show me!

:

Else show me!

} + +

{name}

\ No newline at end of file diff --git a/src/ext/modelist.js b/src/ext/modelist.js index aac3e8fbede..999ba42cf1c 100644 --- a/src/ext/modelist.js +++ b/src/ext/modelist.js @@ -56,6 +56,7 @@ var supportedModes = { AsciiDoc: ["asciidoc|adoc"], ASL: ["dsl|asl|asl.json"], Assembly_x86:["asm|a"], + Astro: ["astro"], AutoHotKey: ["ahk"], BatchFile: ["bat|cmd"], BibTeX: ["bib"], diff --git a/src/mode/astro.js b/src/mode/astro.js new file mode 100644 index 00000000000..c1924892037 --- /dev/null +++ b/src/mode/astro.js @@ -0,0 +1,21 @@ +"use strict"; + +var oop = require("../lib/oop"); +var HtmlMode = require("./html").Mode; +var AstroHighlightRules = require("./astro_highlight_rules").AstroHighlightRules; +var HtmlBehaviour = require("./behaviour/html").HtmlBehaviour; +var HtmlFoldMode = require("./folding/html").FoldMode; + +var Mode = function() { + HtmlMode.call(this); + this.HighlightRules = AstroHighlightRules; + this.$behaviour = new HtmlBehaviour(); +}; + +oop.inherits(Mode, HtmlMode); + +(function() { + this.$id = "ace/mode/astro"; +}).call(Mode.prototype); + +exports.Mode = Mode; \ No newline at end of file diff --git a/src/mode/astro_highlight_rules.js b/src/mode/astro_highlight_rules.js new file mode 100644 index 00000000000..0edf1c15197 --- /dev/null +++ b/src/mode/astro_highlight_rules.js @@ -0,0 +1,100 @@ +"use strict"; + +var oop = require("../lib/oop"); +var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules; +var JavascriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules; + +var AstroHighlightRules = function () { + HtmlHighlightRules.call(this); + + var astro = { + token: "paren.lparen.astro", + regex: /{/, + next: "inline-js-start" + }; + + for (var key in this.$rules) { + if (key.startsWith("js") || key.startsWith("css") || key.startsWith("comment")) continue; + this.$rules[key].unshift(astro); + } + + this.$rules.start.unshift({ + token: "comment", + regex: /^---$/, + onMatch: function (value, state, stack) { + stack.splice(0) + return this.token + }, + next: "js-start" + }) + + this.embedRules(JavascriptHighlightRules, "js-", [{ + regex: /^---$/, + token: "comment", + next: "start", + onMatch: function (value, state, stack) { + stack.splice(0); + return this.token + } + }]); + + this.embedRules(JavascriptHighlightRules, "inline-js-", [{ + regex: /}/, + token: "paren.rparen.astro", + onMatch: function (value, state, stack) { + if (stack.length) { + if (stack.includes("inline-js-start")) { + stack.shift() + this.next = stack.shift() + if (this.next.indexOf("string") !== -1) return "paren.quasi.end" + return "paren.rparen" + } else { + if (stack.includes("string.attribute-value.xml0")) { + this.next = "string.attribute-value.xml0" + } + else if (stack.includes("tag_stuff")) { + this.next = "tag_stuff" + } + return this.token + } + } else { + this.next = this.nextState + return this.token + } + }, + nextState: "start" + }, { + regex: /{/, + token: "paren.lparen", + push: "inline-js-start" + }]); + + var overwriteJSXendRule = function (prefix) { + for (var index in this.$rules[prefix + "jsxAttributes"]) { + if (this.$rules[prefix + "jsxAttributes"][index].token === "meta.tag.punctuation.tag-close.xml") { + this.$rules[prefix + "jsxAttributes"][index].onMatch = function (value, currentState, stack) { + if (currentState == stack[0]) + stack.shift(); + if (value.length == 2) { + if (stack[0] == this.nextState) + stack[1]--; + if (!stack[1] || stack[1] < 0) { + stack.splice(0, 2); + } + } + this.next = stack[0] || prefix + "start"; + return [{ type: this.token, value: value }]; + } + break; + } + } + } + + overwriteJSXendRule.call(this, "js-") + overwriteJSXendRule.call(this, "inline-js-") + + this.normalizeRules(); +}; + +oop.inherits(AstroHighlightRules, HtmlHighlightRules); +exports.AstroHighlightRules = AstroHighlightRules; \ No newline at end of file From 01fd337c21666b17e2e4b85e85d676f09471003f Mon Sep 17 00:00:00 2001 From: Legend Sabbir Date: Mon, 31 Jul 2023 05:20:08 +0000 Subject: [PATCH 3/7] added astro mode --- src/astro.js | 1 - src/astro_highlight_rules.js | 40 ++++++++++++++++++------------------ 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/astro.js b/src/astro.js index c1924892037..a6ae6a00967 100644 --- a/src/astro.js +++ b/src/astro.js @@ -4,7 +4,6 @@ var oop = require("../lib/oop"); var HtmlMode = require("./html").Mode; var AstroHighlightRules = require("./astro_highlight_rules").AstroHighlightRules; var HtmlBehaviour = require("./behaviour/html").HtmlBehaviour; -var HtmlFoldMode = require("./folding/html").FoldMode; var Mode = function() { HtmlMode.call(this); diff --git a/src/astro_highlight_rules.js b/src/astro_highlight_rules.js index 90622083577..f26c1be10fb 100644 --- a/src/astro_highlight_rules.js +++ b/src/astro_highlight_rules.js @@ -16,17 +16,17 @@ var AstroHighlightRules = function () { for (var key in this.$rules) { if (key.startsWith("js") || key.startsWith("css") || key.startsWith("comment")) continue; this.$rules[key].unshift(astro); - } + }; this.$rules.start.unshift({ token: "comment", regex: "---", onMatch: function (value, state, stack) { - stack.splice(0) - return this.token + stack.splice(0); + return this.token; }, next: "js-start" - }) + }); this.embedRules(JavascriptHighlightRules, "js-", [{ regex: "---", @@ -34,7 +34,7 @@ var AstroHighlightRules = function () { next: "start", onMatch: function (value, state, stack) { stack.splice(0); - return this.token + return this.token; } }]); @@ -44,22 +44,22 @@ var AstroHighlightRules = function () { onMatch: function (value, state, stack) { if (stack.length) { if (stack.includes("inline-js-start")) { - stack.shift() - this.next = stack.shift() - if (this.next.indexOf("string") !== -1) return "paren.quasi.end" - return "paren.rparen" + stack.shift(); + this.next = stack.shift(); + if (this.next.indexOf("string") !== -1) return "paren.quasi.end"; + return "paren.rparen"; } else { if (stack.includes("string.attribute-value.xml0")) { - this.next = "string.attribute-value.xml0" + this.next = "string.attribute-value.xml0"; } else if (stack.includes("tag_stuff")) { - this.next = "tag_stuff" + this.next = "tag_stuff"; } - return this.token + return this.token; } } else { - this.next = this.nextState - return this.token + this.next = this.nextState; + return this.token; } }, nextState: "start" @@ -84,14 +84,14 @@ var AstroHighlightRules = function () { } this.next = stack[0] || prefix + "start"; return [{ type: this.token, value: value }]; - } + }; break; - } - } - } + }; + }; + }; - overwriteJSXendRule.call(this, "js-") - overwriteJSXendRule.call(this, "inline-js-") + overwriteJSXendRule.call(this, "js-"); + overwriteJSXendRule.call(this, "inline-js-"); this.normalizeRules(); }; From f3bb29db0f17a9cf54649fad73e3f075d3f34298 Mon Sep 17 00:00:00 2001 From: Legend Sabbir Date: Mon, 31 Jul 2023 08:37:36 +0000 Subject: [PATCH 4/7] added astro mode --- src/mode/astro.js | 1 - src/mode/astro_highlight_rules.js | 48 +++++++++++++++---------------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/mode/astro.js b/src/mode/astro.js index c1924892037..a6ae6a00967 100644 --- a/src/mode/astro.js +++ b/src/mode/astro.js @@ -4,7 +4,6 @@ var oop = require("../lib/oop"); var HtmlMode = require("./html").Mode; var AstroHighlightRules = require("./astro_highlight_rules").AstroHighlightRules; var HtmlBehaviour = require("./behaviour/html").HtmlBehaviour; -var HtmlFoldMode = require("./folding/html").FoldMode; var Mode = function() { HtmlMode.call(this); diff --git a/src/mode/astro_highlight_rules.js b/src/mode/astro_highlight_rules.js index 0edf1c15197..f26c1be10fb 100644 --- a/src/mode/astro_highlight_rules.js +++ b/src/mode/astro_highlight_rules.js @@ -8,7 +8,7 @@ var AstroHighlightRules = function () { HtmlHighlightRules.call(this); var astro = { - token: "paren.lparen.astro", + token: "paren.quasi.start.astro.level3", regex: /{/, next: "inline-js-start" }; @@ -16,50 +16,50 @@ var AstroHighlightRules = function () { for (var key in this.$rules) { if (key.startsWith("js") || key.startsWith("css") || key.startsWith("comment")) continue; this.$rules[key].unshift(astro); - } + }; this.$rules.start.unshift({ token: "comment", - regex: /^---$/, + regex: "---", onMatch: function (value, state, stack) { - stack.splice(0) - return this.token + stack.splice(0); + return this.token; }, next: "js-start" - }) + }); this.embedRules(JavascriptHighlightRules, "js-", [{ - regex: /^---$/, + regex: "---", token: "comment", next: "start", onMatch: function (value, state, stack) { stack.splice(0); - return this.token + return this.token; } }]); this.embedRules(JavascriptHighlightRules, "inline-js-", [{ regex: /}/, - token: "paren.rparen.astro", + token: "paren.quasi.end.astro.level3", onMatch: function (value, state, stack) { if (stack.length) { if (stack.includes("inline-js-start")) { - stack.shift() - this.next = stack.shift() - if (this.next.indexOf("string") !== -1) return "paren.quasi.end" - return "paren.rparen" + stack.shift(); + this.next = stack.shift(); + if (this.next.indexOf("string") !== -1) return "paren.quasi.end"; + return "paren.rparen"; } else { if (stack.includes("string.attribute-value.xml0")) { - this.next = "string.attribute-value.xml0" + this.next = "string.attribute-value.xml0"; } else if (stack.includes("tag_stuff")) { - this.next = "tag_stuff" + this.next = "tag_stuff"; } - return this.token + return this.token; } } else { - this.next = this.nextState - return this.token + this.next = this.nextState; + return this.token; } }, nextState: "start" @@ -84,14 +84,14 @@ var AstroHighlightRules = function () { } this.next = stack[0] || prefix + "start"; return [{ type: this.token, value: value }]; - } + }; break; - } - } - } + }; + }; + }; - overwriteJSXendRule.call(this, "js-") - overwriteJSXendRule.call(this, "inline-js-") + overwriteJSXendRule.call(this, "js-"); + overwriteJSXendRule.call(this, "inline-js-"); this.normalizeRules(); }; From cf4414a9e348e66d439e17b2c5134c76d56368fa Mon Sep 17 00:00:00 2001 From: Legend Sabbir <123853512+legendSabbir@users.noreply.github.com> Date: Mon, 31 Jul 2023 14:44:17 +0600 Subject: [PATCH 5/7] Delete astro.js --- src/astro.js | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 src/astro.js diff --git a/src/astro.js b/src/astro.js deleted file mode 100644 index a6ae6a00967..00000000000 --- a/src/astro.js +++ /dev/null @@ -1,20 +0,0 @@ -"use strict"; - -var oop = require("../lib/oop"); -var HtmlMode = require("./html").Mode; -var AstroHighlightRules = require("./astro_highlight_rules").AstroHighlightRules; -var HtmlBehaviour = require("./behaviour/html").HtmlBehaviour; - -var Mode = function() { - HtmlMode.call(this); - this.HighlightRules = AstroHighlightRules; - this.$behaviour = new HtmlBehaviour(); -}; - -oop.inherits(Mode, HtmlMode); - -(function() { - this.$id = "ace/mode/astro"; -}).call(Mode.prototype); - -exports.Mode = Mode; \ No newline at end of file From cbb54dae79c293e2bdec146bac8362dd3c721013 Mon Sep 17 00:00:00 2001 From: Legend Sabbir <123853512+legendSabbir@users.noreply.github.com> Date: Mon, 31 Jul 2023 14:44:41 +0600 Subject: [PATCH 6/7] Delete astro_highlight_rules.js --- src/astro_highlight_rules.js | 100 ----------------------------------- 1 file changed, 100 deletions(-) delete mode 100644 src/astro_highlight_rules.js diff --git a/src/astro_highlight_rules.js b/src/astro_highlight_rules.js deleted file mode 100644 index f26c1be10fb..00000000000 --- a/src/astro_highlight_rules.js +++ /dev/null @@ -1,100 +0,0 @@ -"use strict"; - -var oop = require("../lib/oop"); -var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules; -var JavascriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules; - -var AstroHighlightRules = function () { - HtmlHighlightRules.call(this); - - var astro = { - token: "paren.quasi.start.astro.level3", - regex: /{/, - next: "inline-js-start" - }; - - for (var key in this.$rules) { - if (key.startsWith("js") || key.startsWith("css") || key.startsWith("comment")) continue; - this.$rules[key].unshift(astro); - }; - - this.$rules.start.unshift({ - token: "comment", - regex: "---", - onMatch: function (value, state, stack) { - stack.splice(0); - return this.token; - }, - next: "js-start" - }); - - this.embedRules(JavascriptHighlightRules, "js-", [{ - regex: "---", - token: "comment", - next: "start", - onMatch: function (value, state, stack) { - stack.splice(0); - return this.token; - } - }]); - - this.embedRules(JavascriptHighlightRules, "inline-js-", [{ - regex: /}/, - token: "paren.quasi.end.astro.level3", - onMatch: function (value, state, stack) { - if (stack.length) { - if (stack.includes("inline-js-start")) { - stack.shift(); - this.next = stack.shift(); - if (this.next.indexOf("string") !== -1) return "paren.quasi.end"; - return "paren.rparen"; - } else { - if (stack.includes("string.attribute-value.xml0")) { - this.next = "string.attribute-value.xml0"; - } - else if (stack.includes("tag_stuff")) { - this.next = "tag_stuff"; - } - return this.token; - } - } else { - this.next = this.nextState; - return this.token; - } - }, - nextState: "start" - }, { - regex: /{/, - token: "paren.lparen", - push: "inline-js-start" - }]); - - var overwriteJSXendRule = function (prefix) { - for (var index in this.$rules[prefix + "jsxAttributes"]) { - if (this.$rules[prefix + "jsxAttributes"][index].token === "meta.tag.punctuation.tag-close.xml") { - this.$rules[prefix + "jsxAttributes"][index].onMatch = function (value, currentState, stack) { - if (currentState == stack[0]) - stack.shift(); - if (value.length == 2) { - if (stack[0] == this.nextState) - stack[1]--; - if (!stack[1] || stack[1] < 0) { - stack.splice(0, 2); - } - } - this.next = stack[0] || prefix + "start"; - return [{ type: this.token, value: value }]; - }; - break; - }; - }; - }; - - overwriteJSXendRule.call(this, "js-"); - overwriteJSXendRule.call(this, "inline-js-"); - - this.normalizeRules(); -}; - -oop.inherits(AstroHighlightRules, HtmlHighlightRules); -exports.AstroHighlightRules = AstroHighlightRules; \ No newline at end of file From 430603cf4b2d87a6a6a6fe4f7d2df39ce750882b Mon Sep 17 00:00:00 2001 From: Legend Sabbir <123853512+legendSabbir@users.noreply.github.com> Date: Mon, 31 Jul 2023 14:50:22 +0600 Subject: [PATCH 7/7] Update astro_highlight_rules.js --- src/mode/astro_highlight_rules.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mode/astro_highlight_rules.js b/src/mode/astro_highlight_rules.js index f26c1be10fb..0348005de45 100644 --- a/src/mode/astro_highlight_rules.js +++ b/src/mode/astro_highlight_rules.js @@ -16,7 +16,7 @@ var AstroHighlightRules = function () { for (var key in this.$rules) { if (key.startsWith("js") || key.startsWith("css") || key.startsWith("comment")) continue; this.$rules[key].unshift(astro); - }; + } this.$rules.start.unshift({ token: "comment", @@ -86,8 +86,8 @@ var AstroHighlightRules = function () { return [{ type: this.token, value: value }]; }; break; - }; - }; + } + } }; overwriteJSXendRule.call(this, "js-"); @@ -97,4 +97,4 @@ var AstroHighlightRules = function () { }; oop.inherits(AstroHighlightRules, HtmlHighlightRules); -exports.AstroHighlightRules = AstroHighlightRules; \ No newline at end of file +exports.AstroHighlightRules = AstroHighlightRules;