thephpleague / html-to-markdown

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

Support for single backtick code blocks #140

Closed dotstormz closed 6 years ago

dotstormz commented 6 years ago

The code places a single backtick for a code block on a single line, however in the spec I cannot find an example of this. The single backtick is not being interpreted correctly by cebe/markdown as it is expecting 3 backticks.

Can someone please link me to the relevant spec and paragraph that outlines the use of a single backtick is accepted markdown as per this spec? http://spec.commonmark.org/0.27/#fenced-code-blocks

https://github.com/thephpleague/html-to-markdown/blob/7f98188f9722dadb88d96603eac76b45900bf33e/src/Converter/PreformattedConverter.php#L46

andreskrey commented 6 years ago

I made that change and we agreed with @colinodell to use single backticks for single lines and three backticks for multiple lines.

https://github.com/thephpleague/html-to-markdown/pull/102#issuecomment-252667025

To be honest I can't find anywhere in the specs that allows this ¯\_(ツ)_/¯

Maybe we should rollback if the aim of the project is to be 100% aligned with the Commonmark spec.

FYI, you're link is outdated. Latest version is 0.28: http://spec.commonmark.org/0.28/

dotstormz commented 6 years ago

@andreskrey No problem I'm sure that my wishes don't need to influence an entire project ;) I just noticed that that particular change wasn't reflected in other libraries such as the cebe/markdown implementation. All good though, that's why we can extend most markdown parsers I guess. Perhaps there could be a configuration option? We would much rather use the official repo than have to fork.

colinodell commented 6 years ago

Single backticks are valid - these represent inline "code spans": http://spec.commonmark.org/0.28/#code-spans

However, there's nothing in the spec that says a single line of code must (or should) be represented by an inline code span - that's really just a preference we've implemented in #102.

I'm not opposed to making this a configuration option :)