Skip to content

Commit 7bfe28c

Browse files
authored
Fix markdown list immediately after paragraph (#252)
1 parent 24b54d8 commit 7bfe28c

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,27 @@
5454
},
5555
"dependencies": {
5656
"hightable": "0.16.0",
57-
"hyparquet": "1.14.0",
57+
"hyparquet": "1.15.0",
5858
"hyparquet-compressors": "1.1.1",
5959
"icebird": "0.3.0",
6060
"react": "18.3.1",
6161
"react-dom": "18.3.1"
6262
},
6363
"devDependencies": {
64-
"@eslint/js": "9.27.0",
64+
"@eslint/js": "9.28.0",
6565
"@storybook/addon-essentials": "8.6.14",
6666
"@storybook/addon-interactions": "8.6.14",
6767
"@storybook/blocks": "8.6.14",
6868
"@storybook/react": "8.6.14",
6969
"@storybook/react-vite": "8.6.14",
7070
"@storybook/test": "8.6.14",
7171
"@testing-library/react": "16.3.0",
72-
"@types/node": "22.15.21",
73-
"@types/react": "19.1.5",
72+
"@types/node": "22.15.29",
73+
"@types/react": "19.1.6",
7474
"@types/react-dom": "19.1.5",
7575
"@vitejs/plugin-react": "4.5.0",
7676
"@vitest/coverage-v8": "3.1.4",
77-
"eslint": "9.27.0",
77+
"eslint": "9.28.0",
7878
"eslint-plugin-react": "7.37.5",
7979
"eslint-plugin-react-hooks": "5.2.0",
8080
"eslint-plugin-react-refresh": "0.4.20",
@@ -85,7 +85,7 @@
8585
"npm-run-all": "4.1.5",
8686
"storybook": "8.6.14",
8787
"typescript": "5.8.3",
88-
"typescript-eslint": "8.32.1",
88+
"typescript-eslint": "8.33.0",
8989
"vite": "6.3.5",
9090
"vitest": "3.1.4"
9191
},

src/components/Markdown/Markdown.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,15 @@ describe('Markdown with nested elements', () => {
351351
expect(container.textContent).toBe('[link]')
352352
expect(container.querySelector('a')).toBeNull()
353353
})
354+
355+
it('renders a list immediately after a paragraph', () => {
356+
const text = 'List:\n - First\n - Second'
357+
const { getByText } = render(<Markdown text={text} />)
358+
expect(getByText('First')).toBeDefined()
359+
expect(getByText('Second')).toBeDefined()
360+
expect(getByText('List:')).toBeDefined()
361+
expect(getByText('List:').tagName).toBe('P')
362+
expect(getByText('First').tagName).toBe('LI')
363+
expect(getByText('Second').tagName).toBe('LI')
364+
})
354365
})

src/components/Markdown/Markdown.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,18 @@ function parseMarkdown(text: string): Token[] {
100100

101101
// Paragraph
102102
const paraLines: string[] = []
103-
while (i < lines.length && lines[i]?.trim() !== '') {
104-
const line = lines[i]
105-
if (line === undefined) {
106-
throw new Error(`Index ${i} not found in lines`)
107-
}
108-
paraLines.push(line)
103+
while (i < lines.length) {
104+
const ln = lines[i]
105+
if (ln === undefined) throw new Error(`Index ${i} not found in lines`)
106+
107+
// stop if we hit a blank line or something that starts its own block
108+
if (!ln.trim()) break
109+
if (ln.startsWith('```')) break // code block
110+
if (ln.startsWith('>')) break // blockquote
111+
if (/^(#{1,6})\s+/.test(ln)) break // heading
112+
if (/^(\s*)([-*+]|\d+\.)\s+/.test(ln)) break // list item
113+
114+
paraLines.push(ln)
109115
i++
110116
}
111117
tokens.push({

0 commit comments

Comments
 (0)