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
GFM Enhancements (Backticks) #132
Conversation
jaswrks
commented
Sep 23, 2013
- Adding support for GFM backticks (for fenced code blocks); in additional to ~~~ already supported in Markdown Extra.
- Adding support for GFM language marker with fenced code blocks.
- Adding support for GFM backticks ``` (for fenced code blocks); in additional to ~~~ already supported in Markdown Extra. - Adding support for GFM language marker; e.g. ```php
|
Hi Michel :-) I think the modifications I made (just minor tweaks); should get GFM-style code blocks working in Markdown Extra. If there are any problems, please let me know. I will be MORE than happy to adjust further and/or conform in any what that you deem necessary. Thanks for reviewing my pull request! :-) It is now possible to do this in Markdown ExtraAlso supports language specification (resulting in
|
|
The HTML lang attribute is not intended for programming languages. Quoting HTML5:
Thus, "php" is an invalid value for attribute lang (not a BCP 47 language tag). Also, your language specification syntax is a conflicting subset of the optional standalone class name attribute syntax for a code block, which already works and is intended for the same purpose (identify the code's language), and also works similarly to other Markdown parsers out there. Both cannot coexist peacefully. I'm also concerned by that you allow mixing backticks with tildes when writing a fence. It should be one or the other, mixing not allowed. Try replacing |
Yes, I agree on not mixing these together. Sorry, I overlooked that before. I updated this in my last commit per your instructions and tested this myself again to be sure it's all still working as expected. Looks great!
I agree on this also (e.g. The reason I would like to see this in your lib.This will NOT work as expected; e.g. GFM-style fenced code blocks; where the language is used commonly here at GitHub. Without the addition I propose, this will not work. With the latest change I propose.
Please correct me if I'm wrong, but I think they can. The existing implementation requires whitespace and a dotted notation; or curly brackets. The addition that I made allows the existing implementation/syntax to remain fully functional but also allows for the optional language specifier used with GFM-style fenced code blocks. I can confirm that all of the following tests work as expected. This works because the language specifier CANNOT be preceded by whitespace, and it may NOT contain a dot That being said, if you just don't want this in there, please let me know and I'll take it out :-) Thanks Michel! |
|
Update: I see the whitespace and dot are actually both optional in the existing implementation Hmm, it would be nice if the whitespace were required (e.g. I'll leave this for a couple days for your review; otherwise I'll take out the language specifier completely unless you can think of a way to make it work effectively. |
|
The syntax allowing for a class class name is already intended to be a language specifier. We can't have two different syntaxes for the language specifier that differ only by one whitespace, that'd be too error-prone. If you need the language specifier in the output to be more explicit, you can set the If you need the language specifier to be something else in the output, then maybe we could add a configuration variable for that (if you can explain why the current output fails you). But that's a separate matter that should have nothing to do with Github-style code blocks. |
Removing the additional code that I applied previously to implement the `data-lang` attribute. In retrospect, this was a bad idea; as the existing implementation does a good job with this already when used properly. Many thanks to Michel Fortin for his help in accomplishing these changes :-) I hope this might be merged into the official copy at some point in the future.
|
Hi Michel. My latest commit removed the extra code I added previously to deal with https://github.com/JasWSInc/php-markdown/commit/ab786ae1d5f8d83ff661fb1dd5a78f07a27c8e8b Removing the additional code that I applied previously to implement the Many thanks to Michel Fortin for the help in accomplishing these changes :-) I hope what is now just very MINOR tweaks; might be merged into the official copy at some point in the future. |
|
Looks good. I'll merge this for the next release. |
|
Excellent news. Thank you Michel :-) |
|
I had a problem with markdown that mixes code span marker (single backtick) and code block (three backticks)... you might want to add a guard in function _hashHTMLBlocks_inMarkdown(). See forked example. Hope this helps! |
|
@markseu Unfortunately, code spans can have markers of any length, so It's a good observation. I think this pull request has the same problem: it'll give priority to code spans in the HTML block parser. We might need to check for fenced code blocks first, and also be more stringent about matching them in a way that lets legitimate code spans pass through. Hard problem. |
|
@michelf Let me know how to help. I would be happy if PHP Markdown Extra (1.2.7 or later) adds GFM backticks and I can delete my fork. |
|
We really need this. |
|
@alrik11es I'm of the same opinion. We need this. Here's my plan:
I've reserved some time for this this week. |
|
Ok, so this is now merged. Rejoice! :-) As a followup, in d6ed0d0 I fixed an issue where the HTML block parser was matching backtick fenced code blocks as code spans. This was most of the time inconsequential, as the HTML block parser treats the same way the content of a code span as it does with a code block. But if you had a marker-like backticks run somewhere in your code block it could cause problems. |
|
Works great, thank you! |