prettier / prettier/prettier

HTML and style/script formatting in Markdown

Open
#15,573 1 comment 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

lang:markdown
Dominant language
JavaScript
Stars
52.3k
Forks
5k
Avg merge
19h 2m
Merged PRs (30d)
117

Description

I'm writing Markdown files to generate static sites using VitePress. The VitePress library allows mixing HTML tags, JavaScript/TypeScript code, and CSS styles in a single .md file, similar to how we use the single-file component (SFC) format in Vue. However, it seems that HTML tags and code in <script> or <style> tags are not formatted. Would it be possible to add formatting for such blocks?

See also: https://vitepress.dev/guide/using-vue

Prettier 3.0.3
Playground link

--parser markdown

(I've tried the vue or html parsers as well, but they do not support Markdown syntax so the output is not correct either.)

Input:

---
hello:      world
---

<script setup>
import { ref } from 'vue'

const count = 
  ref( 0 )
</script>

## Markdown Content

The value for   `count`   is: {{ count }}

<div class="hello">
<span>Hello</span>
</div>

<style module>
.hello {
  color:      red
}
</style>

Output:

(The YAML front-matter formatting is correct.)

---
hello: world
---

<script setup>
import { ref } from 'vue'

const count = 
  ref( 0 )
</script>

## Markdown Content

The value for `count` is: {{ count }}

<div class="hello">
<span>Hello</span>
</div>

<style module>
.hello {
  color:      red
}
</style>

Expected behavior:

---
hello: world
---

<script setup>
import { ref } from 'vue'

const count = ref(0);
</script>

## Markdown Content

The value for `count` is: {{ count }}

<div class="hello">
  <span>Hello</span>
</div>

<style module>
.hello {
  color: red;
}
</style>

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Prettier Playground and the provided Markdown input, comparing the current output with the expected output for script, HTML, and style blocks. Investigate the relevant Markdown formatting entry points and existing parser behavior for these embedded blocks. Done means the Markdown content, JavaScript or TypeScript, HTML, and CSS are formatted as shown while front matter remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
css, html, javascript, markdown, typescript
Domain
tooling, web-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.