diff --git a/packages/glow/src/glow.js b/packages/glow/src/glow.js index 46ff3fd1..417b10ac 100644 --- a/packages/glow/src/glow.js +++ b/packages/glow/src/glow.js @@ -39,6 +39,9 @@ const HTML_TAGS = [ // line comment { tag: 'sup', re: /# .+/ }, + + // inline comment + { tag: 'sup', re: /\/\*.*?\*\//g }, { tag: 'label', re: /\[([a-z\-]+)/g, lang: ['md', 'toml'], shift: true }, @@ -239,7 +242,8 @@ export function parseSyntax(lines, lang, prefix = true) { lines.forEach((line, i) => { if (!comment) { - if (comm_start.test(line)) { + const match = comm_start.exec(line) + if (match?.index == 0) { comment = [line] if (comm_end.test(line) && line?.trim() != "'''") endComment() } else { diff --git a/packages/glow/test/glow.test.js b/packages/glow/test/glow.test.js index 13002d59..646c9ac6 100644 --- a/packages/glow/test/glow.test.js +++ b/packages/glow/test/glow.test.js @@ -39,6 +39,11 @@ test('parse JS comment', () => { expect(blocks[2].comment[0]).toEqual('/*') }) +test('parse TS inline comment', () => { + const html = renderRow('const colors: Record = {};') + expect(html).toInclude('Record</* name */ string, /* hex */ string>') +}) + /* prefix and mark */ test('disable mark', () => {