Skip to content
This repository has been archived by the owner on Nov 5, 2021. It is now read-only.

Commit

Permalink
Adds Markdown Table syntax highlighting (#73)
Browse files Browse the repository at this point in the history
Adds Markdown Table syntax highlighting
  • Loading branch information
alexdima committed Dec 16, 2019
2 parents c50642f + 5b64fd4 commit 307c82d
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/markdown/markdown.ts
Expand Up @@ -57,6 +57,9 @@ export const language = <ILanguage>{
tokenizer: {
root: [

// markdown tables
[/^\s*\|/, '@rematch', '@table_header'],

// headers (with #)
[/^(\s{0,3})(#+)((?:[^\\#]|@escapes)+)((?:#+)?)/, ['white', 'keyword', 'keyword', 'keyword']],

Expand Down Expand Up @@ -88,6 +91,29 @@ export const language = <ILanguage>{
{ 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' }],
Expand Down

0 comments on commit 307c82d

Please sign in to comment.