prettier-plugin-templ-script
Advanced tools
Comparing version
12
index.js
@@ -22,7 +22,13 @@ import prettier from 'prettier'; | ||
const { text } = path.getValue(); | ||
const matches = text.matchAll(/^(\s*)<script>([\s\S]+?)<\/script>$/gm); | ||
const scriptRegex = /^(\s*)<script([^>]*?)>([\s\S]+?)<\/script>$/gm; | ||
const matches = text.matchAll(scriptRegex); | ||
let transformedText = text; | ||
try { | ||
for (const [match, leadingWhitespace, scriptContent] of matches) { | ||
for (const [ | ||
match, | ||
leadingWhitespace, | ||
scriptAttributes, | ||
scriptContent, | ||
] of matches) { | ||
const formattedScript = await prettier.format(scriptContent.trim(), { | ||
@@ -39,3 +45,3 @@ ...options, | ||
const replacementScript = `${leadingWhitespace}<script>\n${indentedScript}\n${leadingWhitespace}</script>`; | ||
const replacementScript = `${leadingWhitespace}<script${scriptAttributes}>\n${indentedScript}\n${leadingWhitespace}</script>`; | ||
transformedText = transformedText.replace(match, replacementScript); | ||
@@ -42,0 +48,0 @@ } |
{ | ||
"name": "prettier-plugin-templ-script", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Prettier plugin for `<script>` tags in templ.", | ||
@@ -5,0 +5,0 @@ "repository": "github:therealparmesh/prettier-plugin-templ-script", |
3083
4.58%48
14.29%