Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions ui-packages/web/src/components/markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ type MarkdownVariant = 'reader' | 'chat'
export type MarkdownAnchorProps = {
href?: string
id?: string
'aria-label'?: string
children?: ReactNode
variant: MarkdownVariant
}

export const MarkdownAnchor = ({
href,
id,
'aria-label': label,
children,
variant,
}: MarkdownAnchorProps): ReactElement => {
Expand All @@ -66,6 +68,8 @@ export const MarkdownAnchor = ({
// A footnote links back to its reference by this id. Only the reader follows # links, and
// chat messages would repeat the same footnote ids.
id={variant === 'reader' ? id : undefined}
// A footnote's back link is a bare arrow; its label says where it goes.
aria-label={label}
href={fragment || /^https?:\/\//.test(href ?? '') ? href : undefined}
target={fragment ? undefined : '_blank'}
rel="noopener noreferrer"
Expand All @@ -82,8 +86,8 @@ const createComponents = (variant: MarkdownVariant, images?: MarkdownImageContex
if (!images || !src) return <span className="omitted-image">{fallback}</span>
return <MarkdownImage alt={alt ?? undefined} context={images} fallback={fallback} src={src} />
},
a: ({ href, id, children }) => (
<MarkdownAnchor href={href} id={id} variant={variant}>
a: ({ href, id, 'aria-label': label, children }) => (
<MarkdownAnchor href={href} id={id} aria-label={label} variant={variant}>
{children}
</MarkdownAnchor>
),
Expand Down
12 changes: 7 additions & 5 deletions ui-packages/web/src/features/assistant/xlsx/tools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ describe('sheet_read', () => {
const byNumber = await call(workbook, 'sheet_read', { fileId: 'f', sheet: '2' })
expect(byName).toEqual(byNumber)
expect(byName.sheet).toBe('汇总')
// A block the rows touch is named, so a value is read as covering all of it.
expect(byName.merged).toEqual(['A1:B1'])
expect(
await call(workbook, 'sheet_read', { fileId: 'f', sheet: '汇总', range: 'C1' }),
).not.toHaveProperty('merged')
expect((await call(workbook, 'sheet_read', { fileId: 'f' })).sheet).toBe('数据')
})

it('names the merged blocks the rows touch, whose value covers all of them', async () => {
const touching = await call(workbook, 'sheet_read', { fileId: 'f', sheet: '汇总', range: 'B1' })
expect(touching.merged).toEqual(['A1:B1'])
const apart = await call(workbook, 'sheet_read', { fileId: 'f', sheet: '汇总', range: 'C1' })
expect(apart).not.toHaveProperty('merged')
})

it('refuses a range it cannot read rather than guessing one', async () => {
await expect(call(workbook, 'sheet_read', { fileId: 'f', range: 'sheet1!A1' })).rejects.toThrow(
/A1 notation/,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('Markdown file links', () => {

it('links a footnote back to the reference that cites it', () => {
const { container } = show('Claim[^1].\n\n[^1]: Note.')
const back = screen.getByRole('link', { name: '↩' })
const back = screen.getByRole('link', { name: 'Back to reference 1' })
const target = container.querySelector(`[id="${back.getAttribute('href')?.slice(1)}"]`)
expect(target).toBe(screen.getByRole('link', { name: '1' }))
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ import { resolveFileReferencePath } from '../../../utils/file-reference'
import { useOpenFile } from '../../workspace/workspace-context'
import { useEmbedScope } from './embed-context'

export type FileLinkProps = Pick<ComponentProps<'a'>, 'href' | 'id' | 'children'>
export type FileLinkProps = Pick<ComponentProps<'a'>, 'href' | 'id' | 'aria-label' | 'children'>

export const FileLink = ({ href, id, children }: FileLinkProps): ReactElement => {
export const FileLink = ({
href,
id,
'aria-label': label,
children,
}: FileLinkProps): ReactElement => {
const scope = useEmbedScope()
const openFile = useOpenFile()
if (!scope || !href || /^(?:[a-z][a-z\d+.-]*:|#|\/\/)/i.test(href.trim()))
return (
<MarkdownAnchor href={href} id={id} variant="reader">
<MarkdownAnchor href={href} id={id} aria-label={label} variant="reader">
{children}
</MarkdownAnchor>
)
Expand Down