diff --git a/docs/Release Notes/Release Notes/v0.94.0.md b/docs/Release Notes/Release Notes/v0.94.0.md index 0a573e92e..fd283aceb 100644 --- a/docs/Release Notes/Release Notes/v0.94.0.md +++ b/docs/Release Notes/Release Notes/v0.94.0.md @@ -48,6 +48,7 @@ * Added support for SystemVerilog. * Added support for mIRC. * Added support for Cobol. + * Added support for Dylan. * Mermaid diagrams: basic syntax highlight (not all diagram types are supported) and code folding. * Slight organization in Appearance settings: code block themes are now in "Text Notes", added a "Related settings" section in Appearance. * [Added support for opening and activating a note in a new tab using Ctrl+Shift+click on notes in the launcher pane, note tree, or note images](https://github.com/TriliumNext/Notes/pull/1854) by @SiriusXT diff --git a/packages/highlightjs/src/languages/dylan.ts b/packages/highlightjs/src/languages/dylan.ts new file mode 100644 index 000000000..107989a0c --- /dev/null +++ b/packages/highlightjs/src/languages/dylan.ts @@ -0,0 +1,76 @@ +import type { HLJSApi, Language, Mode } from "highlight.js"; + +/* + * highlight.js Dylan syntax highlighting definition + * + * Source: https://github.com/highlightjs/highlightjs-dylan/blob/master/src/dylan.js + * + * @see https://github.com/highlightjs/highlight.js + * @see https://opendylan.org/ + * + * :TODO: + * + * @package: highlightjs-dylan + * @author: Peter Hull + * @since: 2019-04-08 + * + * Description: Dylan language definition + * Category: functional + */ + +export default function(hljs: HLJSApi): Language { + const DYLAN_CORE_WORDS = ["define", "end", "handler", "let", "local", "macro", "otherwise"]; + const DYLAN_BEGIN_WORDS = ["begin", "block", "case", "for", "if", "method", + "select", "unless", "until", "while" + ]; + const DYLAN_FUNCTION_WORDS: string[] = []; + const DYLAN_DEFINE_BODY_WORDS = ["class", "library", "method", "module"]; + const DYLAN_DEFINE_LIST_WORDS = ["constant", "variable", "domain"]; + const DYLAN_RESERVED_WORDS = ([] as string[]).concat(DYLAN_CORE_WORDS, + DYLAN_BEGIN_WORDS, + DYLAN_FUNCTION_WORDS, + DYLAN_DEFINE_BODY_WORDS.map(function(word) { + return word + '|2'; + }), + DYLAN_DEFINE_LIST_WORDS + ); + const DYLAN_HASH_WORDS = ["#t", "#f", "#next", "#rest", "#key", "#all-keys", "#include"]; + const DYLAN_WORD = '[a-z\-+\*/^=#!%$_><@\?~][a-z0-9\-+\*/^=#!%$_><@\?~]*'; + const KEYWORDS = { + $pattern: DYLAN_WORD, + literal: DYLAN_HASH_WORDS.join(" "), + keyword: DYLAN_RESERVED_WORDS.join(" ") + }; + const DYLAN_CODE = { + case_insensitive: true, + className: 'dylan', + keywords: KEYWORDS, + contains: [{ + className: 'class', + begin: '<' + DYLAN_WORD + '>', + relevance: 0 + }, + { + className: 'symbol', + begin: '#' + DYLAN_WORD + }, + { + className: 'symbol', + begin: DYLAN_WORD + ':', + relevance: 0 + }, + { + className: 'string', + begin: '\'\\\\?.', + end: '\'', + illegal: '.' + }, + hljs.C_NUMBER_MODE, + hljs.QUOTE_STRING_MODE, + hljs.C_LINE_COMMENT_MODE, + hljs.C_BLOCK_COMMENT_MODE + ] + }; + + return DYLAN_CODE; +}; diff --git a/packages/highlightjs/src/syntax_highlighting.ts b/packages/highlightjs/src/syntax_highlighting.ts index 6353f5ad9..d7d70467a 100644 --- a/packages/highlightjs/src/syntax_highlighting.ts +++ b/packages/highlightjs/src/syntax_highlighting.ts @@ -60,7 +60,7 @@ const byMimeType: MimeRecord = { "text/x-diff": () => import("highlight.js/lib/languages/diff"), "text/x-django": () => import("highlight.js/lib/languages/django"), "text/x-dockerfile": () => import("highlight.js/lib/languages/dockerfile"), - "text/x-dylan": null, + "text/x-dylan": () => import("./languages/dylan.js"), "text/x-ebnf": () => import("highlight.js/lib/languages/ebnf"), "text/x-ecl": null, "text/x-eiffel": null,