Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beautify on HTML does not work well #78

Closed
Paquan opened this issue Dec 12, 2016 · 6 comments
Closed

Beautify on HTML does not work well #78

Paquan opened this issue Dec 12, 2016 · 6 comments

Comments

@Paquan
Copy link

Paquan commented Dec 12, 2016

bildschirmfoto 2016-12-12 um 15 23 15

@Paquan
Copy link
Author

Paquan commented Dec 12, 2016

Why does it break into a newline after a for attribute.
And it adds more and more tabs for some elements but does not come back with the closeing element.

@HookyQR
Copy link
Owner

HookyQR commented Dec 27, 2016

Please provide a code snippet so I can test at this end.

@schmuli
Copy link

schmuli commented Jan 5, 2017

I'm not sure if this is the same issue, or if it even belongs in this repo, but I'm having a similar issue when formatting HTML.

When setting wrap-attributes to force or force-aligned, the head and body tags are being indented (indent-inner-html is set to false), and the indentation after lines with wrapped attributes is incorrect.

In the example below, you can see how the <head> tag is incorrectly indented, additionally the last comment in the head is also incorrectly indented, and this actually continues on further down the page too.

Original

<!DOCTYPE html>
<html ng-app="MyBelovedApp" ng-strict-di="true">

<head>
    <!-- build:base -->
    <base href="/src/app/" />
    <!-- endbuild -->

    <title>My Beloved App</title>

    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />

    <!-- build:icon -->
    <link rel="shortcut icon" href="../assets/favicon64.png" />
    <!-- endbuild -->

    <link href='https://fonts.googleapis.com/css?family=Inconsolata|Open+Sans:300,400' rel='stylesheet' type='text/css' />

    <!-- build:css -->
    <link rel="stylesheet" href="core/styles.css" />
    <!-- endbuild -->

    <!-- Google Analytics -->
    <script>
        window.ga = window.ga || function() {
            (ga.q = ga.q || []).push(arguments)
        };
        ga.l = +new Date;
        ga('create', 'UA-76399650-1', 'auto');

    </script>
    <script src='https://www.google-analytics.com/analytics.js' async></script>
    <!-- End Google Analytics -->
</head>

<body layout>

Expected

<!DOCTYPE html>
<html ng-app="MyBelovedApp"
      ng-strict-di="true">

<head>
    <!-- build:base -->
    <base href="/src/app/" />
    <!-- endbuild -->

    <title>My Beloved App</title>

    <meta http-equiv="X-UA-Compatible"
          content="IE=edge" />
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />

    <!-- build:icon -->
    <link rel="shortcut icon"
          href="../assets/favicon64.png" />
    <!-- endbuild -->

    <link href='https://fonts.googleapis.com/css?family=Inconsolata|Open+Sans:300,400'
          rel='stylesheet'
          type='text/css' />

    <!-- build:css -->
    <link rel="stylesheet"
          href="core/styles.css" />
    <!-- endbuild -->

    <!-- Google Analytics -->
    <script>
        window.ga = window.ga || function() {
            (ga.q = ga.q || []).push(arguments)
        };
        ga.l = +new Date;
        ga('create', 'UA-76399650-1', 'auto');
    </script>
    <script src='https://www.google-analytics.com/analytics.js'
            async></script>
    <!-- End Google Analytics -->
</head>

<body layout>

Actual

<!DOCTYPE html>
<html ng-app="MyBelovedApp"
      ng-strict-di="true">

    <head>
        <!-- build:base -->
        <base href="/src/app/" />
        <!-- endbuild -->

        <title>My Beloved App</title>

        <meta http-equiv="X-UA-Compatible"
              content="IE=edge" />
        <meta name="viewport"
              content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />

        <!-- build:icon -->
        <link rel="shortcut icon"
              href="../assets/favicon64.png" />
        <!-- endbuild -->

        <link href='https://fonts.googleapis.com/css?family=Inconsolata|Open+Sans:300,400'
              rel='stylesheet'
              type='text/css' />

        <!-- build:css -->
        <link rel="stylesheet"
              href="core/styles.css" />
        <!-- endbuild -->

        <!-- Google Analytics -->
        <script>
            window.ga = window.ga || function() {
                (ga.q = ga.q || []).push(arguments)
            };
            ga.l = +new Date;
            ga('create', 'UA-76399650-1', 'auto');

        </script>
        <script src='https://www.google-analytics.com/analytics.js'
                async></script>
            <!-- End Google Analytics -->
    </head>

    <body layout>

.jsbeautifyrc config

{
    "indent_char": " ",
    "indent_size": 4,
    "indent_with_tabs": false,
    "eol": "\n",
    "end_with_newline": true,
    "preserve_newlines": true,
    "max_preserve_newlines": 2,

    "html": {
        "wrap_attributes": "force-aligned",
        "wrap_attributes_indent_size": 4,
        "indent_scripts": "normal",
        "indent_inner_html": false
    },

    "css": {
        "newline_between_rules": true,
        "selector_separator_newline": true,
        "space_around_combinator": true
    },

    "js": {
        "jslint_happy": true,
        "keep_array_indentation": false,
        "keep_function_indentation": true
    }
}

Another example of incorrect indentation

All the elements should have the same level of indentation.

        <div class="main-content"
             ui-view></div>

            <div toasts></div>

            <footer>
                My Beloved App &copy; 2017
            </footer>

            <computation-progress></computation-progress>

@HookyQR
Copy link
Owner

HookyQR commented Jan 5, 2017

@schmuli, your's js-beautify issue. It seems that if attribute wrapping is done at all, the indent doesn't come back to where it should. You'll need to log it on the js-beautify repo: https://github.com/beautify-web/js-beautify. @Anbe93, your's is probably related too, but I don't know why it's always wrapping on the for attribute.

@HookyQR
Copy link
Owner

HookyQR commented Jan 5, 2017

I've logged an issue for you: beautifier/js-beautify#1103

@HookyQR
Copy link
Owner

HookyQR commented Feb 10, 2017

New version released with the js-beautify fix manually added.

@HookyQR HookyQR closed this as completed Feb 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants