-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add tables support for Markdown #3589
Add tables support for Markdown #3589
Conversation
@azah welcome and congrulations on your first pull request 🎉 |
elsif element[0] == ':' | ||
return "left" | ||
else | ||
return "left" |
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.
No need to return
since it's implicit.
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.
Updated.
Add spec update for implicit returns Change to text-align because table.align is deprecated
Updated, because apparently table.align is deprecated. |
At first I was thinking that this just GFM and doesn't need to be part of the Crystal markdown parser but seeing as...
...then we should support it just for the sake of crystal docs |
This actually breaks for all of the examples on Github's page about tables require "markdown"
md = "
# MyProject
## A Table
| First Header | Second Header |
| ------------- | ------------- |
| Content Cell | Content Cell |
| Content Cell | Content Cell |
"
Markdown.to_html md
# Missing hash key: 0 (KeyError) And I would add some more tests. I would test against the examples on that Github page I shared and also the Ruby Kramdown lib actually has a good collection of markdown text files and the expected HTML output. |
@samueleaton yeah I now realize github doesn't support the format I used, it appears they require the I would have to rewrite the code then pretty much, so I will at some point. |
Not sure we should support this, CommonMark only allows the HTML syntax, see http://spec.commonmark.org/0.27/ rule 4.6.6. |
@jhass well, GitHub flavoured markdown has supported PHP markdown tables for a while. Redcarpet and friends deal with this by being able to turn on or off unofficial extensions. |
I'd say that the best way to do this is to conform to commonmark by default but allow extensions to the markdown parser. This would probably require the markdown code to be rewritten to allow extensibility however. |
CommonMark has no table support at all besides using raw html, which is both ugly and tedious compared to markdown's simplicity. Kramdown, Github, Gitlab, and PHP Markdown Extra use this format for tables:
with left, center, or right alignment syntax as follows:
They also also support this syntax:
I think that we use tables enough that they should be a core aspect, and we definitely use Github/Gitlab enough to give their syntax merit. However, extensions would be a good idea, because of differences like Gitlab's emojis or diff syntax:
References: |
Maybe this can be a standalone shards for parsing more markdown dialects? |
That's likely the best solution because custom extensions like Unfortunately I am working full time as a teacher & studying Korean- if someone else is interested in working on this by all means go ahead. I'll eventually make a shard at some point in the future. |
Crystal should support GFM by default because it's standard de facto. And it's great for API documentation etc. Just look at https://toolchain.gitbook.com/syntax/markdown.html |
Please keep the discussion about improving the markdown implementation in #4613 |
This commit lets this syntax work for markdown:
-
denotes a header, and:
denotes alignment.This style saves the extra line of typical markdown syntax:
This is my first contribution, so if my implementation can be made better or more "Crystal-like" please let me know.