diff --git a/main.js b/main.js
index 3fcef62..b95f75f 100644
--- a/main.js
+++ b/main.js
@@ -400,7 +400,7 @@ var snippets = [
insert: "• "
},
{
- command: "//",
+ command: "/comment",
insert: "",
cursor: -4
}];
@@ -2081,6 +2081,11 @@ function escapeHtml(unsafe) {
.replace(/'/g, "'");
}
+var languagekeywords = {
+ "sql": ["select", "from", "where", "and", "or"],
+ "js": ["var", "for", "if", "else"]
+}
+
function applycolors()
{
if (!settings.colors)
@@ -2089,8 +2094,9 @@ function applycolors()
}
var lines = md.value.split("\n");
- header = false;
- code = false;
+ var header = false;
+ var code = false;
+ var language = "";
var result = [];
lines.every( (line, i) =>
{
@@ -2130,21 +2136,27 @@ function applycolors()
if (line.startsWith("```") && !code)
{
code = true;
- //lg = line.substring(3);
- line = "
" + line;
+ language = line.substring(3);
+ line = "" + line;
}
- if (line == "```" && code)
+ else if (line == "```" && code)
{
code = false;
- line = line + "
";
+ language = "";
+ line = line + "";
}
- /*else if (code)
+ else if (code)
{
- line = line.replace(/(select)/ig, "$1");
- line = line.replace(/(from)/ig, "$1");
- line = line.replace(/(where)/ig, "$1");
- /// todo: keywords by language. whole word only. use a loop. etc.
- }*/
+ if (languagekeywords[language])
+ {
+ var keywords = languagekeywords[language];
+ keywords.forEach(keyword =>
+ {
+ var r = new RegExp("(" + keyword + ")", "ig");
+ line = line.replace(new RegExp("\\b(" + keyword + ")\\b", "ig"), "$1");
+ })
+ }
+ }
// internal links
line = line.replace(/(\[\[.*\]\])/g, "$1");
@@ -2156,6 +2168,10 @@ function applycolors()
// comments
line = line.replace(/<\!/g, "<!");
line = line.replace(/\-\->/g, "-->");
+ if (line.startsWith("// "))
+ {
+ line = "" + line + "";
+ }
result.push(line);