-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Markdown integration #2444
Comments
For the blockquote you can use the fill primitive built by @karl: https://medium.com/geckoboard-under-the-hood/adding-a-new-layout-strategy-to-prettier-8d33084c0f99 Instead of having hardline be the separator, you can have |
@motiz88 If you need any help or pointers getting the |
@vjeux It will take me some digging to figure out what a solution using In the mean time I've hacked in the new primitive I was after (tentatively |
@motiz88 I'd be really interested in seeing how the Markdown parsing works (specifically around the blockquotes). I think I can picture the kind of issues you might come across that would make using If you have some code already working please feel free to create a work in progress ( |
Not creating a PR just yet, as the code is nowhere near complete; But anyone wishing to have a super-early look is welcome to check out https://github.com/motiz88/prettier/tree/markdown or just the test snapshot file. Again, just to clearly communicate where I am on this: Very few nodes are implemented right now, the tests don't all reflect the intended eventual behaviour, and overall correctness is - shall we say not guaranteed 😉 @karl It appears that |
In fun news, curiosity got the better of me and I got the multiparser working, so my implementation now formats code within Markdown code blocks. I especially like this test of a prettified code block nested in a blockquote. |
At this point, I would love to get some sort of buy-in for this feature from Prettier's maintainers, as getting it into a PRable and mergeable state is going to take some time & effort - which I'm more than happy to put in, but not if, say, Markdown is simply out of scope for inclusion in Prettier and the PR would never be merged. Which is fair enough! Just tell me up front 😃 |
I'd be very interested in this - we use Bitbucket Server at the company I work at and it doesn't wrap markdown when it's being viewed in PRs or have a rich diff mode like Github does. I'd be more than happy if the first release just solved the issue of wrapping the markdown - formatting the code within code blocks wouldn't be too important for us. |
Regarding a single flavor of markdown: There is this initiative from several big shots in the markdown community: http://commonmark.org/ |
Formatting code inside Markdown would be amazing, I'm willing to help out with getting it merge-ready.
I think this is our best option. We haven't introduced any non-JS settings yet and I think it would be best to keep it that way. |
Aint sure what features do u plan as part of pretty formatting Markdown - but pretty printed tables would be incredibly cool! Also great work on the multiparser 👏 |
I'm not sure if prettier is should be a markdown formatter, feels like a stretch. However, I think any tool that is a markdown formatter should call prettier to format code code blocks. As far as creating such a tool, my number 1 annoyance about peoples' READMEs is that they're poorly formatted for reading in a terminal. Markdown is first meant to be a plain text markup, it just conveniently is also used as the markup language for lots of stuff that outputs HTML (like GitHub). I would love if a Markdown auto-formatter had output wrapped at 80 characters so that it could easily be viewed in a terminal. |
What about things like this? https://github.com/thinkmill/react-markings IMO it would be amazing if prettier formatted this like it formats styled components. (I know that styled components are going to come up more than markdown, I'm just saying 😄 ) |
@sorahn If we land markdown support, it will be trivial to add support for |
Forgot to announce here, I've opened #2943 to address this issue, feedbacks welcome. |
Hi everyone!
I've decided to dive into the Prettier source code with the intention of ultimately building full Markdown support into it. I can find my own way around the codebase OK for now, but I'd like to discuss here (given the truth of this tweet) some fundamental issues as I encounter them, to increase the chances of this actually landing in Prettier at some point.
Goal
A Markdown integration for Prettier, which, the way I envision it, involves formatting Markdown files and ideally also JS/CSS/etc code blocks within them.
Q: Is such a Markdown integration even desired?
Basic approach
Using
remark
as a parser and as a reference printer:remark-parse
to implementparser-remark.js
(this part is straightforward).remark-stringify
to Prettier's formatting primitives (and coding conventions) to implementprinter-remark.js
.printer-remark.js
once it has reached parity withremark-stringify
.Problems/questions
Passing user options to the parser/printer
remark
supports several flavours of Markdown and takes various options; would we expose any of this to the user? (How?) The alternative is to essentially commit to a single flavour of Markdown, but that may be too opinionated to be viable.A new document type for blockquotes
If we want to print Markdown blockquotes the "standard" pretty way - with hard wrapping and a
>
marker at the beginning of each line:Then AFAICT we need a new document type to represent it and probably a different implementation of
indent
andalign
indoc-printer.js
(supporting arbitrarily mixed indentation and non-space markers, including nested blockquotes etc). Can someone confirm this or point out something I've missed?Multiparser architecture
I have not begun to tackle this at all, but would appreciate any thoughts about it nonetheless.
My current thinking is that we can extract parts of the existing JS-centric "multiparser" for reuse in a Markdown multiparser, and potentially uncover interesting generalisations.Just realised the existing multiparser also does CSS in HTML; it's probably already general enough.Thanks for a fantastic tool and thanks in advance for any help on this!
The text was updated successfully, but these errors were encountered: