✨(DocPlugin): usePlayGround 自动格式化 CSS 语句
This commit is contained in:
		
							parent
							
								
									e3c2b471b3
								
							
						
					
					
						commit
						d3d5f1e1a6
					
				@ -100,16 +100,14 @@ function trimBr(str: string): string {
 | 
				
			|||||||
 * @returns 格式化代码
 | 
					 * @returns 格式化代码
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
async function formatCode(filename: string, data: string) {
 | 
					async function formatCode(filename: string, data: string) {
 | 
				
			||||||
  const { format } = await import("prettier/standalone");
 | 
					  const [format, parserHtml, parserTypeScript, parserBabel, parserPostcss] =
 | 
				
			||||||
  const parserTypeScript = await import("prettier/parser-typescript").then(
 | 
					    await Promise.all([
 | 
				
			||||||
    (m) => m.default
 | 
					      import("prettier/standalone").then((r) => r.format),
 | 
				
			||||||
  );
 | 
					      import("prettier/parser-html").then((m) => m.default),
 | 
				
			||||||
  const parserBabel = await import("prettier/parser-babel").then(
 | 
					      import("prettier/parser-typescript").then((m) => m.default),
 | 
				
			||||||
    (m) => m.default
 | 
					      import("prettier/parser-babel").then((m) => m.default),
 | 
				
			||||||
  );
 | 
					      import("prettier/parser-postcss").then((m) => m.default),
 | 
				
			||||||
  const parserHtml = await import("prettier/parser-html").then(
 | 
					    ]);
 | 
				
			||||||
    (m) => m.default
 | 
					 | 
				
			||||||
  );
 | 
					 | 
				
			||||||
  let code = data;
 | 
					  let code = data;
 | 
				
			||||||
  let parser: BuiltInParserName;
 | 
					  let parser: BuiltInParserName;
 | 
				
			||||||
  if (filename.endsWith(".vue")) {
 | 
					  if (filename.endsWith(".vue")) {
 | 
				
			||||||
@ -125,7 +123,7 @@ async function formatCode(filename: string, data: string) {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
  code = format(code, {
 | 
					  code = format(code, {
 | 
				
			||||||
    parser,
 | 
					    parser,
 | 
				
			||||||
    plugins: [parserHtml, parserTypeScript, parserBabel],
 | 
					    plugins: [parserHtml, parserTypeScript, parserBabel, parserPostcss],
 | 
				
			||||||
    semi: false, // 语句末尾打印分号
 | 
					    semi: false, // 语句末尾打印分号
 | 
				
			||||||
    singleQuote: true, // 使用单引号
 | 
					    singleQuote: true, // 使用单引号
 | 
				
			||||||
    vueIndentScriptAndStyle: false, // 是否缩进 Vue 文件中的 script 和 style 标签
 | 
					    vueIndentScriptAndStyle: false, // 是否缩进 Vue 文件中的 script 和 style 标签
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user