Skip to content

<br> tags within <pre><code>...</code></pre> tags don't get converted to newlines#514

Description

@Corion

When using a contentEditable element, the browser (Firefox) inserts <br> tags when the Enter key is pressed. This results in HTML like the following:

<div><pre><code>First line<br>Second line<br>Third line</code></pre></div>

This is currently converted to

First lineSecond lineThird line

Expected is

    First line
    Second line
    Third line

I've added the following test cases to the index.html test suite:

<div class="case" data-name="pre/code block with newline as &lt;br&gt; tag">
  <div class="input"><div><pre><code>First line<br>Second line<br>Third line</code></pre></div></div>

  <pre class="expected">    First line
    Second line
    Third line</pre>
</div>

<div class="case" data-name="fenced pre/code block with newline as &lt;br&gt; tag" data-options='{"codeBlockStyle": "fenced"}'>
  <div class="input"><div><pre><code>First line<br>Second line<br>Third line</code></pre></div></div>

  <pre class="expected">```
First line
Second line
Third line
```</pre>
</div>

The fix for my Perl port of turndown is at Corion/Text-HTML-Turndown@a28a2a9 , for comparison / inspiration

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions