docgeni / docgeni

📖 A modern, powerful and out of the box documentation generator for Angular components lib and markdown docs.(现代化的、强大的、开箱即用的 Angular 组件文档生成工具)

Home Page:https://docgeni.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tokenizer 方法获取文件路径出错

kemaosen opened this issue · comments

commented

我在使用组件引入其他的.md文件 报错can't resolve path ./foo.md
查看源码部分:
获取文件路径 absFilePath会有磁盘符D/的形式,导致nodeAbsPath 的路径错误

使用的是windows 老哥你用的苹果么?

 tokenizer(src, tokens) {
        const rule = /^<embed\W*src=['"]([^"']*)\W*\/?>(<\/embed>?)/gi; // Regex for the complete token
        const match = rule.exec(src);
        if (match) {
            const rangeRule = /(#L(\d+)(-L(\d+))?)?$/;
            const rangeMatch = rangeRule.exec(match[1].trim());
            const token = {
                // Token to generate
                type: 'embed',
                raw: match[0],
                src: match[1].trim().replace(rangeRule, ''),
                tokens: []
            };
          console.log('token',token);

          const absFilePath = this.lexer.options['absFilePath'];

          const absDirPath = path.dirname(absFilePath);
          const nodeAbsPath = path.resolve(absDirPath, token.src);


          // absFilePath /D/Project/docgeni-template/docs/guides/index.md
          // nodeAbsPath D:\D\Project\docgeni-template\docs\guides\foo.md
          console.log('absFilePath',absFilePath);
          console.log('nodeAbsPath',nodeAbsPath);


            if (nodeAbsPath !== absFilePath && toolkit_1.toolkit.fs.pathExistsSync(nodeAbsPath)) {
                const content = toolkit_1.toolkit.fs.readFileSync(nodeAbsPath).toString();
                this.lexer.blockTokens(getEmbedBody(content, [parseInt(rangeMatch[2], 10), parseInt(rangeMatch[4], 10)], token.src), token.tokens);
            }
            else {
                token.message = `can't resolve path ${token.src}`;
            }
            return token;
        }
    },

这是一个兼容性的缺陷,我使用的是Mac系统。

commented

好的,谢谢你

通过 getSystemPath 最终转化一下文件路径即可,我尽快修复

commented