Skip to content

Range Ignore Support in HTML #5508

@donaldpipowitch

Description

@donaldpipowitch

Prettier 1.15.2
Playground link

--parser html

Input:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
</head>
<body>
  <!-- prettier-ignore-start -->
  <%
    // - copies _all_ stage-specific configs from `./config/*.js` into the bundle,
    //   but only `./config/config.js` will be loaded
    // - by default we rename `config.local.js` to `config.js` for development,
    //   but on deployment to a specific stage the corresponding config will be renamed to `config.js`
    // - if you want to use a different config for local development pass `-e STAGE={stage-name}` to `yarn build`/`yarn watch`
    require.context('!copy-loader!./config/', true, /^\.\/.*\.js$/);
    require('!file-loader?name=./config/config.js!./config/config.local.js')
  %>
  <!-- prettier-ignore-end -->
  <script src="/v2/config/config<%= process.env.STAGE ? '.' + process.env.STAGE : '' %>.js"></script>
</body>
</html>

Output:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
  </head>
  <body>
    <!-- prettier-ignore-start -->
    <% // - copies _all_ stage-specific configs from `./config/*.js` into the
    bundle, // but only `./config/config.js` will be loaded // - by default we
    rename `config.local.js` to `config.js` for development, // but on
    deployment to a specific stage the corresponding config will be renamed to
    `config.js` // - if you want to use a different config for local development
    pass `-e STAGE={stage-name}` to `yarn build`/`yarn watch`
    require.context('!copy-loader!./config/', true, /^\.\/.*\.js$/);
    require('!file-loader?name=./config/config.js!./config/config.local.js') %>
    <!-- prettier-ignore-end -->
    <script src="/v2/config/config<%= process.env.STAGE ? '.' + process.env.STAGE : '' %>.js"></script>
  </body>
</html>

Expected behavior:

Keep Input.

Now that HTML support has landed in Prettier it would be nice, if we could use range ignore for the same reasons it is supported in Markdown.

💡 The best solution for the example above would be, if underscore templates could be treated as JavaScript, but range ignore would be a great start to mix HTML with several other templating flavors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:ignore.prettierignore file, --ignore-path CLI option, /* prettier-ignore */ comments and so onarea:rangesIssues about formatting/ignoring/etc segments of fileshelp wantedWe're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue!lang:htmlIssues affecting HTML (and SVG but not JSX)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions