Skip to content
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

img path error at hexo@7.2.0 using markdown #281

Open
6 tasks done
W4y2Sh3ll opened this issue Apr 21, 2024 · 4 comments · May be fixed by hexojs/hexo#5481
Open
6 tasks done

img path error at hexo@7.2.0 using markdown #281

W4y2Sh3ll opened this issue Apr 21, 2024 · 4 comments · May be fixed by hexojs/hexo#5481

Comments

@W4y2Sh3ll
Copy link

Check List

  • I have already read README.
  • I have already searched existing issues and they are not help to me.
  • I examined error or warning messages and it's difficult to solve.
  • I am using the latest version of this repository.
  • I am using the latest version of Hexo.
  • My Node.js is matched the required version.

Describe the bug

image

Expected behavior

image

How to reproduce

image(href, title, text) {
    const { hexo, options } = this;
    const { relative_link } = hexo.config;
    const { lazyload, figcaption, prependRoot, postPath } = options;

    if (!/^(#|\/\/|http(s)?:)/.test(href) && !relative_link && prependRoot) {
      if (!href.startsWith('/') && !href.startsWith('\\') && postPath) {
        const PostAsset = hexo.model('PostAsset');
        // findById requires forward slash
        console.log(PostAsset);
        console.log(postPath);
        const asset = PostAsset.findById(join(postPath, href.replace(/\\/g, '/')));
        // asset.path is backward slash in Windows
        if (asset) href = asset.path.replace(/\\/g, '/');
      }
      href = url_for.call(hexo, href);
    }

    let out = `<img src="${encodeURL(href)}"`;
    if (text) out += ` alt="${text}"`;
    if (title) out += ` title="${title}"`;
    if (lazyload) out += ' loading="lazy"';

    out += '>';
    if (figcaption && text) {
      return `<figure>${out}<figcaption aria-hidden="true">${text}</figcaption></figure>`;
    }
    console.log(out);
    return out;
  }

I found in hexo@7.2.0 all PostAsset's path is divided only by double backslash , So

const asset = PostAsset.findById(join(postPath, href.replace(/\\/g, '/')));

can't find a correct asset

Screenshots

No response

Environment information

Windows 10
Node v21.7.3
Hexo@7.2.0

Additional context

No response

@stevenjoezhang
Copy link
Member

Hexo 7.2.0 version has altered the handling of backslash escaping for the id attribute, and it seems its impact is broader than expected, making it difficult for plugins to maintain compatibility across multiple Hexo versions. We might need to consider reverting these changes.

@DexterMorgan0417
Copy link

yes,I have the same problem,how to slove it?

@W4y2Sh3ll
Copy link
Author

W4y2Sh3ll commented Apr 29, 2024

yes,I have the same problem,how to slove it?

downgrade hexo to 7.1.1

@DexterMorgan0417
Copy link

yes,I have the same problem,how to slove it?

downgrade hexo to 7.1.1

If I want to make the .md and the picture in the same path,is there have any method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants