-
-
Notifications
You must be signed in to change notification settings - Fork 279
Added strikethrough syntax to GitHub Flavored Markdown parser #307
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
Conversation
@gettalong Do you require a certain Ubuntu version for Travis?
|
@gettalong Tests are passing on all but Ruby 1.8.7. May I ask why you still support 1.8.7? It's been EOL'd a really long time ago and it's generally A Bad Idea to use it now after a number of years in disrepair. The 1.8.7 error: -<p>I <del>don\342\200\231t even</del>~ have an extra tilde.</p>
+<p>I <del>don’t even</del>~ have an extra tilde.</p> |
/cc @benbalter, for your notes. I have this working. |
@gettalong Do you have time to review this? If not, would you consider adding me as a collaborator? |
@parkr FYI: I have no inside knowledge (but I have confirmed Thomas Leitner for a talk on Tue Feb/23 in Vienna) - as far as I know Thomas might be on skiing vacations - thus, you will need a little patience until you will get a response. |
@geraldb Good to know! Thanks for the update. |
@@ -19,6 +19,7 @@ changes: | |||
* Support for fenced code blocks using three or more backticks has been added. | |||
* Hard line breaks in paragraphs are enforced by default (see option 'hard_wrap'). | |||
* ATX headers need a whitespace character after the hash signs. | |||
* Strikethroughs can be created using two or more tildes surrounding a piece of text |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that only two tildes are only ever used, not "two or more".
@parkr You can ignore the 1.8.7 failure for GFM, this is restriction is only for the main kramdown parser. As why it is still supported: There is currently no reason to not support it in 1.x and there are apparently folks still using 1.8.x. |
@gettalong Updated. I also skipped all GFM tests for 1.8.7. |
Thanks! One more thing: Please combine all GFM strikethrough related commits (ie. all except the one concerning TravisCI) into one commit. |
@parkr After the STRIKETHROUGH_DELIM change the test is failing because whitespace after the initial/before the final delimiter is not correctly handled. Two options: Either restore the original behavior (which is potentially much slower) or look at the emphasis parsing implementation to see how to handle this situation. |
Are you suggesting that I copy the implementation/logic for the emphasis parser? |
You probably don't need all the logic from there but some logic needs to be included to make sure
|
@gettalong Rebased on latest
Added test case. It passes.
Added test case. It passes. Anything else? I don't know a better way to accomplish this that's more efficient. Feel free to take our two commits and improve upon them, but I believe this works just fine. 😄 |
@gettalong Let me know if there is anything else needed here. I would love to see this feature make it into the next version of kramdown. Thanks! |
There is still at least one edge case that is not handled correctly with the current code - I will look at it. |
Before I do anything further could someone please tell me the GFM specification for strikethrough? There are two possibilities:
The reason why I ask is the following example: This ~~is a complex strike through *test ~~with nesting~~ involved*. This ~~is a complex strike through *test It currently gives the following result when evaluated in this input field: <p>This <del>is a complex strike through *test ~~with nesting</del> involved*.</p> As you can see this is not good... So, what should be done? Support GFM like it is now or support something working in a useful way? |
Thanks for looking into that.
This is a question for @benbalter. My thoughts are to support it as it is rather than how it ought to be. If it makes our code more complex to support it as it is, then I am fine with this breakage. 👍 |
Since GFM is not my main concern it would be okay if it is broken by design (in contrast to the kramdown parser). However, note that if this is how the GFM parser should work it will be announced as such in kramdown's documentation to make this clear and tests for the broken design will also be added. I also had to make this choice for kramdown initially: Support the broken Markdown.pl way or break 100% compatibility to do something useful and, especially, predictive. The latter was my choice for kramdown (though there are some things I would change). |
Until we move to something like CommonMark, there's no such thing as a GFM spec, AFAIK, so there's not necessarily a "right" way to do things, in my mind.
@gettalong based on your comment above, it sounds like you see the GFM parser primarily as something to give parity to GitHub Markdown. If that's the case, then my vote would be for mirroring GitHub's implementation, even if it's silly. My reasoning is that if I push a file to GitHub.com (which uses GFM), and then they try to render it using Kramdown (which advertises GFM support) and the two differ, my first reaction would be to file a bug, because the software violated my expectations (regardless of if the behavior was right or not). If you see GFM support as a first-class, but alternative parser for those that prefer GFM (but may not use it with regard to GitHub's implementation), then the more philosophically pure implementation makes sense. Otherwise, I'd err on the side of practicality and user expectations, unless that adds unnecessary complexity to the code. FWIW, I wrote up a quick test to compare common markdown fixtures rendered with Kramdown and with the GitHub Markdown API, and these seems to be the only major point of differentiation, once e.g., whitespace is normalized. (Also to note, I did some spelunking through the github-markdown implementation and history, but couldn't find any guidance one way or the other). |
If I may add my two cents @gettalong @benbalter @parkr Why not split-off the kramdown GFM Parser class into a new gem and its own project e.g. kramdown-gfm or something. Why? First the code is actually so far minor e.g. about 100+ lines of ruby - see Kramdown::Parser::GFM. Thomas Leitner - as I talked to him - if I dare to say has no interest really in supporting the GitHub-Flavored (GFM) markdown - also as said before - Thomas is not using Jekyll either ;-). His main concern is the "core" kramdown syntax (without any extensions). If you use your own (split-off) addon and gem than you can change the code as you like and that's in the best interest and you will get the support and approval of Thomas Leitner as far as I understand (from our in-person conversations). And it makes sense. As a real-world case study example there's already the kramdon-rfc2629 parser by Carsten Bormann. Why should Thomas in his spare time support the GitHub-Flavored (GFM) addon / syntax? I'd say that is not really optimal for getting updates and changes included in Jekyll and GitHub Pages. Using your own kramdown-gfm addon - you can update and push changes whenver you like and Thomas and others can still contribute (it's open source on GitHub ;-) And again the code involved is minimal - maybe two or three hundred lines of Ruby - if you add the new strikethrough and autolink extensions? Really not much more involved than a Jekyll plugin. Than it's easy to add strikethrough and some other minor missing extras without worring about the need for a spec - it's your code and that's good enough - the code is the spec ;-) Keep it simple. Onwards. Cheers. |
@benbalter I don't intend the GFM parser to be a standalone, separate Markdown parser that is used outside the context of Github and therefore "first-class". GFM makes, in my opinion, only sense when used in the context of Github, eg. Github Pages. So if there is no GFM spec to work with or test against, I'm fine with including the changes in this way. @geraldb Splitting off the GFM parser would be a possibility but is currently not really necessary as contributing to the GFM parser inside the kramdown project is possible. |
The parser needed some more work to mimic Github in respect to my "broken" example. I also removed some unneeded code in regards to the escaping mechanism and fixed the tests. Thanks for the input and discussion! |
@gettalong Thank you! And thank you for preserving our commits in your merge. Cheers! 🍻 |
Duplicates #184 by @diegobg. Fixes #304.
@gettalong We'd like to work with you to bring this GFM parser up to speed with the current offerings on GitHub. Expect some PR's to that effect in the coming weeks. Thank you for kramdown!