From 62626128ec1fb7290cf9a99037e8023fe97f7321 Mon Sep 17 00:00:00 2001 From: i18n Date: Mon, 27 Jan 2025 02:02:32 +0800 Subject: [PATCH 1/4] fix template pug format --- src/embed.ts | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/embed.ts b/src/embed.ts index 195bc62..1eaa129 100644 --- a/src/embed.ts +++ b/src/embed.ts @@ -293,17 +293,21 @@ async function formatBodyContent( if (parser === 'pug' && typeof body === 'string') { // Pug returns no docs but a final string. // Therefore prepend the line offsets - const whitespace = options.useTabs - ? '\t' - : ' '.repeat( - options.pugTabWidth && options.pugTabWidth > 0 - ? options.pugTabWidth - : options.tabWidth, - ); - const pugBody = body - .split('\n') - .map((line) => (line ? whitespace + line : line)) - .join('\n'); + let pugBody = body; + if(options.svelteIndentScriptAndStyle){ + const whitespace = options.useTabs + ? '\t' + : ' '.repeat( + options.pugTabWidth && options.pugTabWidth > 0 + ? options.pugTabWidth + : options.tabWidth, + ); + pugBody = body + .split('\n') + .map((line) => (line ? whitespace + line : line)) + .join('\n'); + } + if(!pugBody.endsWith('\n')) pugBody += '\n'; return [hardline, pugBody]; } From a5ed1ef1ff7963235b5f44f8663553ac8e088943 Mon Sep 17 00:00:00 2001 From: i18n Date: Wed, 5 Feb 2025 14:53:19 +0800 Subject: [PATCH 2/4] add support for stylus --- src/embed.ts | 7 ++++--- src/print/node-helpers.ts | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/embed.ts b/src/embed.ts index 1eaa129..73d6e35 100644 --- a/src/embed.ts +++ b/src/embed.ts @@ -13,6 +13,7 @@ import { isInsideQuotedAttribute, isJSON, isLess, + isStylus, isNodeSupportedLanguage, isPugTemplate, isScss, @@ -196,7 +197,7 @@ export function embed(path: AstPath, _options: Options) { const embedType = ( tag: 'script' | 'style' | 'template', - parser: 'typescript' | 'babel-ts' | 'css' | 'scss' | 'less' | 'pug' | 'json', + parser: 'typescript' | 'babel-ts' | 'css' | 'scss' | 'less' | 'stylus | 'pug' | 'json', isTopLevel: boolean, ) => { return async ( @@ -226,7 +227,7 @@ export function embed(path: AstPath, _options: Options) { isTopLevel, ); const embedStyle = (isTopLevel: boolean) => - embedType('style', isLess(node) ? 'less' : isScss(node) ? 'scss' : 'css', isTopLevel); + embedType('style', isStylus(node) ? 'stylus' : isLess(node) ? 'less' : isScss(node) ? 'scss' : 'css', isTopLevel); const embedPug = () => embedType('template', 'pug', false); switch (node.type) { @@ -283,7 +284,7 @@ function getSnippedContent(node: Node) { async function formatBodyContent( content: string, - parser: 'typescript' | 'babel-ts' | 'css' | 'scss' | 'less' | 'pug' | 'json', + parser: 'typescript' | 'babel-ts' | 'css' | 'scss' | 'less' | 'stylus | 'pug' | 'json', textToDoc: (text: string, options: object) => Promise, options: ParserOptions & { pugTabWidth?: number }, ) { diff --git a/src/print/node-helpers.ts b/src/print/node-helpers.ts index 4f820fc..926694b 100644 --- a/src/print/node-helpers.ts +++ b/src/print/node-helpers.ts @@ -280,6 +280,11 @@ export function isLess(node: Node) { return ['less'].includes(lang); } +export function isStylus(node: Node) { + const lang = getLangAttribute(node) || ''; + return ['stylus'].includes(lang); +} + export function isScss(node: Node) { const lang = getLangAttribute(node) || ''; return ['sass', 'scss'].includes(lang); From def8ff5944e7132b465d0703aa57db72601bd502 Mon Sep 17 00:00:00 2001 From: i18n Date: Wed, 5 Feb 2025 14:55:41 +0800 Subject: [PATCH 3/4] fix --- src/embed.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/embed.ts b/src/embed.ts index 73d6e35..6f31550 100644 --- a/src/embed.ts +++ b/src/embed.ts @@ -197,7 +197,7 @@ export function embed(path: AstPath, _options: Options) { const embedType = ( tag: 'script' | 'style' | 'template', - parser: 'typescript' | 'babel-ts' | 'css' | 'scss' | 'less' | 'stylus | 'pug' | 'json', + parser: 'typescript' | 'babel-ts' | 'css' | 'scss' | 'less' | 'stylus' | 'pug' | 'json', isTopLevel: boolean, ) => { return async ( @@ -284,7 +284,7 @@ function getSnippedContent(node: Node) { async function formatBodyContent( content: string, - parser: 'typescript' | 'babel-ts' | 'css' | 'scss' | 'less' | 'stylus | 'pug' | 'json', + parser: 'typescript' | 'babel-ts' | 'css' | 'scss' | 'less' | 'stylus' | 'pug' | 'json', textToDoc: (text: string, options: object) => Promise, options: ParserOptions & { pugTabWidth?: number }, ) { From 22e6f247c8339bbc9416e80aff73a17ef7ad2059 Mon Sep 17 00:00:00 2001 From: i18n Date: Wed, 5 Feb 2025 15:24:35 +0800 Subject: [PATCH 4/4] fix --- src/print/node-helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/print/node-helpers.ts b/src/print/node-helpers.ts index 926694b..1165571 100644 --- a/src/print/node-helpers.ts +++ b/src/print/node-helpers.ts @@ -29,7 +29,7 @@ import { AstPath } from 'prettier'; import { findLastIndex, isASTNode, isPreTagContent } from './helpers'; import { ParserOptions, isBracketSameLine } from '../options'; -const unsupportedLanguages = ['coffee', 'coffeescript', 'styl', 'stylus', 'sass']; +const unsupportedLanguages = ['coffee', 'coffeescript', 'sass']; export function isInlineElement(path: AstPath, options: ParserOptions, node: Node) { return (