Supporting HTML
Problem
Angular, Vue and Ember all use variants of html/mustache with JS and CSS embedded. It would be really awesome to make prettier support it as well. This would allow the project to be the one stop destination for all the front-end related code.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Implement HTML/Mustache Support in Prettier
Prettier currently lacks built-in support for HTML/Mustache templates used in frameworks like Angular, Vue, and Ember. This limitation prevents developers from formatting these templates consistently alongside their JavaScript and CSS code, leading to a fragmented development experience.
Awaiting Verification
Be the first to verify this fix
- 1
Fork Prettier Repository
Start by forking the Prettier repository on GitHub to create a personal copy where you can implement changes.
bashgit clone https://github.com/YOUR_USERNAME/prettier.git - 2
Create HTML/Mustache Parser
Develop a parser for HTML/Mustache templates that integrates with Prettier's existing parsing architecture. This parser should handle syntax highlighting and formatting rules specific to Mustache syntax.
javascript// Example of a simple Mustache parser function parseMustache(template) { // Parsing logic here } - 3
Integrate Parser with Prettier
Modify Prettier's core formatting engine to include the new HTML/Mustache parser. Ensure that it can detect Mustache syntax within HTML files and apply appropriate formatting.
javascript// Integration example const prettier = require('prettier'); const formatted = prettier.format(template, { parser: 'mustache' }); - 4
Write Unit Tests
Create unit tests to validate the functionality of the new HTML/Mustache support. Ensure that various Mustache templates are formatted correctly and edge cases are handled.
javascripttest('formats mustache correctly', () => { const input = '{{name}}'; const output = prettier.format(input, { parser: 'mustache' }); expect(output).toBe('formatted output'); }); - 5
Submit Pull Request
Once the implementation and tests are complete, submit a pull request to the main Prettier repository for review. Include documentation on the new feature and usage examples.
bashgit push origin feature/mustache-support # Then create a PR on GitHub
Validation
To confirm the fix worked, run Prettier on a sample HTML/Mustache template and check if the output is formatted correctly. Additionally, ensure all unit tests pass successfully.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep