Skip to content

Commit

Permalink
fix(glow): handle inline /* ... */ comment
Browse files Browse the repository at this point in the history
  • Loading branch information
maurice committed Jan 27, 2025
1 parent e7cf831 commit e65b06c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/glow/src/glow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },

Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions packages/glow/test/glow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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</* name */ string, /* hex */ string> = {};')
expect(html).toInclude('Record<i>&lt;</i><sup>/* name */</sup> <strong>string</strong><i>,</i> <sup>/* hex */</sup> <strong>string</strong><i>&gt;</i>')
})


/* prefix and mark */
test('disable mark', () => {
Expand Down

0 comments on commit e65b06c

Please sign in to comment.