{"id":13906849,"url":"https://github.com/helpers/handlebars-helper-prettify","last_synced_at":"2026-03-08T11:35:23.621Z","repository":{"id":10062421,"uuid":"12114279","full_name":"helpers/handlebars-helper-prettify","owner":"helpers","description":"{{prettify}} handlebars helper, for formatting (\"beautifying\") HTML, CSS and JavaScript.     ","archived":false,"fork":false,"pushed_at":"2017-04-03T17:11:06.000Z","size":32,"stargazers_count":19,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-06-17T12:45:20.943Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://assemble.io/helpers/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/helpers.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-08-14T16:54:59.000Z","updated_at":"2024-10-13T20:38:01.000Z","dependencies_parsed_at":"2022-08-28T01:51:28.749Z","dependency_job_id":null,"html_url":"https://github.com/helpers/handlebars-helper-prettify","commit_stats":null,"previous_names":["helpers/prettify","helpers/helper-prettify"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/helpers/handlebars-helper-prettify","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helpers%2Fhandlebars-helper-prettify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helpers%2Fhandlebars-helper-prettify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helpers%2Fhandlebars-helper-prettify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helpers%2Fhandlebars-helper-prettify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/helpers","download_url":"https://codeload.github.com/helpers/handlebars-helper-prettify/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helpers%2Fhandlebars-helper-prettify/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260862913,"owners_count":23074182,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-06T23:01:43.578Z","updated_at":"2026-01-11T13:29:43.422Z","avatar_url":"https://github.com/helpers.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# {{prettify}} [![NPM version](https://badge.fury.io/js/prettify.png)](http://badge.fury.io/js/prettify) \n\n\u003e {{prettify}} handlebars helper for formatting (beautifying) HTML, JavaScript and CSS.\n\nThis helper depends on and extends [js-beautify](https://github.com/einars/js-beautify). Please visit and star that project to show your support.\n\n[Also see examples →](./EXAMPLES.md)\n\n## Getting Started\nIn the root of the project in which you plan to use the helper, in the command line run:\n\n```bash\nnpm i prettify --save\n```\n\nUse within your application with the following line of JavaScript:\n\n```js\nvar helpers = require('prettify');\n```\n\nNow your handlebars instance will have access to the {{prettify}} helper.\n\n\n\n\n## Options\n#### Defining options\n\nAll options from [js-beautify](https://github.com/einars/js-beautify) are available in this helper, as well as a few custom options that were specially created for this helper. The helper comes with some sensible defaults (in the humble opinion of the helper creator), but it's easy to customize them if you need to. Here are are two (convenient) ways to set options:\n\n* **options object**: pass an options object to the helper as a parameter. E.g. `{{#prettify opts.obj}}`.\n* **options hash**: this is an easy way to set options on the helper, and it also gives you granular control over how the helper renders content.\n* **Gruntfile**: if you use both [Grunt](http://gruntjs.com/) and [Assemble](http://assemble.io), you can define options in the Assemble task options of your project's Gruntfile.\n\n\n##### options hash\nBy design, options define here will override options defined anywhere else. This approach also provides granular control over options, allowing you to defined different options on multiple instances of the helper in the same file.\n\nExample:\n\n```handlebars\n{{#prettify condense='true'}}\n  {{\u003e header }}\n{{/prettify}}\n\n{{#prettify padcomments='true'}}\n  {{\u003e body }}\n{{/prettify}}\n\n{{#prettify condense='true'}}\n  {{\u003e footer }}\n{{/prettify}}\n```\n\n\n##### \"assemble\" task options\nThe helper can be used without [Grunt](http://gruntjs.com/) or [Assemble](http://assemble.io). But if you happen to use these two awesome tools you can define options for the helper in your Gruntfile in the `prettify` sub-options for Assemble:\n\n```javascript\ngrunt.initConfig({\n  assemble: {\n    options: {\n      prettify: {\n        mode: 'js',  // 'html' is defined by default\n        condense: true,\n        padcomments: true,\n        indent: 4\n      }\n    },\n    ...\n  }\n});\n```\n\nOptions defined in the Assemble task can be viewed as custom \"global\" defaults, which can be overridden by options defined in the options hash.\n\n\n#### option defaults\n\nThe following options are passed to [js-beautify](https://github.com/einars/js-beautify). The defaults are shown for each option.\n\n###### \"html\" mode\n\nThese options are available by default (see [detailed HTML options](./OPTIONS.md)):\n\n```js\n{\n  \"brace_style\": \"expand\",      // collapse|expand|end-expand\n  \"indent-scripts\": \"normal\",   // keep|separate|normal\n  \"indent_char\": \" \",           // (default: space) Indentation character. Can be an actual tab or space\n  \"indent_handlebars\": false,   // format and indent {{#foo}}...{{/foo}}\n  \"indent_inner_html\": false,   // Indent \u003chead\u003e and \u003cbody\u003e sections\n  \"indent_size\": 2,             // Indentation size\n  \"max_preserve_newlines\": 5,   // Maximum number of line-breaks to be preserved in one chunk\n  \"preserve_newlines\": true,    // Preserve existing line-breaks\n  \"unformatted\": [\"a\", \"sub\", \"sup\", \"b\", \"i\", \"u\"], // List of tags that should not be reformatted (inline elements included by default)\n  \"wrap_line_length\": 78,       // Maximum characters per line (0 disables this)\n\n  // custom options made for this helper\n  \"indent\": 2,          // convenience alias for indent_size\n  \"condense\": false,    // remove extra newlines missed by js-beautify.\n  \"padcomments\": false  // add an extra newline above each HTML code comment\n}\n```\n\n###### \"js\" mode\n\nWhen `mode` is set to `js`, the following options are available:\n\n```js\n{\n  \"brace_style\": \"collapse\",\n  \"break_chained_methods\": false,\n  \"eval_code\": false,\n  \"indent\": 2,\n  \"indent_char\": \" \",\n  \"indent_level\": 0,\n  \"indent_size\": 2,\n  \"indent_with_tabs\": false,\n  \"jslint_happy\": false,\n  \"keep_array_indentation\": false,\n  \"keep_function_indentation\": false,\n  \"max_preserve_newlines\": 10,\n  \"preserve_newlines\": true,\n  \"space_before_conditional\": true,\n  \"unescape_strings\": false,\n  \"wrap_line_length\": 0\n}\n```\n\n###### \"css\" mode\n\nWhen `mode` is set to `css`, the following options are available:\n\n```js\n{\n  \"end_with_newline\": false,\n  \"indent\": 2,\n  \"indent_char\": \" \",\n  \"indent_size\": 2,\n  \"selector_separator\": \"\"\n}\n```\n\n#### custom options\n\n\u003e Options created specially for this helper\n\n##### mode\nType: `String`\nDefault value: `html` (valid modes: `html`|`js`|`css`)\n\nOnly necessary if you want to format CSS or JavaScript (e.g. you must specify either `js` or `css` respectively). Example:\n\n```handlebars\n{{#prettify mode=\"js\" indent=4}}\nfunction foo(str) {return str;}\n{{/prettify}}\n```\n\nAssemble options:\n\n```js\nassemble: {\n  options: {\n    prettify: {\n      // options for default 'html' mode go here\n      js: {\n        // options for 'js' mode go here\n      },\n      css: {\n        // options for 'css' mode go here\n      }\n    }\n  }\n}\n```\n\n##### indent\n_Alias for `indent_size`_.\nType: `Number`\nDefault value: `2`\n\nNumber of spaces or tabs to indent the generated code. This option is an _alias for `indent_size`_.\n\n##### condense\nType: `Boolean`\nDefault value: `true`\n\nRemoves extra newlines and retains indenting:\n\n##### padcomments\nType: `Boolean`\nDefault value: `True`\n\nAdd a newline above each code comment:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"UTF-8\"\u003e\n    \u003ctitle\u003eDocument\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n\n    \u003c!-- code comment --\u003e\n    \u003ch1\u003eMy Blog\u003c/h1\u003e\n    \u003ch2\u003ePost of the day\u003c/h2\u003e\n\n    \u003c!-- scripts --\u003e\n    \u003ca href=\"#\"\u003eRead more...\u003c/a\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n\n## Contributing\nPlease see the [Contributing to Assemble](http://assemble.io/contributing) guide for information on contributing to this project.\n\n## Author\n\n+ [github.com/jonschlinkert](https://github.com/jonschlinkert)\n+ [twitter.com/jonschlinkert](http://twitter.com/jonschlinkert)\n\n## Related Projects and Links\n\n+ [handlebars-helpers](https://github.com/assemble/handlebars-helpers)\n+ [helpers](https://github.com/helpers): some great handlebars helpers that we decided not to include in the [handlebars-helpers](https://github.com/assemble/handlebars-helpers) project, most likely because the code footprint was too big or the helper wasn't generic enough.\n+ [grunt-prettify](https://github.com/jonschlinkert/grunt-prettify)\n\n## License\nCopyright (c) 2013 Jon Schlinkert, contributors.\nReleased under the MIT license\n\n***\n\n_This file was generated on Thu Nov 14 2013 02:25:44._\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhelpers%2Fhandlebars-helper-prettify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhelpers%2Fhandlebars-helper-prettify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhelpers%2Fhandlebars-helper-prettify/lists"}