tokenizer 方法获取文件路径出错
kemaosen opened this issue · comments
KMS 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;
}
},
why520crazy commented
这是一个兼容性的缺陷,我使用的是Mac系统。
KMS commented
好的,谢谢你
why520crazy commented
通过 getSystemPath 最终转化一下文件路径即可,我尽快修复
KMS commented
好的(•̤̀ᵕ•̤́๑)ᵒᵏᵎᵎᵎᵎ
…---- 回复的原邮件 ----
| 发件人 | ***@***.***> |
| 日期 | 2022年07月16日 17:05 |
| 收件人 | ***@***.***> |
| 抄送至 | ***@***.******@***.***> |
| 主题 | Re: [docgeni/docgeni] tokenizer 方法获取文件路径出错 (Issue #376) |
通过 getSystemPath 最终转化一下文件路径即可,我尽快修复
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>