Skip to content

Commit b39ace3

Browse files
authored
Markdown: handle unicode list markers (#257)
1 parent 3fc44e2 commit b39ace3

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/components/Markdown/Markdown.test.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,22 @@ describe('Markdown lists', () => {
239239
expect(codeBlock).toBeDefined()
240240
expect(codeBlock?.textContent).toContain('console.log("Nested code")')
241241
})
242+
243+
it('renders a list with unicode dash –', () => {
244+
const text = '– Item 1\n– Item 2\n– Item 3\n\n'
245+
const { getByText } = render(<Markdown text={text} />)
246+
expect(getByText('Item 1')).toBeDefined()
247+
expect(getByText('Item 2')).toBeDefined()
248+
expect(getByText('Item 3')).toBeDefined()
249+
})
250+
251+
it('renders a list with unicode dot •', () => {
252+
const text = '• Item 1\n• Item 2\n• Item 3\n\n'
253+
const { getByText } = render(<Markdown text={text} />)
254+
expect(getByText('Item 1')).toBeDefined()
255+
expect(getByText('Item 2')).toBeDefined()
256+
expect(getByText('Item 3')).toBeDefined()
257+
})
242258
})
243259

244260
describe('Markdown with nested elements', () => {

src/components/Markdown/Markdown.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function parseMarkdown(text: string): Token[] {
6767
}
6868

6969
// List (ordered or unordered)
70-
const listMatch = /^(\s*)([-*+]|\d+\.)\s+(.*)/.exec(line)
70+
const listMatch = /^(\s*)([-*+]|\d+\.)\s+(.*)/.exec(line)
7171
if (listMatch !== null) {
7272
if (!(1 in listMatch) || !(2 in listMatch)) {
7373
throw new Error('Missing entries in regex matches')
@@ -109,7 +109,7 @@ function parseMarkdown(text: string): Token[] {
109109
if (ln.startsWith('```')) break // code block
110110
if (ln.startsWith('>')) break // blockquote
111111
if (/^(#{1,6})\s+/.test(ln)) break // heading
112-
if (/^(\s*)([-*+]|\d+\.)\s+/.test(ln)) break // list item
112+
if (/^(\s*)([-*+]|\d+\.)\s+/.test(ln)) break // list item
113113

114114
paraLines.push(ln)
115115
i++
@@ -137,7 +137,7 @@ function parseList(lines: string[], start: number, baseIndent: number): [Token[]
137137
}
138138

139139
// This matches a new top-level bullet/number for the list
140-
const match = /^(\s*)([-*+]|\d+\.)\s+(.*)/.exec(line)
140+
const match = /^(\s*)([-*+]|\d+\.)\s+(.*)/.exec(line)
141141
// If we don't find a bullet/number at the same indent, break out
142142
if (match === null || !(1 in match) || match[1].length !== baseIndent || !(3 in match)) {
143143
break
@@ -186,7 +186,7 @@ function parseList(lines: string[], start: number, baseIndent: number): [Token[]
186186
}
187187

188188
// Check for nested list
189-
const sublistMatch = /^(\s*)([-*+]|\d+\.)\s+(.*)/.exec(subline)
189+
const sublistMatch = /^(\s*)([-*+]|\d+\.)\s+(.*)/.exec(subline)
190190
if (sublistMatch && 1 in sublistMatch && sublistMatch[1].length > baseIndent && 2 in sublistMatch) {
191191
const newBaseIndent = sublistMatch[1].length
192192
const ordered = /^\d+\./.test(sublistMatch[2])

0 commit comments

Comments
 (0)