1+ import fs from 'fs'
2+ import os from 'os'
3+ import path from 'path'
4+ import { describe , it , expect } from 'vitest'
5+ import { compileMdx } from './compile-mdx.server.js'
6+
7+ // Disposable object for temporary files
8+ function createTempFile ( name : string , content : string ) {
9+ const tempDir = os . tmpdir ( )
10+ const testFile = path . join ( tempDir , name )
11+ fs . writeFileSync ( testFile , content )
12+
13+ return {
14+ path : testFile ,
15+ [ Symbol . dispose ] ( ) {
16+ try {
17+ fs . unlinkSync ( testFile )
18+ } catch {
19+ // Ignore cleanup errors
20+ }
21+ }
22+ }
23+ }
24+
25+ describe ( 'compileMdx title parsing' , ( ) => {
26+ it ( 'should extract title with backticks correctly' , async ( ) => {
27+ // Create a temporary MDX file with backticks in title
28+ const testMdxContent = `# Title with \`something\` highlighted
29+
30+ This is some content.
31+ `
32+
33+ using tempFile = createTempFile ( 'test-backtick-title.mdx' , testMdxContent )
34+
35+ const result = await compileMdx ( tempFile . path )
36+
37+ // The title should be extracted correctly, preserving the full text
38+ expect ( result . title ) . toBe ( 'Title with `something` highlighted' )
39+ } )
40+
41+ it ( 'should extract title with multiple backticks correctly' , async ( ) => {
42+ const testMdxContent = `# \`Code\` and \`more code\` in title
43+
44+ This is some content.
45+ `
46+
47+ using tempFile = createTempFile ( 'test-multiple-backticks.mdx' , testMdxContent )
48+
49+ const result = await compileMdx ( tempFile . path )
50+
51+ expect ( result . title ) . toBe ( '`Code` and `more code` in title' )
52+ } )
53+
54+ it ( 'should extract title with mixed markdown correctly' , async ( ) => {
55+ const testMdxContent = `# Title with \`code\` and **bold** text
56+
57+ This is some content.
58+ `
59+
60+ using tempFile = createTempFile ( 'test-mixed-markdown.mdx' , testMdxContent )
61+
62+ const result = await compileMdx ( tempFile . path )
63+
64+ // Bold formatting should be stripped, but backticks preserved
65+ expect ( result . title ) . toBe ( 'Title with `code` and bold text' )
66+ } )
67+ } )
0 commit comments