thephpleague / html-to-markdown

Convert HTML to Markdown with PHP
MIT License
1.77k stars 205 forks source link

<code> tags are blocks if inside <pre>, inline otherwise #162

Closed MrPetovan closed 6 years ago

MrPetovan commented 6 years ago

Fixes #26 Fixes #70 Undoes most incompatible behavior of #102 Fixes #140 Fixes #161 Blocks https://github.com/friendica/friendica/pull/5765#issuecomment-422097903

Per the CommonMark spec, single backtick (inline) code blocks produce <p><code>....</code></p> tags without honoring new lines, while multiple backtick (block) code blocks produce <pre><code>...</code></pre> tags, keeping new lines.

Going the other way, we should only convert to a multiple-backticks code block if the <code> tag is inside a <pre> tag. By himself, a HTML <code> tag is inline and doesn't show new lines, only the <pre> tag confers this ability.

This PR also removes references to PHP_EOL where \n was mostly used.

Tests have been updated.

MrPetovan commented 6 years ago

Please disregard the Travis failed check, it's a timeout for the hhvm version.

colinodell commented 6 years ago

This is awesome, thank you so much for the contribution!! :tada:

MrPetovan commented 6 years ago

You're very welcome!