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

Prettier: failed to parse buffer — on mixed HTML/PHP file #331

Open
herrbischoff opened this issue Jul 27, 2022 · 1 comment
Open

Prettier: failed to parse buffer — on mixed HTML/PHP file #331

herrbischoff opened this issue Jul 27, 2022 · 1 comment

Comments

@herrbischoff
Copy link

Do you want to request a feature or report a bug?
Either a configuration issue, unsupported functionality or a bug.

What is the current/expected behavior?
When working with PHP template files of the Kirby CMS system, vim-prettier is unable to format the files and aborts with a Prettier: failed to parse buffer error. The file extension and loaded filetype is php (file name is default.php) but contains mostly HTML. Excerpt:

<!DOCTYPE html>
<html lang="de">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta charset="utf-8" />
    <meta name="description" content="something here" />
    <meta name="robots" content="index,follow" />
    <meta name="revisit-after" content="2 days" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title><?= $page->title() ?></title>
    <?= css(["assets/css/main.min.css", "@auto"]) ?>
  </head>
  <body>
    <header class="section">HEADER</header>
    <main class="section">
      <div class="columns">
        <div class="column">
          <article>
[...]

If I install @prettier/plugin-php, the error disappears and the PHP part of the file gets formatted. All of the HTML is left untouched though.

Setting ft=html, either directly or via mode line does not change this behavior, only renaming the file to have an .html extension works. This breaks the CMS expectations regarding file naming however, making this untenable.

Is this a bug or expected behavior? If expected, how do I get this setup to work? I'm looking to format the HTML content of the files. Ideally, the PHP plugin would work as well but I don't care too much about that. Alternatively, as I'm using ALE, I'm very much open regarding ideas how to make this work but I should probably ask their community.

What version of vim-prettier are you using - (output of :PrettierVersion) ?
1.0.0-beta

What version of prettier are you using - (output of :PrettierCliVersion) ?
2.4.1

What is your prettier executable path - (output of :PrettierCliPath) ?
prettier

Did this work in previous versions of vim-prettier and/or prettier ?
unknown

@MDxWARRIORxOP
Copy link

Im getting the same error, but with jsx and nextjs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants