close
Skip to content

Bug: nl2br and toc extensions removes line that come immediatly after [toc] #1160

@cbeauchesne

Description

@cbeauchesne

Issue

On this specific markdown (pay attention to the unique line return after the toc marker)

[TOC]
where am I?

The nl2br and toc extensions used together remove the second line :

import markdown

parser = markdown.Markdown(extensions=['toc', 'nl2br'])

print(parser.convert("[TOC]\nWhere am I?",))

prints :

<div class="toc">
<ul></ul>
</div>

  • Add another \n between the marker and the seconde line, and it's ok.
  • Do not use nl2br, and it's also ok (in this case, the toc is not created, but I guess it's the expected behavior, as [toc] should be a block).

Expected behavior

From what I understand, and regarding previous versions (tested on Markdown==3.1.1), the result should be:

<p>[TOC]<br>
x</p>

Context

  • Python 3.9.6 and Python 3.7.3
  • Markdown==3.3.4
  • both 5.10.25-linuxkit and MacOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBug report.confirmedConfirmed bug report or approved feature request.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions