Skip to content

Commit

Permalink
fix: update highlight terraform code
Browse files Browse the repository at this point in the history
  • Loading branch information
yilanboy committed Dec 26, 2024
1 parent 84008b8 commit 7fea663
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions resources/ts/highlight-terraform.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// https://github.com/highlightjs/highlightjs-terraform/blob/master/terraform.js
import { HLJSApi } from 'highlight.js';

export default function (hljs: HLJSApi) {
export default function(hljs: HLJSApi) {
const KWS = [
'resource',
'variable',
Expand All @@ -10,23 +10,22 @@ export default function (hljs: HLJSApi) {
'locals',
'module',
'data',
'terraform|10',
'terraform',
'for',
'in',
'if',
'if'
];

const LITERAL = ['true', 'false', 'null'];

const KEYWORDS = {
keyword: KWS,
literal: LITERAL,
literal: LITERAL
};

const NUMBERS = {
scope: 'number',
begin: /\b\d+(\.\d+)?/,
relevance: 0,
begin: /\b\d+(\.\d+)?/
};

const STRINGS = {
Expand All @@ -37,50 +36,54 @@ export default function (hljs: HLJSApi) {
{
scope: 'variable',
begin: /\${/,
end: /}/,
relevance: 9,
},
],
end: /}/
}
]
};

const PARAMETER = {
scope: 'variable',
match: /\n\s*[a-zA-Z0-9_]+\s*(?==)/,
const FUNCTION = {
scope: 'title.function',
match: /[a-zA-Z0-9_]+(?=\()/
};

const ATTRIBUTE = {
scope: 'attr',
match: /[a-zA-Z0-9_]+\s*(?==)/
};

const BLOCK_PARAMETER = {
const BLOCK_ATTRIBUTE = {
scope: 'keyword',
match: /\n\s*[a-zA-Z0-9_]+\s*(?={)/,
match: /[a-zA-Z0-9_]+\s*(?={)/
};

const FUNCTION = {
scope: 'title.function',
match: /[a-zA-Z0-9_]+(?=\()/,
const PARAMETER = {
scope: 'params',
begin: /(?<==\s)(?!true\b|false\b|null\b)(\[.*?]|[\w.]+)/
};

const LEFT_BRACE = {
scope: 'punctuation',
match: /\{/,
match: /\{/
};

const RIGHT_BRACE = {
scope: 'punctuation',
match: /}/,
match: /}/
};

const LEFT_BRACKET = {
scope: 'punctuation',
match: /\[/,
match: /\[/
};

const RIGHT_BRACKET = {
scope: 'punctuation',
match: /]/,
match: /]/
};

const EQUALS = {
scope: 'operator',
match: /=/,
match: /=/
};

return {
Expand All @@ -91,14 +94,15 @@ export default function (hljs: HLJSApi) {
hljs.COMMENT(/#/, /$/),
NUMBERS,
STRINGS,
PARAMETER,
BLOCK_PARAMETER,
FUNCTION,
ATTRIBUTE,
BLOCK_ATTRIBUTE,
PARAMETER,
EQUALS,
LEFT_BRACE,
RIGHT_BRACE,
LEFT_BRACKET,
RIGHT_BRACKET,
],
RIGHT_BRACKET
]
};
}

0 comments on commit 7fea663

Please sign in to comment.