From fc6f4878bfd0812c01d95bd1a8578767defa671e Mon Sep 17 00:00:00 2001 From: Michael Camilleri Date: Wed, 15 Jan 2020 09:03:39 +0900 Subject: [PATCH 1/2] Support optional props --- lib/rouge/lexers/typescript.rb | 7 +++++++ spec/visual/samples/typescript | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/rouge/lexers/typescript.rb b/lib/rouge/lexers/typescript.rb index 353ca7ffd5..478cdb481e 100644 --- a/lib/rouge/lexers/typescript.rb +++ b/lib/rouge/lexers/typescript.rb @@ -18,6 +18,13 @@ class Typescript < Javascript filenames '*.ts', '*.d.ts' mimetypes 'text/typescript' + + prepend :statement do + rule %r/(#{Javascript.id_regex}\??)(\s*)(:)/ do + groups Name::Label, Text, Punctuation + push :expr_start + end + end end end end diff --git a/spec/visual/samples/typescript b/spec/visual/samples/typescript index 6d9511dc1d..7379879409 100644 --- a/spec/visual/samples/typescript +++ b/spec/visual/samples/typescript @@ -167,7 +167,7 @@ declare module "foo" { export interface IFoo { theObject: any; aWord: string; - aNumber: number; + aNumber?: number; } } From 98e729e61db9db9dade7df306f35f8dc7ab95267 Mon Sep 17 00:00:00 2001 From: Michael Camilleri Date: Thu, 23 Jan 2020 00:40:45 +0900 Subject: [PATCH 2/2] Use Punctuation token for question mark --- lib/rouge/lexers/typescript.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/rouge/lexers/typescript.rb b/lib/rouge/lexers/typescript.rb index 478cdb481e..52f95e7695 100644 --- a/lib/rouge/lexers/typescript.rb +++ b/lib/rouge/lexers/typescript.rb @@ -20,8 +20,8 @@ class Typescript < Javascript mimetypes 'text/typescript' prepend :statement do - rule %r/(#{Javascript.id_regex}\??)(\s*)(:)/ do - groups Name::Label, Text, Punctuation + rule %r/(#{Javascript.id_regex})(\??)(\s*)(:)/ do + groups Name::Label, Punctuation, Text, Punctuation push :expr_start end end