Js-beautify: Don't indent unclosed HTML tags containing server directives "<@"

Created on 18 May 2017  路  9Comments  路  Source: beautify-web/js-beautify

Steps to Reproduce

  1. Create a test.aspx or test.jsp file with the following content
<%@Master language="C#"%>
<%@Register TagPrefix="a" Namespace="a" Assembly="a"%>
<%@Register TagPrefix="b" Namespace="a" Assembly="a"%>
<%@Register TagPrefix="c" Namespace="a" Assembly="a"%>
<!DOCTYPE html>
<html><some-content /></html>
  1. Run jsbeautify. This will result in:
<%@Master language="C#"%>
    <%@Register TagPrefix="a" Namespace="a" Assembly="a"%>
        <%@Register TagPrefix="b" Namespace="a" Assembly="a"%>
            <%@Register TagPrefix="c" Namespace="a" Assembly="a"%>
                <!DOCTYPE html>
                <html>
                <some-content />

                </html>

Expected outcome:

<%@Master language="C#"%>
<%@Register TagPrefix="a" Namespace="a" Assembly="a"%>
<%@Register TagPrefix="b" Namespace="a" Assembly="a"%>
<%@Register TagPrefix="c" Namespace="a" Assembly="a"%>
<!DOCTYPE html>
<html>
<some-content />

</html>

Suggested solution: When no closing tag is found, treat server directive tags (<%@ %>) as if they were self closing (<%@ %/>), or as if they were comments. Could this logic be applied to unclosed tags in general?

Resources:

good first issue html fixed? enhancement

Most helpful comment

Could this problem be solved earlier?

All 9 comments

Could this problem be solved earlier?

unfortunately it also breaks ejs templates :/

This could be an easy fix - adding <%@ to the list of singleton elements.
@maciejjankowski Are there non-singleton server directive elements?

@bitwiseman you mean using
html.format.unformatted option?
I tried addint "html.format.unformatted": "wbr, %" but then formating stops working altogether

This appears to have been resolved in v1.8.0-rc12.

When I ran it, the actual result was:

<%@Master language="C#"%>
<%@Register TagPrefix="a" Namespace="a" Assembly="a"%>
<%@Register TagPrefix="b" Namespace="a" Assembly="a"%>
<%@Register TagPrefix="c" Namespace="a" Assembly="a"%>
<!DOCTYPE html>
<html>
<some-content />

</html>

Which matches the expected result. @fengerzh, @maciejjankowski, and @alirobe, do you want to double check via http://jsbeautifier.org/?

When I ran it, it became like this:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%> <
!DOCTYPE html >
    <
    html >
    <
    head >
    <
    meta http - equiv = "Content-Type"
content = "text/html; charset=UTF-8" / >
    <
    meta name = "viewport"
content = "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" / >
    <
    meta name = "apple-mobile-web-app-capable"
content = "yes" / >

@fengerzh I rechecked it and I'm still getting the correct indenting. Did you check your settings? I used only the default settings and made sure to select the HTML option.

@MacKLess Verified. 1.8.0-rc13 solved the problem. Thanks!

Wew! Fixed :) Thanks

Was this page helpful?
0 / 5 - 0 ratings