Skip to content

Commit 410c25f

Browse files
authored
Merge pull request #5 from fram-lang/comments
Update syntax highlighting of Fram comments
2 parents 7f4f400 + d32b169 commit 410c25f

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

js/highlight-fram.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
hljs.registerLanguage("fram", function (hljs) {
2+
// Based on `hljs.END_SAME_AS_BEGIN`, which is included with highlight.js.
3+
// Here we only require that the opening match group is a suffix of the
4+
// closing one. Used for Fram comments.
5+
function MATCH_BEGIN_END(mode) {
6+
return Object.assign(mode,
7+
{ 'on:begin': (m, resp) =>
8+
{ resp.data._beginMatch = m[1]; },
9+
'on:end': (m, resp) =>
10+
{ if (!m[1].endsWith(resp.data._beginMatch)) resp.ignoreMatch(); }
11+
});
12+
}
13+
14+
const COMMENT_NAME = "([\\w'<>&$?!@^+\\-~*%;,=|:./#]*)";
15+
216
return {
317
keywords: {
418
keyword:
@@ -10,11 +24,11 @@ hljs.registerLanguage("fram", function (hljs) {
1024
contains: [
1125
hljs.APOS_STRING_MODE,
1226
hljs.QUOTE_STRING_MODE,
13-
hljs.C_LINE_COMMENT_MODE,
14-
hljs.COMMENT("\\(\\*", "\\*\\)"),
27+
hljs.HASH_COMMENT_MODE,
28+
MATCH_BEGIN_END(hljs.COMMENT("{#" + COMMENT_NAME, COMMENT_NAME + "#}")),
1529
{
1630
className: "type",
17-
begin: "\\b[A-Z]\\w*",
31+
begin: "\\b[A-Z][\\w']*",
1832
},
1933
{
2034
className: "number",

0 commit comments

Comments
 (0)