From 5b64fd49384b1374fde0b55fb90f69c77cb8c8ac Mon Sep 17 00:00:00 2001 From: Steven Degutis Date: Thu, 3 Oct 2019 10:04:29 -0500 Subject: [PATCH] Adds Markdown Table syntax highlighting New styles used are `keyword.table.{header,left,middle,right}`. --- src/markdown/markdown.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/markdown/markdown.ts b/src/markdown/markdown.ts index 4b0653a8..9fa4dbca 100644 --- a/src/markdown/markdown.ts +++ b/src/markdown/markdown.ts @@ -57,6 +57,9 @@ export const language = { tokenizer: { root: [ + // markdown tables + [/^\s*\|/, '@rematch', '@table_header'], + // headers (with #) [/^(\s{0,3})(#+)((?:[^\\#]|@escapes)+)((?:#+)?)/, ['white', 'keyword', 'keyword', 'keyword']], @@ -88,6 +91,29 @@ export const language = { { include: '@linecontent' }, ], + table_header: [ + { include: '@table_common' }, + [/[^\|]+/, 'keyword.table.header'], // table header + ], + + table_body: [ + { include: '@table_common' }, + { include: '@linecontent' }, + ], + + table_common: [ + [/\s*[\-:]+\s*/, { token: 'keyword', switchTo: 'table_body' }], // header-divider + [/^\s*\|/, 'keyword.table.left'], // opening | + [/^\s*[^\|]/, '@rematch', '@pop'], // exiting + [/^\s*$/, '@rematch', '@pop'], // exiting + [/\|/, { + cases: { + '@eos': 'keyword.table.right', // closing | + '@default': 'keyword.table.middle', // inner | + } + }], + ], + codeblock: [ [/^\s*~~~\s*$/, { token: 'string', next: '@pop' }], [/^\s*```\s*$/, { token: 'string', next: '@pop' }],