diff --git a/src/highlighting.js b/src/highlighting.js index a1eb854..299add9 100644 --- a/src/highlighting.js +++ b/src/highlighting.js @@ -11,10 +11,12 @@ import 'prismjs/components/prism-go'; import 'prismjs/components/prism-groovy'; import 'prismjs/components/prism-haskell'; import 'prismjs/components/prism-java'; +import 'prismjs/components/prism-javastacktrace'; import 'prismjs/components/prism-javascript'; import 'prismjs/components/prism-json'; import 'prismjs/components/prism-kotlin'; //import 'prismjs/components/prism-log'; +import './prism/prism-log'; // TODO replace with above once released import 'prismjs/components/prism-markdown'; //import 'prismjs/components/prism-php'; import 'prismjs/components/prism-protobuf'; @@ -40,9 +42,11 @@ export const languageIds = [ 'groovy', 'haskell', 'java', + 'javastacktrace', + 'javascript', 'json', 'kotlin', - //'log', + 'log', 'markdown', //'php', 'protobuf', diff --git a/src/prism/prism-log.js b/src/prism/prism-log.js new file mode 100644 index 0000000..9d69ecb --- /dev/null +++ b/src/prism/prism-log.js @@ -0,0 +1,115 @@ +/* eslint-disable */ + +import { languages } from 'prismjs/components/prism-core'; + +// Copied from https://github.com/PrismJS/prism/blob/master/components/prism-log.js +// License: https://github.com/PrismJS/prism/blob/master/LICENSE + +// This is a language definition for generic log files. +// Since there is no one log format, this language definition has to support all formats to some degree. +// +// Based on https://github.com/MTDL9/vim-log-highlighting + +languages.log = { + 'string': { + // Single-quoted strings must not be confused with plain text. E.g. Can't isn't Susan's Chris' toy + pattern: /"(?:[^"\\\r\n]|\\.)*"|'(?![st] | \w)(?:[^'\\\r\n]|\\.)*'/, + greedy: true, + }, + + 'level': [ + { + pattern: /\b(?:ALERT|CRIT|CRITICAL|EMERG|EMERGENCY|ERR|ERROR|FAILURE|FATAL|SEVERE)\b/, + alias: ['error', 'important'] + }, + { + pattern: /\b(?:WARN|WARNING)\b/, + alias: ['warning', 'important'] + }, + { + pattern: /\b(?:DISPLAY|INFO|NOTICE|STATUS)\b/, + alias: ['info', 'keyword'] + }, + { + pattern: /\b(?:DEBUG|FINE)\b/, + alias: ['debug', 'keyword'] + }, + { + pattern: /\b(?:FINER|FINEST|TRACE|VERBOSE)\b/, + alias: ['trace', 'comment'] + } + ], + + 'property': { + pattern: /((?:^|[\]|])[ \t]*)[a-z_](?:[\w-]|\b\/\b)*(?:[. ]\(?\w(?:[\w-]|\b\/\b)*\)?)*:(?=\s)/im, + lookbehind: true + }, + + 'separator': { + pattern: /(^|[^-+])-{3,}|={3,}|\*{3,}|- - /m, + lookbehind: true, + alias: 'comment' + }, + + 'url': /\b(?:https?|ftp|file):\/\/[^\s|,;'"]*[^\s|,;'">.]/, + 'email': { + pattern: /(^|\s)[-\w+.]+@[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)+(?=\s)/, + lookbehind: true, + alias: 'url' + }, + + 'ip-address': { + pattern: /\b(?:\d{1,3}(?:\.\d{1,3}){3})\b/i, + alias: 'constant' + }, + 'mac-address': { + pattern: /\b[a-f0-9]{2}(?::[a-f0-9]{2}){5}\b/i, + alias: 'constant' + }, + 'domain': { + pattern: /(^|\s)[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)*\.[a-z][a-z0-9-]+(?=\s)/, + lookbehind: true, + alias: 'constant' + }, + + 'uuid': { + pattern: /\b\w{8}-\w{4}-\w{4}-\w{4}-\w{12}\b/, + alias: 'constant' + }, + 'hash': { + pattern: /\b(?:[a-f0-9]{32}){1,2}\b/i, + alias: 'constant' + }, + + 'file-path': { + pattern: /\b[a-z]:[\\/][^\s|,;:(){}\[\]"']+|(^|[\s:\[\](>|])\.{0,2}\/\w[^\s|,;:(){}\[\]"']*/i, + lookbehind: true, + greedy: true, + alias: 'string' + }, + + 'date': { + pattern: RegExp( + /\b\d{4}[-/]\d{2}[-/]\d{2}T(?=\d{1,2}:)/.source + + '|' + + /\b\d{1,4}[-/ ](?:\d{1,2}|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[-/ ]\d{2,4}T?\b/.source + + '|' + + /\b(?:(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)(?:\s{1,2}(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec))?|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s{1,2}\d{1,2}\b/.source, + 'i' + ), + alias: 'number' + }, + 'time': { + pattern: /\b\d{1,2}:\d{1,2}:\d{1,2}(?:[.,:]\d+)?(?:\s?[+-]\d{2,4}|Z)?\b/, + alias: 'number' + }, + + 'boolean': /\b(?:true|false|null)\b/i, + 'number': { + pattern: /(^|[^.\w])(?:0x[a-f0-9]+|0o[0-7]+|0b[01]+|v?\d[\da-f]*(?:\.\d+)*(?:e[+-]?\d+)?[a-z]{0,3}\b)\b(?!\.\w)/i, + lookbehind: true + }, + + 'operator': /[;:?<=>~/@!$%&+\-|^(){}*#]/, + 'punctuation': /[\[\].,]/ +}; \ No newline at end of file