raphaellouis
2022-05-27
Hi all!
1. Context
- “Emmet is a plugin for many popular text editors which greatly improves HTML & CSS workflow”
- “Emmet is a plugin for many popular text editors which greatly improves the speed with which you write HTML by allowing you to transform CSS-like selectors into full-blown HTML very fast.”
- “Emmet abbreviation and snippet expansions are enabled by default in
html,haml,pug,slim,jsx,xml,xsl,css,scss,sass,lessandstylusfiles, as well as any language that inherits from any of the above likehandlebarsandphp.”
2. Features of Emmet
- HTML from CSS — You’ve already known how to use Emmet abbreviations: its syntax is inspired by CSS selectors.
- Dynamic Snippets — Each abbreviation is transformed in runtime: just slightly change its name to get a different result.
- Ultra-fast Coding — With Emmet you can quickly write a bunch of code, wrap code with new tags, quickly traverse and select important code parts and more!
- Customizable — Users can easily add new snippets and fine-tune Emmet experience with just a few JSON files.
- Platform for new tools — Dig into Emmet source code and re-use its modules to create your very own and unique actions.
- Highly Portable — Emmet is written in pure JavaScript and works across different platforms: web browser, Node.js, Microsoft WSH and Mozilla Rhino.
3. Reason
- Minifying the html speeds up page loading and results in happy visitors. In short, this process will remove unnecessary whitespace characters, newline characters, comments, and block delimiters from your code.
- My idea would be to use the emmet pattern to minify the html - emmet is easy to understand and looks a lot like regular expressions which is somehow interesting to maintain readability 3.There is not as far as I am aware of an official api to minify html 4.I would like to help the Wicg Discourse group on the html specification
3. Concept
3.1 before_minification.html
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
The content of the document......
</body>
</html>
3.2 after_minification_with_emmet.html
(head>meta[charset=${charset}]+title\n "Title of the document"{${1:Document}})+body\n "The content of the document......"
References
- Zen Coding: A Speedy Way To Write HTML/CSS Code — Smashing Magazine
- https://emmet.io/
- Cheat Sheet
- Emmet in Visual Studio Code
- Abbreviations
- https://levelup.gitconnected.com/speed-up-your-coding-with-emmet-in-vscode-433162d95880?gi=72aecf7262f8
- HTML doctype declaration
- GitHub - kangax/html-minifier: Javascript-based HTML compressor/minifier (with Node.js support)
- GitHub - wilsonzlin/minify-html: Extremely fast and smart HTML + JS + CSS minifier, available for Rust, Node.js, Python, Java, and Ruby
- GitHub - tdewolff/minify: Go minifiers for web formats