0a4e206368169aa62421c3db084abb13ef866e74492c39c16139e605ae50a5458e39c6210f9bf7c97a0d81c1ef3f28b25863711fa83cf8ad9d734b58b6681e 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # {%= name %} {%= badge("fury") %}
  2. > {%= description %}
  3. Useful for protecting tokens, like templates in HTML, from being mutated when the string is transformed in some way, like from a formatter/beautifier.
  4. **Example without `preserve`**
  5. Let's say you want to use [js-beautify] on a string of html with Lo-Dash/Underscore templates, such as: `<ul><li><%= name %></li></ul>`:
  6. js-beautify will render the template unusable (and apply incorrect formatting because of the unfamiliar syntax from the Lo-Dash template):
  7. ```html
  8. <ul>
  9. <li>
  10. <%=n ame %>
  11. </li>
  12. </ul>
  13. ```
  14. **Example with `preserve`**
  15. Correct.
  16. ```html
  17. <ul>
  18. <li><%= name %></li>
  19. </ul>
  20. ```
  21. For the record, this is just a random example, I've had very few issues with js-beautify in general. But with or without js-beautify, this kind of token mangling does happen sometimes when you use formatters, beautifiers or similar tools.
  22. ## Install
  23. {%= include("install-npm", {save: true}) %}
  24. ## Run tests
  25. ```bash
  26. npm test
  27. ```
  28. ## API
  29. {%= apidocs("index.js") %}
  30. ## Contributing
  31. Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue]({%= bugs.url %})
  32. ## Author
  33. {%= include("author") %}
  34. ## License
  35. {%= copyright() %}
  36. {%= license() %}
  37. ***
  38. {%= include("footer") %}
  39. [js-beautify]: https://github.com/beautify-web/js-beautify