From fb8d7e67bdb888ecfdc84a5a50c70f6cc69a2349 Mon Sep 17 00:00:00 2001 From: Jai Chandra Date: Mon, 9 May 2016 15:30:11 -0400 Subject: [PATCH] fixes https://github.com/beautify-web/js-beautify/issues/930 --- README.md | 18 +++++++++++++++++- js/lib/beautify-html.js | 9 +++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2c98da250..6c6a4d3b5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# JS Beautifier +# JS Beautifier (With Handlebars update) [![Build Status](https://img.shields.io/travis/beautify-web/js-beautify/master.svg)](http://travis-ci.org/beautify-web/js-beautify) [![Build status](https://ci.appveyor.com/api/projects/status/5bxmpvew5n3e58te/branch/master?svg=true)](https://ci.appveyor.com/project/beautify-web/js-beautify/branch/master) [![NPM version](https://img.shields.io/npm/v/js-beautify.svg)](https://www.npmjs.com/package/js-beautify) @@ -7,6 +7,22 @@ [![NPM stats](https://nodei.co/npm/js-beautify.svg?downloadRank=true&downloads=true)](https://www.npmjs.org/package/js-beautify) +# Why this fork +Original js-beautify handlebars formatting breaks if handlebars comments contain handlebars tags `{{...}}`. This fork adds support for including handlebars tags inside comments without breaking formatting. Long commenting standard (`{{!--...--}}`) needs to be used for formatting to work with inline tags. + +Example +```handlebars +{{!-- + foo partial comments + Example: + {{> foo-partial}} +--}} +``` + +Everything below this is original documentation + +--- + This little beautifier will reformat and reindent bookmarklets, ugly JavaScript, unpack scripts packed by Dean Edward’s popular packer, diff --git a/js/lib/beautify-html.js b/js/lib/beautify-html.js index 7f16aee46..2d53d0c40 100644 --- a/js/lib/beautify-html.js +++ b/js/lib/beautify-html.js @@ -588,9 +588,14 @@ } else if (comment.indexOf(''; matched = true; - } else if (comment.indexOf('{{!') === 0) { // {{! handlebars comment - delimiter = '}}'; + } else if (comment.indexOf('{{!--') === 0) { // {{!-- handlebars comment + delimiter = '--}}'; matched = true; + } else if (comment.indexOf('{{!') === 0) { // {{! handlebars comment + if (comment.length === 5 && comment.indexOf('{{!--') === -1) { + delimiter = '}}'; + matched = true; + } } else if (comment.indexOf(''; matched = true;