---
title: "HTML To Markdown: list, link and code fixes in PHP | VulCode"
description: "Three fixes to the HTML To Markdown converter in PHP: ordered lists starting at zero, autolinks with an ampersand in the URL and an extra empty line in <pre>."
url: "https://vulcode.com/en/opensource/contributions/html-to-markdown"
lang: "en"
---

[All contributions](https://vulcode.com/en/opensource/contributions)

thephpleague/html-to-markdown

# HTML To Markdown

A PHP library from The PHP League that converts HTML to Markdown, turning lists, links, code blocks and other elements into their Markdown equivalents.

[See the repository](https://github.com/thephpleague/html-to-markdown) [All contributions](https://vulcode.com/en/opensource/contributions)

- **Language**: PHP
- **GitHub stars**: 1,908
- **Merged changes**: 3

## What we changed

Ordered lists with start="0" begin at zero, links with an & in the address become autolinks, and a <pre> block no longer gets an empty first line in the fenced code block.

### What this work shows

- The HTML spec and the libxml parser

- Markdown syntax: autolinks and code fences

- HTML entities and URL encoding

- PHPUnit tests

What was broken

### A list starting at zero began at one

<ol start="0"> is valid HTML and CommonMark supports lists starting at zero, but the converter numbered such a list from 1. The check built on intval() treated 0 the same as a missing attribute, because in PHP both are falsy.

How we fixed it

### is_numeric instead of a truthiness check

ListItemConverter now checks the attribute with is_numeric(), which is false for an empty string and true for "0". A list from zero gives 0. and 1., and other values such as start="120" work as before.

[#277](https://github.com/thephpleague/html-to-markdown/pull/277)

What was broken

### A link with & did not become an autolink

With use_autolinks, the converter writes a link as <address> when its text matches the href. The text goes through htmlspecialchars, though, so & became &amp;, the comparison failed and the output was a plain link with &amp; in its text.

How we fixed it

### Comparing after undoing &amp;

Before comparing, we undo only &amp; back to &, so https://example.com/?a=1&b=2 gives an autolink. Other encoding differences, such as %2F against /, still give a plain link, and a test also covers an address with &lt; and &gt; entities.

[#281](https://github.com/thephpleague/html-to-markdown/pull/281)

What was broken

### An empty line at the top of a code block

The HTML spec says a newline right after the <pre> start tag is dropped, but the libxml parser keeps it. The fenced code block in Markdown got an extra empty first line as a result.

How we fixed it

### One leading newline dropped

PreformattedConverter strips one leading newline, CRLF included, before building the code block. It does so only there and not in getContent(), because a <pre> kept as raw HTML loses that newline when rendered. We also updated old testPreformat expectations that had pinned the bug.

[#278](https://github.com/thephpleague/html-to-markdown/pull/278)

## Merged changes 3

- [#281 fix: use autolinks for URLs that contain an ampersand Merged 18 October 2026](https://github.com/thephpleague/html-to-markdown/pull/281)

- [#278 fix: strip the newline right after the <pre> start tag Merged 18 October 2026](https://github.com/thephpleague/html-to-markdown/pull/278)

- [#277 fix: honor start="0" on ordered lists Merged 7 September 2026](https://github.com/thephpleague/html-to-markdown/pull/277)

## What it taught us

Conversion between formats breaks at the edges: zero treated as a missing value, the &amp; entity compared with a raw &, a newline the HTML spec says to drop. We check each such case against the format's rule and close it with a test.

[More about this technology: PHP](https://vulcode.com/en/technologies/php)

## Other projects we write code for

- [**Composer** PHP · 29,590 stars The dependency manager for PHP: it installs and updates a project's libraries from its composer.json.](https://vulcode.com/en/opensource/contributions/composer)

- [**PHPMailer** PHP · 22,347 stars The classic PHP library for sending email, used by WordPress and many other systems.](https://vulcode.com/en/opensource/contributions/phpmailer)

- [**Monolog** PHP · 21,407 stars A PHP logging library that sends records to files, sockets, inboxes, databases and web services. Symfony and Laravel use it, among others.](https://vulcode.com/en/opensource/contributions/monolog)

- [**Carbon** PHP · 16,583 stars A PHP DateTime extension for working with dates, standard in the Laravel ecosystem.](https://vulcode.com/en/opensource/contributions/carbon)

- [**Whoops** PHP · 13,231 stars A PHP library that turns uncaught exceptions into a readable error page with the stack trace, known from Laravel.](https://vulcode.com/en/opensource/contributions/whoops)

- [**ramsey/uuid** PHP · 12,642 stars A PHP library for generating universally unique identifiers (UUIDs).](https://vulcode.com/en/opensource/contributions/ramsey-uuid)

## Describe your project.

A free quote comes back within an hour during working hours.

### Rather skip the form?

Ask in the chat or write to us directly.

Open the chat

- **Email**: [hello@vulcode.com](mailto:hello@vulcode.com)
- **Phone**: [+48 576 043 920](tel:+48576043920)
- **Discord**: [discord.gg/vulcode](https://discord.gg/vulcode)
