Skip to content

Commit 7da6efc

Browse files
committed
feat: add CDS grammar definition for syntax highlighting
1 parent e6d2482 commit 7da6efc

2 files changed

Lines changed: 90 additions & 1 deletion

File tree

docs/.vitepress/config.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import { withMermaid } from 'vitepress-plugin-mermaid'
33
import { agentmarkup } from '@agentmarkup/vite'
44
import { externalTutorialsPlugin } from './plugins/external-tutorials.js'
55
import { expandTutorialsPlugin } from './plugins/md-expand-tutorials.js'
6+
import { readFileSync } from 'fs'
7+
import { fileURLToPath } from 'url'
8+
import { join, dirname } from 'path'
9+
10+
const __dirname = dirname(fileURLToPath(import.meta.url))
11+
const cdsGrammar = JSON.parse(readFileSync(join(__dirname, 'grammars/cds.tmLanguage.json'), 'utf-8'))
612

713
const BASE = '/cap-hana-exercises-codejam/'
814
const SITE_URL = 'https://SAP-samples.github.io/cap-hana-exercises-codejam'
@@ -28,7 +34,9 @@ export default withMermaid(
2834
appearance: true,
2935

3036
markdown: {
31-
languageAlias: { cds: 'typescript' },
37+
languages: [
38+
{ ...cdsGrammar, name: 'cds', aliases: ['cap', 'name'] },
39+
],
3240
// Fix: markdown-it wraps loose list items in <p>, but <details> is a
3341
// block element that cannot be inside <p> (HTML5 content model).
3442
// Vue's strict SFC parser throws "Element is missing end tag" for this.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
3+
"name": "CDS",
4+
"scopeName": "source.cds",
5+
"fileTypes": ["cds"],
6+
"patterns": [
7+
{
8+
"include": "#keywords"
9+
},
10+
{
11+
"include": "#strings"
12+
},
13+
{
14+
"include": "#comments"
15+
},
16+
{
17+
"include": "#types"
18+
}
19+
],
20+
"repository": {
21+
"keywords": {
22+
"patterns": [
23+
{
24+
"name": "keyword.control.cds",
25+
"match": "\\b(namespace|using|context|service|entity|type|aspect|annotation|extend|annotate|view|key|virtual|as|where|on|select|from|into|distinct|order by|group by|having)\\b"
26+
},
27+
{
28+
"name": "keyword.other.cds",
29+
"match": "\\b(managed|aspect|composition|association|many|optional|not null|default|enum)\\b"
30+
}
31+
]
32+
},
33+
"types": {
34+
"patterns": [
35+
{
36+
"name": "storage.type.cds",
37+
"match": "\\b(String|Integer|Int32|Int64|Decimal|Double|Boolean|Date|Time|DateTime|Timestamp|Binary|LargeBinary|LargeString|UUID|UInt8|Int16|LocalDate|LocalTime)\\b"
38+
}
39+
]
40+
},
41+
"strings": {
42+
"patterns": [
43+
{
44+
"name": "string.quoted.single.cds",
45+
"begin": "'",
46+
"end": "'",
47+
"patterns": [
48+
{
49+
"name": "constant.character.escape.cds",
50+
"match": "\\\\."
51+
}
52+
]
53+
},
54+
{
55+
"name": "string.quoted.double.cds",
56+
"begin": "\"",
57+
"end": "\"",
58+
"patterns": [
59+
{
60+
"name": "constant.character.escape.cds",
61+
"match": "\\\\."
62+
}
63+
]
64+
}
65+
]
66+
},
67+
"comments": {
68+
"patterns": [
69+
{
70+
"name": "comment.line.double-slash.cds",
71+
"match": "//.*$"
72+
},
73+
{
74+
"name": "comment.block.cds",
75+
"begin": "/\\*",
76+
"end": "\\*/"
77+
}
78+
]
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)