From a98b5ea6fe8e8cc98a55e0fd793e6e8660ea31c1 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Thu, 30 Dec 2021 19:47:21 +0100 Subject: chore: add prismjs for syntax highlighting --- public/prism/prism-dart.js | 83 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 public/prism/prism-dart.js (limited to 'public/prism/prism-dart.js') diff --git a/public/prism/prism-dart.js b/public/prism/prism-dart.js new file mode 100644 index 0000000..1f7f88d --- /dev/null +++ b/public/prism/prism-dart.js @@ -0,0 +1,83 @@ +(function (Prism) { + var keywords = [ + /\b(?:async|sync|yield)\*/, + /\b(?:abstract|assert|async|await|break|case|catch|class|const|continue|covariant|default|deferred|do|dynamic|else|enum|export|extends|extension|external|factory|final|finally|for|get|hide|if|implements|import|in|interface|library|mixin|new|null|on|operator|part|rethrow|return|set|show|static|super|switch|sync|this|throw|try|typedef|var|void|while|with|yield)\b/, + ]; + + // Handles named imports, such as http.Client + var packagePrefix = /(^|[^\w.])(?:[a-z]\w*\s*\.\s*)*(?:[A-Z]\w*\s*\.\s*)*/ + .source; + + // based on the dart naming conventions + var className = { + pattern: RegExp(packagePrefix + /[A-Z](?:[\d_A-Z]*[a-z]\w*)?\b/.source), + lookbehind: true, + inside: { + namespace: { + pattern: /^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/, + inside: { + punctuation: /\./, + }, + }, + }, + }; + + Prism.languages.dart = Prism.languages.extend('clike', { + 'class-name': [ + className, + { + // variables and parameters + // this to support class names (or generic parameters) which do not contain a lower case letter (also works for methods) + pattern: RegExp(packagePrefix + /[A-Z]\w*(?=\s+\w+\s*[;,=()])/.source), + lookbehind: true, + inside: className.inside, + }, + ], + keyword: keywords, + operator: + /\bis!|\b(?:as|is)\b|\+\+|--|&&|\|\||<<=?|>>=?|~(?:\/=?)?|[+\-*\/%&^|=!<>]=?|\?/, + }); + + Prism.languages.insertBefore('dart', 'string', { + 'string-literal': { + pattern: + /r?(?:("""|''')[\s\S]*?\1|(["'])(?:\\.|(?!\2)[^\\\r\n])*\2(?!\2))/, + greedy: true, + inside: { + interpolation: { + pattern: /((?:^|[^\\])(?:\\{2})*)\$(?:\w+|\{(?:[^{}]|\{[^{}]*\})*\})/, + lookbehind: true, + inside: { + punctuation: /^\$\{?|\}$/, + expression: { + pattern: /[\s\S]+/, + inside: Prism.languages.dart, + }, + }, + }, + string: /[\s\S]+/, + }, + }, + string: undefined, + }); + + Prism.languages.insertBefore('dart', 'class-name', { + metadata: { + pattern: /@\w+/, + alias: 'function', + }, + }); + + Prism.languages.insertBefore('dart', 'class-name', { + generics: { + pattern: + /<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<[\w\s,.&?]*>)*>)*>)*>/, + inside: { + 'class-name': className, + keyword: keywords, + punctuation: /[<>(),.:]/, + operator: /[?&|]/, + }, + }, + }); +})(Prism); -- cgit v1.2.3