markdown-plain-text.client.spec.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { describe, expect, it } from 'vitest'
  2. import { extractMarkdownPlainText } from '@deepseek-ai/dsh-client-ui-primitives'
  3. const MARKDOWN = [
  4. '# Release notes',
  5. '',
  6. 'First **paragraph** with [a link](https://example.com) and ![diagram](diagram.png).',
  7. '',
  8. '- shipped',
  9. '- `verified`',
  10. '',
  11. '```ts',
  12. 'const ready = true',
  13. '```',
  14. ].join('\n')
  15. describe('extractMarkdownPlainText', () => {
  16. it('projects the complete GFM document without presentation syntax', () => {
  17. expect(extractMarkdownPlainText(MARKDOWN)).toBe([
  18. 'Release notes',
  19. '',
  20. 'First paragraph with a link and diagram.',
  21. '',
  22. 'shipped',
  23. 'verified',
  24. '',
  25. 'const ready = true',
  26. ].join('\n'))
  27. })
  28. it('selects the first visible line or first semantic paragraph', () => {
  29. expect(extractMarkdownPlainText(MARKDOWN, { mode: 'first-line' })).toBe('Release notes')
  30. expect(extractMarkdownPlainText(MARKDOWN, { mode: 'first-paragraph' }))
  31. .toBe('First paragraph with a link and diagram.')
  32. })
  33. it('preserves raw HTML while removing Markdown presentation markup', () => {
  34. const block = [
  35. '<background-job-complete id="trajectory-ui-watch">',
  36. 'Command: pnpm test',
  37. 'Exit code: 0',
  38. '</background-job-complete>',
  39. ].join('\n')
  40. expect(extractMarkdownPlainText(block)).toBe(block)
  41. expect(extractMarkdownPlainText('**Status:** <span data-state="ok">ready</span>'))
  42. .toBe('Status: <span data-state="ok">ready</span>')
  43. expect(extractMarkdownPlainText(block, { mode: 'first-paragraph' }))
  44. .toBe('<background-job-complete id="trajectory-ui-watch">')
  45. })
  46. it('projects GFM tables, references, hard breaks, and block structure', () => {
  47. const markdown = [
  48. '> first\\',
  49. '> second with ![diagram][asset] and <span>visible</span>',
  50. '',
  51. '---',
  52. '',
  53. '| Name | Value |',
  54. '| --- | --- |',
  55. '| alpha | `1` |',
  56. '',
  57. '[asset]: diagram.png',
  58. ].join('\n')
  59. expect(extractMarkdownPlainText(markdown)).toBe([
  60. 'first second with diagram and <span>visible</span>',
  61. '',
  62. 'Name\tValue',
  63. 'alpha\t1',
  64. ].join('\n'))
  65. })
  66. })