-
-
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
Improve Markdown implementation - Or: Should we separate compiler tools? #4613
Comments
GitHub Flavored Markdown (GFM) has the spec now. |
Yes, that's the CommonMark spec plus a few extensions, so GFM is essentially a superset of CommonMark. These extensions are:
As asterite and ysbadden stated it is probably best if the default implementation does not include extensions. There is already a Crystal implementation for CommonMark at https://github.com/ujifgc/crmark, though it is a direct port of the JavaScript reference implementation, so it can certainly be optimized in many ways. |
Instead of implementing a parser in Crystal we could also use the existing C implementation. |
It would be good to adopt the full CommonMark specs in the stdlib. But I think it will be better to have a crystal native implementation. That way we could toggle extensions like GFM which many probably want. If the failing CommonMark specs can be grouped and the design of the parser the reference implementation can be ported then we might be in a better shape to improve the markdown implementation as you suggest. The markdown parser is mainly used to generate the docs from crystal code. And it is slightly used in the playground. That is basically why the current implementation didn't need all markdown features. |
What do you mean with grouping the failing specs? The spec file is essentially a literate description (HTML at spec.commonmark.org) with embedded examples from which the test cases are extracted. So the tests are part of the hierarchical document structure. The default test runner for example can be limited to specs from specific sections with parameter I would prefer a Crystal implementation as well. Seems like I was mistaken about extensibility of cmark. There is however an open PR to include extensions. Github have forked cmark to implement their syntax additions. Besides the already mentioned projects, there are also huacnlee/remarkdown, an extension of stdlib's |
I created markd just to validate how to write a CommonMark and better support extensions. In my other project named wasp is a static site generator. It requires powerful markdown parser for the users. cmark is not the best solution to wasp, and same to crystal community. BTW, PL#4496 is another discussion. |
I'm sure that GFM should be default. Because it will be default everywhere. |
What makes you sure of this? Even Github understands GFM as a set of extensions to the standard CommonMark. A default implementation should use the most basic common denominator. It is a better approach to add certain extensions to the basic set when they are necessary, instead of removing them when they are not needed. |
Just because any modern language/framework documentation browser based on GFM. But Yes, GFM as option in stdlib is OK. |
Don't you guys think that two markdown parsers are a little bit of overkill? I personally would advocate that none should be embedded in Crystal at all. Unless I'm losing some details, I really see no need for markdown parsers when you could simply implement it as a shard and import as needed. |
@kazzkiq |
I've said it before and I'll say it again: If the only reason the markdown parser is in the stdlib is so that it can be used in |
@straight-shoota in #4613 (comment) i meant that if the failing specs can be grouped by features, then this issue is more actionable / can be tackled down based on that list of features. Maybe that list is just the TOC of http://spec.commonmark.org/0.27/ (now that I've opened the link). That been said, PRs are welcome to move the crystal stdlib markdown module towards CommonMark. If the module migrate to a separate shard that is another story. Let's first have a commonmark native implementation we are all happy about. |
The current implementation probably needs some architectural changes to properly support all of CommonMark and to make it extensible. As a side node: documentation flags (#3519) could also be implemented as an extension to the default markdown class and can then be used by the docs generator. |
Now markd is 100% compliant to Commonmark, and pass all specs. Here is the result of a sample markdown file parse at MacBook Pro Retina 2015 (2.2 GHz):
parse cost time:
note: preparing input is only process the source as |
Wow, that's great! A performance loss is certainly to be expected, but I suppose there is room for optimization...? |
@straight-shoota Updated the result, i found and used a complete commonmark source as a sample to benchmark. 🤣 |
Add ujifgc/crmark, It was best with commonmark support for now.
I can't install ysbaddaden/crystal-cmark, it missed the benchmark:
|
Would you care comparing the performance to crystal-cmark (libcmark bindings)? And maybe some implementations in other languages (cmark and commonmark.js are reference implementations)? |
@icyleaf use |
Simple benchmark, each ran 10 times. source code
|
Updated and add common_mark (thanks @RX14).
without built-in markdown
|
I'd say we move the Thoughts? |
The current markdown implementation is insufficient in many ways, even for the job of producing the docs. Therefore I'd like to see an improvement to the markdown employed by the compiler, be it in stdlib or from an external shard (I don't know about the practical application of this). I'd question if it would be worth sticking around with the current implementation if it gets hidden in the compiler's source. It's not good enough for this purpose and it's unlikely to get improved if nobody uses it except from the compiler. |
@straight-shoota The current std is documented with it and I didn't find it lacking. We could perfectly support a subset of it, like for lists, links and codeblocks. |
Yes, for the current stdlib documentation it is sufficient. But I've run into problems several times documenting my own code, mostly cause by missing support for raw HTML. While this shouldn't be needed for most documentation purposes, there are occasions where e.g. a table would help a lot. This is a common feature used in many API documentations. |
@straight-shoota surely since we all agree it's substandard, surely the best thing to do is to limit it's usage to to docs tool. If someone wants to implement all of commonmark properly and completely, i'm sure we can vendor in that shard and use it in the compiler. |
@j8r markd is already feature complete and passes all specs. There haven't been recent commits that fix stuff in the library, just optimizations (it seems) or new features. So I think moving this to the standard library is good:
|
@j8r I agree that having libraries tied to Crystal's stdlib release schedule can be problematic. But as @asterite said, it's a huge issue regarding In the future we might eventually ending up with the stdlib consisting of essentially a set of standard shards that come installed with crystal by default, but individual projects can use different versions of them (installed in local |
Ok that may be fine if you consider the markdown implementation very stable. In fact, the main issue I find is to put everything possible (I exaggerate) in the crystal/crystal monorepo. Can we still keep in its own repo, and include it with subtree (or whatever) in the stdlib (option 3)? |
Why not?
I imagine
This only affects Crystal std/compiler developers, so just a bunch of people compared to the entire Crystal userbase. So I personally don't see this decision as having a lot of importance and it could always be tackled later. |
Because he won't be the owner of the repo anymore, just another Crystal contributor.
Not really. It would also be harder to contribute than if markd lives in its own repo. Review would be longer, CI too, the |
If there is a chance for the markdown module to be available directly in the std-lib I would like to avoid having a release without it. Right now 0.31.0 might come out without a markdown module. While we settle how/if do this, should rollback #8115 to avoid reverting a breaking change in a release? |
@j8r You're making generally valid points and more separation might be a good path for the future. But currently, we have a monolith repository. And I think this is fine for now and we don't need to change this setup. That would require a lot of effort and simply isn't necessary at the moment. Besides, your argument only targets markdown, because the markd implementation is currently a separate shard, suggested to be moved into stdlib. It has not been a part of the stdlib before now, but the same is true for to many other standard libraries. The only difference is, they're currently already in stdlib. I don't think it makes sense to go a separate way right now just for markdown. @bcardiff Yes, we should avoid breaking markdown in 0.31.0. But I suppose, if we settle on @asterite's proposal, Markd could be imported rather quickly. If we target for a release at the beginning of October, this should work out. |
Another way to see it: we can import |
I think I won't have time to do this, so if someone can take over I'll be very grateful 🙏 |
If someone wants to tackle this, they will need to:
|
@j8r It's alright to move markd to crystal-lang organization, I believe this move will make markd and |
Actually, let me try once. more today. Yesterday I bumped into a compiler bug that was recently reported and I desisted, but maybe I can find a workaround. |
Which bug was it? (maybe someone can have a try at it while you have fun with markd?) |
Ah, nevermind the bug. I somehow copied the text from #8163 (comment) into the markdown code and it was exploding because of that. No idea how that happened. Later today I'll submit the markd inside std PR. It won't have the git history, sorry. But the history can be kept in markd's repo. |
I have the code but I won't send the PR. It seems Brian and Juan agreed that it might not be good to have Markdown in the standard library and that we should move So for now it might be better to just do nothing here. |
We were iterating with @waj on what to do here, our proposal would be:
This way we avoid copying the whole shard, allow @icyleaf to keep iterating, offer migration from Crystal 0.30 to 0.31, aim for reducing the std-lib size and maybe split the compiler. |
What's the purpose of that? Why can't markd continue existing as a shard on its own? Why do we need to become its owners? |
Avoiding dependencies outside the organization is a safe policy for avoiding them to disappear. |
An option for the future would be to have the markdown library as a dev dependency (that could be bundled, or not, in the release). |
In the future the docs tool might even get out of the compiler directly. Yet bundled in the distribution packages. Doing that could also remove the chicken and egg situation of shards used in the compiler if needed. Again, I want to focus on what the users should use as a replacement of the moved Markdown in order include that in the release 0.31. We can focus on how to improve the docs with better markdown support later. |
@bcardiff If we want to postpone the decision to after 0.31.0, I suggest to hold off on moving markd to |
That would be a full postpone. :-) But I'm fine with it.
|
I think this is all just a big mistake. Markdown in docs has a very tiny priority. The next big steps are getting parallelism tried out and done well and Windows, not focusing on extracting tools outside of the compiler, which is transparent for users and probably a maintenance burden for us and Crystal distributors. But improving Markdown is already here without a cost at all (I already sent a PR) and brings an immediate improvement without breaking any API (the main If I never continued commenting on this issue this entire "let's wait and extract compiler tools" discussion wouldn't even exist. But do as you wish. |
The Markdown parser and renderer is still very basic and misses important features like for example raw html.
I suggest to implement the CommonMark specification which is very reasonable and the de-facto standard reference for Markdown implementations. There is an entire test suite jgm/CommonMark to validate implementations. Currently
Markdown.to_html
passes only 137 of 621 (22 %).It would also be nice if the Markdown parser/renderer can be easily extended to add support for more specialized features like Github Flavoured Markdown (e.g #2217)
The text was updated successfully, but these errors were encountered: