简体   繁体   English

无法使用摩纳哥编辑器以更漂亮的格式工作

[英]Not working in prettier formatting using monaco editor

I'm trying to make an IDE that works in the browser using the Monaco editor.我正在尝试使用 Monaco 编辑器制作可在浏览器中运行的 IDE。 I wanted to use Prettier for a nice formatting.我想使用 Prettier 进行漂亮的格式化。 It only works for Javascript files or only html files.它仅适用于 Javascript 个文件或仅适用于 html 个文件。 However, it does not work on files of the types I have specified below.但是,它不适用于我在下面指定的类型的文件。 How can I fix.我该如何解决。

Expected:预期的: 在此处输入图像描述

Result:结果: 在此处输入图像描述

Also i am getting this error:我也收到此错误: 在此处输入图像描述

    monaco.languages.registerDocumentFormattingEditProvider("javascript", {
            async provideDocumentFormattingEdits(model) {
                alert(1);
                var text1 = prettier.format(model.getValue(), {
                    wrapAttributes: "force",
                    parser: "babel",
                    // plugins: [babel],
                    htmlWhitespaceSensitivity: "ignore",
                    arrowParens: "always",
                    bracketSpacing: true,
                    endOfLine: "lf",
                    insertPragma: false,
                    singleAttributePerLine: false,
                    bracketSameLine: false,
                    printWidth: 400,
                    proseWrap: "preserve",
                    quoteProps: "as-needed",
                    requirePragma: false,
                    semi: true,
                    singleQuote: true,
                    tabWidth: 4,
                    //trailingComma: 'es5',
                    useTabs: false,
                    vueIndentScriptAndStyle: false,
                });

               

                return [
                    {
                        range: model.getFullModelRange(),
                        text: text1,
                    },
                ];
            },
        });
 monaco_scr_editor = monaco.editor.create(document.getElementById("browserIDE"), {
            value: ["<html>Please Wait Loading</html>"].join("\n"),
            language: "javascript",
            theme: "vs-dark",
            wrappingColumn: 0,
            autoIndent: true,
            formatOnPaste: true,
            formatOnType: true,
            wrappingIndent: "indent",
            wordWrap: "off",
            automaticLayout: true,
            overviewRulerLanes: 1,
            overviewRulerBorder: true,
            minimap: { enabled: false },
        });

You need to provide right value for options.parser .您需要为options.parser提供正确的值。

From docs来自文档

options.parser must be set according to the language you are formatting (see the list of available parsers ). options.parser必须根据您正在格式化的语言进行设置(请参阅可用解析器列表)。 Alternatively, options.filepath can be specified for Prettier to infer the parser from the file extension.或者,可以为 Prettier 指定options.filepath以从文件扩展名推断解析器。

so set it to parser: "html" .所以将它设置为parser: "html"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM