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

markdown 图片自定义渲染,token.attrGet('alt') 获取不到值 #4607

Closed
4 tasks done
Huangbinghui opened this issue Mar 8, 2025 · 3 comments
Closed
4 tasks done
Labels
bug: pending triage Maybe a bug, waiting for confirmation

Comments

@Huangbinghui
Copy link

Describe the bug

markdown 图片自定义渲染,token.attrGet('alt') 获取不到值。
md.renderer.rules.image = (tokens, idx, options, env, self) => { const token = tokens[idx]; let alt = token.attrGet('alt'); console.log("alt :"+ alt); let result = self.renderToken(tokens, idx, options); if (alt) { result +=\n } return result; }
这段代码alt的值获取不到。

Reproduction

config.js 的markdown配置中配置如下:
md.renderer.rules.image = (tokens, idx, options, env, self) => { const token = tokens[idx]; let alt = token.attrGet('alt'); console.log("alt :"+ alt); let result = self.renderToken(tokens, idx, options); if (alt) { result +=\n } return result; }

Expected behavior

希望可以取到alt属性值。

System Info

System:
    OS: macOS 15.3.1
    CPU: (8) arm64 Apple M1
    Memory: 77.58 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 23.6.0 - ~/.nvm/versions/node/v23.6.0/bin/node
    npm: 10.9.2 - ~/.nvm/versions/node/v23.6.0/bin/npm
    pnpm: 8.15.0 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 133.0.6943.142
    Safari: 18.3
  npmPackages:
    vitepress: ^1.6.3 => 1.6.3

Additional context

No response

Validations

@Huangbinghui Huangbinghui added the bug: pending triage Maybe a bug, waiting for confirmation label Mar 8, 2025
@brc-dd
Copy link
Member

brc-dd commented Mar 8, 2025

use token.content

Image

@brc-dd brc-dd closed this as completed Mar 8, 2025
@Huangbinghui
Copy link
Author

but ,the case is <img src="/page_214_1.png" alt="图 14-1" style="zoom:25%;" />
won't work in this case .

@Huangbinghui
Copy link
Author

could you please share the project of the picture,so i can debug myself。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: pending triage Maybe a bug, waiting for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants