diff --git a/__tests__/unit/node/markdown/plugins/include.test.ts b/__tests__/unit/node/markdown/plugins/include.test.ts index 772106b0..1ca005e3 100644 --- a/__tests__/unit/node/markdown/plugins/include.test.ts +++ b/__tests__/unit/node/markdown/plugins/include.test.ts @@ -628,6 +628,15 @@ describe('node/markdown/plugins/include', () => { ]) }) + test('alert bodies inside includes resolve exactly', async () => { + await write('sub/part.md', '> [!NOTE]\n> body [x](./x)\n') + + const { locs } = await renderLocs('\n') + expect(locs).toEqual([ + { file: path.join(root, 'sub/part.md'), line: 2, column: 8 } + ]) + }) + test('pages without includes get an identity line map', async () => { const { env } = await render('# Hi\n\n[a](./a)\n') expect(env.lineMap!.resolve(2)).toEqual({ diff --git a/__tests__/unit/node/markdown/plugins/sourceAttrs.test.ts b/__tests__/unit/node/markdown/plugins/sourceAttrs.test.ts index cdaa647e..441f4207 100644 --- a/__tests__/unit/node/markdown/plugins/sourceAttrs.test.ts +++ b/__tests__/unit/node/markdown/plugins/sourceAttrs.test.ts @@ -72,6 +72,32 @@ describe('node/markdown/plugins/sourceAttrs', () => { ) }) + test('hand-built wrappers re-emit the attribute', async () => { + const { vueSrc, file } = await renderPage( + { + 'index.md': '::: v-pre\nvp\n:::\n\n::: raw\nrw\n:::\n\n$$\nx^2\n$$\n' + }, + { markdown: { math: true } } + ) + const at = (line: number) => `data-v-inspector="${rel(file)}:${line}:1"` + expect(vueSrc).toContain(`
${title}
\n` + return `${title}
\n` } } diff --git a/src/node/markdown/plugins/preWrapper.ts b/src/node/markdown/plugins/preWrapper.ts index 6b544923..dcdcd1e5 100644 --- a/src/node/markdown/plugins/preWrapper.ts +++ b/src/node/markdown/plugins/preWrapper.ts @@ -1,7 +1,7 @@ import type { MarkdownItAsync } from 'markdown-it-async' import type { MarkdownEnv, MarkdownLocaleOptions } from '../../shared' -import { SOURCE_LOC_ATTR } from './sourceAttrs' +import { popSourceLocAttr } from './sourceAttrs' export interface Options { codeCopyButton: { tooltipText: string; copiedText: string } @@ -43,11 +43,10 @@ export function preWrapperPlugin(md: MarkdownItAsync, options: Options) { localeButton?.copiedText || options.codeCopyButton.copiedText // the fence renderer builds its markup by hand, so the source-location - // attribute is re-emitted on the wrapper - const sourceLoc = token.attrGet(SOURCE_LOC_ATTR) - const sourceLocAttr = sourceLoc - ? ` ${SOURCE_LOC_ATTR}="${md.utils.escapeHtml(sourceLoc)}"` - : '' + // attribute moves onto the wrapper - popped off the token because a + // custom `highlight` may fall back to markdown-it's default fence + // renderer, which does render token attrs + const sourceLocAttr = popSourceLocAttr(md, token) return ( `