-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
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:
- Take a direct dependency on
remark-parse
to implementparser-remark.js
(this part is straightforward). - Fully port
remark-stringify
to Prettier's formatting primitives (and coding conventions) to implementprinter-remark.js
. - Make stylistic tweaks to
printer-remark.js
once it has reached parity withremark-stringify
. - Multiparser??? - Haven't explored in any depth yet
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:
> This is a blockquote. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> This is a blockquote. Lorem ipsum dolor sit amet, consectetuer adipiscing
> elit. Aliquam hendrerit mi posuere lectus.
Then AFAICT we need a new document type to represent it and probably a different implementation of indent
and align
in doc-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!