Skip to content

Add inline_br option for linebreaks in inline elements#258

Open
TytoCapensis wants to merge 1 commit intomatthewwithanm:developfrom
TytoCapensis:develop
Open

Add inline_br option for linebreaks in inline elements#258
TytoCapensis wants to merge 1 commit intomatthewwithanm:developfrom
TytoCapensis:develop

Conversation

@TytoCapensis
Copy link

@TytoCapensis TytoCapensis commented Mar 16, 2026

Some HTML tables (and generally, other inline elements) may use <br> in table cells. For example:

<table>
<tr>
	<th>User</th>
	<th>Email</th>
</tr>
<tr>
	<td>John Doe</td>
	<td>john.doe@example.com</td>
</tr>
<tr>
	<td>Jane Doe</td>
	<td>jane.doe@example.com<br>jane.doe@example.org</td>
</tr>
</table>

Currently, line breaks with <br> in inline elements are replaced by spaces. The table above is converted to this by markdownify:

| User | Email |
| --- | --- |
| John Doe | john.doe@example.com |
| Jane Doe | jane.doe@example.com jane.doe@example.org |

This is acceptable, but it may lead to confusion in some cases.
There is no official Markdown way to have line-breaks inside cells, but the de-facto standard is to use <br> to manage this:

| User | Email |
| --- | --- |
| John Doe | john.doe@example.com |
| Jane Doe | jane.doe@example.com<br>jane.doe@example.org |

(Note that this also works in GitHub's Markdown)

This pull request adds a inline_br / --inline-br option to keep all inline <br> tags. (This option is disabled by default to not disrupt existing behaviors)

All tests are passing. If I force inline_br on all tests, 2 are failing (because of a <br> conversion, which is expected). Feel free to suggest how this could be integrated in tests!

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 this pull request may close these issues.

1 participant