Js-beautify: HTML Beautify: do not format YAML front matter

Created on 15 Aug 2014  ·  5Comments  ·  Source: beautify-web/js-beautify

Static site generators like Assemble or Middleman or Jekyll are supporting YAML front matter at the top of a template. When running html beautify on these templates, the front matter gets messed up.

So this yaml front matter:

title: Test
is-test: true

---

converts to:

--- title: Test is-test: true ---

I would suggest to ignore everything "wrapped" between three dashes or to add an extra option.

Further information: http://assemble.io/docs/YAML.html or http://middlemanapp.com/basics/frontmatter/

html templating fixed?

Most helpful comment

I do believe that beautifier should have a parameter like preservenewlines . If it already have it then preserve new lines in the text. It is not only issue of front matter. For example let's say there is HTML code and some people work in VS Code and other in MidnightCommander right on the server. that is why all text is formatted like this.

<p>
    This is multiple
    line text, that is
    easy to read in 
    MC
</p>

This works right when HTML is rendered and also visible in MC. But if someone format it with beautifier this is gone.

So preserve new lines in the text would be awesome.

All 5 comments

There are so many of the templating systems the people what to use with js, html, and css.
@einars, @evocateur do you have any thoughts/opinions of whether (or how) the beautifiers can be modified so we aren't adding special cases into all the core code to deal with all these?

Short of dramatically refactoring with a robust AST parser (e.g., Esprima), providing a plugin interface to allow custom poking of such an AST, and thus abandoning the Python version, I don't see this happening. (And almost all of the AST code generators, like escodegen, produce output that is extremely difficult to customize)

To be perhaps a little more blunt, this project should not do anything more than beautify JS. Notice I left out HTML and CSS, but if they must remain, then they should only beautify CSS and HTML. It is time-wasting folly to attempt to contort our static parser to allow for every pre- and post-processor's malformed "sugar" of syntax.

We don't beautify YAML, nor Markdown/LESS/SASS/React/Go/Ruby/Brainfuck for that matter. Curmudgeonliness aside, the encroaching complexity of supporting every weird meta-syntax fever dreamt by our strange beautiful community of front-end craftspeople is just loony. There are other beautifiers, today, that do attempt to engage the AST angle (though the plugin APIs, if they exist at all, tend to be very immature).

Very reasonable. Same principle as "beautifier is not a general purpose formatter".

The js beautifier provides an easy api for wrapping it inside another beautifier. That is exactly what the html beautifier does. When it encounters javascript, the html beautifier passes control to the js beautifier and then integrates the output. People are welcome to wrap or modify the components provided by this project to create their own. If people are interested and willing to take/share responsibility, they could make their projects part of beautify-web.

In the short-term, we should probably start marking bug requests based outside of html, css, and javascript, and then decide where to go from there.

I do believe that beautifier should have a parameter like preservenewlines . If it already have it then preserve new lines in the text. It is not only issue of front matter. For example let's say there is HTML code and some people work in VS Code and other in MidnightCommander right on the server. that is why all text is formatted like this.

<p>
    This is multiple
    line text, that is
    easy to read in 
    MC
</p>

This works right when HTML is rendered and also visible in MC. But if someone format it with beautifier this is gone.

So preserve new lines in the text would be awesome.

I think this is fixed. Just needs a test.

Was this page helpful?
0 / 5 - 0 ratings