11import {
22 type DocItem ,
3+ getLocalImagePath ,
34 getNavigationForOriginalSlug ,
45} from '@/service/directory-service' ;
5- import { getLocalImagePath } from '@/service/directory-service' ;
66import { transformFilesLink } from '@/service/path-utils' ;
77import type {
88 Code ,
99 Heading ,
10- Html ,
1110 Image ,
1211 Link ,
1312 Node ,
@@ -18,17 +17,12 @@ import type {
1817 RootContent ,
1918 Text ,
2019} from 'mdast' ;
21- import { compact } from 'mdast-util-compact ' ;
20+ import type { HugoShortcodeElement } from 'mdast-util-md-hugo-marker ' ;
2221import {
2322 hugoShortcodeFromMarkdown ,
2423 hugoShortcodeToMarkdown ,
2524} from 'mdast-util-md-hugo-marker' ;
26- import type {
27- HugoShortcodeArgument ,
28- HugoShortcodeElement ,
29- } from 'mdast-util-md-hugo-marker' ;
3025import { hugoShortcode } from 'micromark-extension-md-hugo-marker' ;
31- import type { Plugin } from 'unified' ;
3226import { SKIP , visit } from 'unist-util-visit' ;
3327import { getNonSelfClosingElements } from './utils' ;
3428
@@ -246,23 +240,21 @@ function transformNormalLink(
246240export function transformHugoShortcodeLinks ( tree : Root ) : void {
247241 visit ( tree , ( node : Node , index ?: number , parent ?: Parent ) => {
248242 const hugoNode = node as any ;
249- //console.log("hugoNode: ", JSON.stringify(hugoNode, null, 2));
250243 if (
251244 hugoNode . type === 'hugoShortcode-Link-Href' &&
252245 parent &&
253246 typeof index === 'number'
254247 ) {
255- // console.log("hugoNode: ", JSON.stringify(hugoNode, null, 2));
256-
257248 const siblings = parent . children as unknown as Text [ ] ;
258249 const prevSibling = siblings [ index - 1 ] as unknown as Text ;
259- const nextSibling = siblings [ index + 1 ] as unknown as Text ;
250+ const nextSibling = siblings [ index + 1 ] as unknown as Text | undefined ;
260251
261- const originalNextSiblingValue = nextSibling . value ;
262- const endBrackIndex = nextSibling . value ?. indexOf ( ')' ) ?? - 1 ;
252+ const originalNextSiblingValue = nextSibling ? .value ;
253+ const endBrackIndex = nextSibling ? .value ?. indexOf ( ')' ) ?? - 1 ;
263254
264255 // 检查前后邻居是否为text节点且符合特定模式
265256 if (
257+ originalNextSiblingValue &&
266258 prevSibling ?. type === 'text' &&
267259 nextSibling ?. type === 'text' &&
268260 prevSibling . value ?. endsWith ( '](' ) &&
0 commit comments