-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Markdown: Preserve code blocks within list items #3459
Copy link
Copy link
Labels
lang:markdownIssues affecting MarkdownIssues affecting Markdownlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.Please open a new issue and fill out the template instead of commenting.priority:highCode is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent!Code is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent!scope:dependencyIssues that cannot be solved inside Prettier itself, and must be fixed in a dependencyIssues that cannot be solved inside Prettier itself, and must be fixed in a dependency
Milestone
Metadata
Metadata
Assignees
Labels
lang:markdownIssues affecting MarkdownIssues affecting Markdownlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.Please open a new issue and fill out the template instead of commenting.priority:highCode is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent!Code is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent!scope:dependencyIssues that cannot be solved inside Prettier itself, and must be fixed in a dependencyIssues that cannot be solved inside Prettier itself, and must be fixed in a dependency
Prettier 1.9.1
Playground link
Input:
Code blocks may be nested within list items per the original Markdown syntax for lists:
Output:
Prettier strips the 8 leading spaces and replaces them with 3 to align with the list item content:
This treats the nested code blocks as subsequent paragraphs in the list items rather than as code blocks:
Change to your home directory:
cd
List the contents:
ls -l
Expected behavior:
The original input should either be preserved, indented with tabs or fenced to ensure the nested code blocks are rendered properly:
Change to your home directory:
List the contents:
Subsequent runs change result
If the nested code blocks are indented with 2 tabs (rather than 8 spaces), they are initially converted to 7 spaces. If the same file is saved again, the 7 spaces are converted to 3 spaces.
Fenced code blocks as workaround
If the nested code blocks are fenced, the input is preserved and output is generated as expected: