@@ -2,7 +2,13 @@ import {bold} from 'chalk';
2
2
import Token from 'markdown-it/lib/token' ;
3
3
4
4
import { StateCore } from '../../typings' ;
5
- import { GetFileTokensOpts , getFileTokens , getFullIncludePath , isFileExists } from '../../utilsFS' ;
5
+ import {
6
+ GetFileTokensOpts ,
7
+ getFileTokens ,
8
+ getFullIncludePath ,
9
+ getRealPath ,
10
+ isFileExists ,
11
+ } from '../../utilsFS' ;
6
12
import { findBlockTokens } from '../../utils' ;
7
13
import { MarkdownItPluginCb , MarkdownItPluginOpts } from '../typings' ;
8
14
@@ -44,20 +50,22 @@ function unfoldIncludes(md: MarkdownItIncluded, state: StateCore, path: string,
44
50
45
51
const fullIncludePath = getFullIncludePath ( includePath , root , path ) ;
46
52
47
- let pathname = fullIncludePath ;
48
- let hash = '' ;
49
- const hashIndex = fullIncludePath . lastIndexOf ( '#' ) ;
50
- if ( hashIndex > - 1 && ! isFileExists ( pathname ) ) {
51
- pathname = fullIncludePath . slice ( 0 , hashIndex ) ;
52
- hash = fullIncludePath . slice ( hashIndex + 1 ) ;
53
- }
53
+ // Check the real path of the file in case of a symlink
54
+ let pathname = getRealPath ( fullIncludePath ) ;
54
55
55
56
if ( ! pathname . startsWith ( root ) ) {
56
57
i ++ ;
57
58
58
59
continue ;
59
60
}
60
61
62
+ let hash = '' ;
63
+ const hashIndex = fullIncludePath . lastIndexOf ( '#' ) ;
64
+ if ( hashIndex > - 1 && ! isFileExists ( pathname ) ) {
65
+ pathname = fullIncludePath . slice ( 0 , hashIndex ) ;
66
+ hash = fullIncludePath . slice ( hashIndex + 1 ) ;
67
+ }
68
+
61
69
// Check the existed included store and extract it
62
70
const included = md . included ?. [ pathname ] ;
63
71
0 commit comments