Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newlines collapsed with custom converter #119

Closed
hsmallbone opened this issue Oct 19, 2015 · 3 comments
Closed

Newlines collapsed with custom converter #119

hsmallbone opened this issue Oct 19, 2015 · 3 comments

Comments

@hsmallbone
Copy link

I have some HTML which looks like this:

<pre>
<code>
line 1
<br>
<br>
line 2
<br>
<br>
<br>
line 3
</code>
</pre>

and a custom converter like this (using GFM):

                {
                    filter: function (node) {
                        return node.nodeName === 'PRE' &&
                            node.firstChild &&
                            node.firstChild.nodeName === 'CODE';
                    },
                    replacement: function (content, node) {
                        return '```\n' + content + '\n```';
                    }
                }

The end result looks like this:

line 1

line 2

line 3

Instead of having two or three newlines it only keeps one, despite my filter returning the correct number of newlines between each line.

Am I going wrong somewhere in my code or is this a bug or a known issue...?

@hsmallbone hsmallbone changed the title Newlines are being collapsed with custom converter Newlines collapsed with custom converter Oct 19, 2015
@hsmallbone
Copy link
Author

After some investigation it appears to be related to the end of the toMarkdown function, where repeated newlines are collapsed. I'm not sure if that is correct behaviour as in this case it leads to explicit newlines being collapsed but it could be related to the spec?

@domchristie
Copy link
Collaborator

it appears to be related to the end of the toMarkdown function, where repeated newlines are collapsed.

Yes, correct. Repeated newlines are collapsed to tidy up the converted HTML, but as you have pointed out, this approach fails when processing repeated new lines in pre blocks.

Thanks for raising this.

@domchristie
Copy link
Collaborator

This behaviour is fixed in https://github.com/domchristie/turndown which is a rewrite and will supersede this project. Feel free to give it a go, and raise any issues there.

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

No branches or pull requests

2 participants