-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📐 Replace xref text when using angle brackets (#1183)
Co-authored-by: Rowan Cockett <rowanc1@gmail.com>
- Loading branch information
Showing
4 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'myst-transforms': patch | ||
--- | ||
|
||
Replace xref text when using angle brackets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { describe, expect, test } from 'vitest'; | ||
import { VFile } from 'vfile'; | ||
import type { Link, ResolvedExternalReference } from './types'; | ||
import { MystTransformer } from './myst'; | ||
import { linksTransform } from './plugin'; | ||
|
||
export const TEST_REFERENCES: ResolvedExternalReference[] = [ | ||
{ | ||
key: 'myst-ref', | ||
url: 'https://example.com/myst-ref', | ||
kind: 'myst', | ||
value: { | ||
version: '1', | ||
myst: '1.2.0', | ||
references: [ | ||
{ | ||
identifier: 'explicit-figure', | ||
kind: 'figure', | ||
data: '/my-figure.json', | ||
url: '/my-figure', | ||
}, | ||
], | ||
}, | ||
}, | ||
]; | ||
|
||
describe('Link Plugin Transformer', () => { | ||
test('link text is matched', async () => { | ||
const file = new VFile(); | ||
const t = new MystTransformer(TEST_REFERENCES); | ||
|
||
const link: Link = { | ||
type: 'link', | ||
url: `xref:myst-ref#explicit-figure`, | ||
children: [{ type: 'text', value: 'xref:myst-ref#explicit-figure' }], | ||
}; | ||
linksTransform({ type: 'root', children: [link] }, file, { transformers: [t] }); | ||
expect(file.messages.length).toEqual(0); | ||
expect(link.internal).toBe(false); | ||
expect(link.url).toEqual('https://example.com/myst-ref/my-figure'); | ||
expect(link.dataUrl).toEqual('https://example.com/myst-ref/my-figure.json'); | ||
expect(link.type).toEqual('crossReference'); | ||
expect((link as any).remote).toBe(true); | ||
expect((link as any).identifier).toEqual('explicit-figure'); | ||
expect((link as any).label).toEqual('explicit-figure'); | ||
expect(link.children).toEqual([]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters