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

<p> inside <a> creates too much whitespace #313

Closed
mfulton26 opened this issue Mar 21, 2020 · 1 comment
Closed

<p> inside <a> creates too much whitespace #313

mfulton26 opened this issue Mar 21, 2020 · 1 comment

Comments

@mfulton26
Copy link

<p><a href="https://github.com/domchristie/turndown">This demonstrates turndown – an HTML to Markdown converter in JavaScript.</a></p>

results in

[This demonstrates turndown – an HTML to Markdown converter in JavaScript.](https://github.com/domchristie/turndown)

while

<a href="https://github.com/domchristie/turndown"><p>This demonstrates turndown – an HTML to Markdown converter in JavaScript.</p></a>

results in

[

This demonstrates turndown – an HTML to Markdown converter in JavaScript.

](https://github.com/domchristie/turndown)

In HTML5, paragraph tags are valid content for anchors tags and while browsers render the HTML snippets above the same Turndown seems to add too much whitespace around the paragraph element when it is a child of an anchor element. They should result in the same markdown without the extra new lines, etc. Thank you.

@domchristie
Copy link
Collaborator

domchristie commented Mar 27, 2020

Yes, conversions of anchors with block-level elements to markdown presents a problem, since it is often not clear how it should be presented. For example, the following is valid but has no markdown equivalent:

<a href="#>
  <h1>Hello world</h1>
  <p>This whole block is linked</p>
</a>

We could link the <h1> and not the paragraph, but other situations might not be so straightforward, so it becomes extremely difficult to cater for every case. (There's even a debate as to whether we should be using block links.)

The best option for now is to add a custom rule as suggested in #278 (comment)

Closing as duplicate of #278

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