|
I'm writing a web extension that uses highlight.js (was using Prism previously) and Prettier to format code on a webpage. Since I am using standalone Prettier, I have to add the plugins to the Prettier.format() call directly. The included plugins (typescript, estree, babel, etc.) import fine with require() statements, but I cannot figure out how to do this for the prettier-java-plugin. I posted an Issue on their github page, but haven't received a response as of yet so figured I'd try my luck here. More info/code samples on my stack-overflow post |
Replies: 1 comment
|
Hi, @nop990! I made a minimal working example here: https://github.com/Poliklot/prettier-plugin-java-standalone-browser-example The main issue is that The important part is: import * as prettier from "prettier/standalone";
import prettierPluginJava from "prettier-plugin-java";
const formatted = await prettier.format(source, {
parser: "java",
plugins: [prettierPluginJava],
});I used npm install
npm run start:csp-likeSo the Prettier standalone API itself works with |
Hi, @nop990!
I made a minimal working example here:
https://github.com/Poliklot/prettier-plugin-java-standalone-browser-example
The main issue is that
prettier/standalonedoes not auto-load plugins fromnode_modules. The Java plugin has to be imported and passed directly toplugins.The important part is:
I used
esbuildinstead of Browserify. From a fresh clone this works:So the Prettier standalone API itself works with
prettier-plugin-java. Thepβ¦