/
githubmirror
/
marktext
Обзор
Документация
Войти
/
githubmirror
/
marktext
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
packages/muya/src/inlineRenderer/__tests__/referenceLinkImageAnchor.spec.ts
51 строка
2 KB
Ran Luo
fix(muya): follow the link on Ctrl/Cmd-click for reference-linked and raw-HTML linked images (#4865) (#4866)
05 июл 2026, 08:02
Не верифицирован
05 июл 2026, 08:02
67848d7
Код
Авторство
О чём код?
import type { ReferenceLinkToken, Token } from '../types'; import { describe, expect, it } from 'vitest'; import { tokenizer } from '../lexer'; // #4865: a full reference link whose text is an image — `[][ref]`, // the standard README-badge pattern — must tokenize as ONE reference_link // carrying the image as its child. The anchor group used `[^\]]+?`, which // stopped at the image's inner `]`, so the input fragmented into a bare image // plus a separate empty reference link and the image never nested in the link. function toks(src: string): Token[] { const labels = new Map([['ref', { href: 'https://example.com/dst', title: '' }]]); return tokenizer(src, { labels } as Parameters<typeof tokenizer>[1]); } describe('reference link with an image anchor (#4865)', () => { it('tokenizes `[][ref]` as a single reference_link wrapping the image', () => { const result = toks('[][ref]'); expect(result).toHaveLength(1); const link = result[0] as ReferenceLinkToken; expect(link.type).toBe('reference_link'); expect(link.isFullLink).toBe(true); expect(link.label).toBe('ref'); expect(link.children).toHaveLength(1); const image = link.children[0] as Token & { attrs?: { src: string; alt: string } }; expect(image.type).toBe('image'); expect(image.attrs?.src).toBe('https://example.com/badge.svg'); expect(image.attrs?.alt).toBe('alt'); }); it('still tokenizes a plain-text reference link `[text][ref]` unchanged', () => { const result = toks('[text][ref]'); expect(result).toHaveLength(1); const link = result[0] as ReferenceLinkToken; expect(link.type).toBe('reference_link'); expect(link.children).toHaveLength(1); expect(link.children[0].type).toBe('text'); }); it('does not treat `[][ref]` as a link when the ref is undefined', () => { // No matching definition ⇒ not a reference link (CommonMark); the image // stays a standalone image, never a fabricated link. const result = tokenizer('[][missing]'); expect(result.some(t => t.type === 'reference_link')).toBe(false); expect(result.some(t => t.type === 'image')).toBe(true); }); });