-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Another bug about #2733 #3487
Comments
Can you create a repo that can reproduce this? I don't know what you mean by "opened ./d.efg twice" marked does not do anything different if you open a file. |
Here is a repo: https://github.com/CNOCTAVE/marked_reader |
In Markdown, ./-style relative path is common. When in Electron(a Node.js-based framework), Electron always parse ./ path as Node path, so ./ path should be rewritten to absolute path. This repo is a Markdown reader, user should open a local Markdown file. To make that bug clearer, you can write a picture path as relative path, if picture cannot correctly shows out, that's bug! |
You are adding the walkTokens function everytime they open a file. You should only be adding it once: import { marked } from "marked";
function walkTokens(token) {
if (token.type === 'image' || token.type === 'link') {
token.href = markdownDir + ("/" + token.href).replace("//", "/").replace("\\", "/").replace("%5C", "/").replace("./", "/"); // 修正相对路径
}
}
marked.use({ walkTokens }); or you can use an instance to not have the extensions be global import { Marked } from "marked";
...
ipcMain.on('render-markdown', (event, filePath) => {
...
function walkTokens(token) {
if (token.type === 'image' || token.type === 'link') {
token.href = markdownDir + ("/" + token.href).replace("//", "/").replace("\\", "/").replace("%5C", "/").replace("./", "/"); // 修正相对路径
}
}
const marked = new Marked();
marked.use({ walkTokens });
const htmlContent = marked.parse(markdownContent);
event.reply('markdown-rendered', htmlContent);
}); |
Can you PR to https://github.com/CNOCTAVE/marked_reader to show your modified code? It doesn't work for me. |
use |
Now the bug is gone after using marked.parse(...). |
Marked version:
14.1.2
Describe the bug
In #2733, someone gave out a function walkTokens(token). But this workaroound has another bug, it will repeatedly change URL.
To Reproduce
For example, if a file is ./d.efg located at C:/abc/,
if I opened ./d.efg once, the result will become C:/abc/d.efg (correct),
if I opened ./d.efg twice, the result will become C:/abc/C:/abc/d.efg (incorrect).
Expected behavior
marker.use() ( here is marker.use( { walkTokens(token) } ) ) should be non-state.
The text was updated successfully, but these errors were encountered: