Alir3z4 / Alir3z4/html2text

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

Offen
#441 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
2.2k
Forks
296
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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'
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.