Alir3z4 / Alir3z4/html2text

Ampersand in link causes different markdown to be generated vs. non-ampersand link

未关闭
#441 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
2.2k
派生
296
PR 合并指标
30 天内没有已合并 PR

描述

Version: `html2text==2025.4.15`.

I want to rely on the behavior where `http://link/` gets rendered in Markdown as ``.

Unfortunately if the link contains an ampersand it renders using `[link](link)`, despite the link and text being exactly the same:

```python
>>> from html2text import HTML2Text as H
>>> h = H()

# good!
>>> h.handle('https://foo/')
'\n\n'

# an ampersand in the URL causes []() link syntax, but I guess that's expected since "&y" turns into "&y;"
>>> h.handle('https://foo/?x=1&y=2')
'[https://foo/?x=1&y;=2](https://foo/?x=1&y=2)\n\n'

# but even when & is escaped, and both link and text end up being exactly the same string, []() is still generated for the link
>>> h.handle('https://foo/?x=1&y=2')
'[https://foo/?x=1&y=2](https://foo/?x=1&y=2)\n\n'
```

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。