prettier-plugin-jsp
Advanced tools
Comparing version
{ | ||
"name": "prettier-plugin-jsp", | ||
"description": "Format JSP using Prettier", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"main": "plugin.js", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -7,3 +7,10 @@ const { parsers } = require("prettier/parser-html"); | ||
const ESCAPE_TOKEN = "____"; | ||
const ESCAPE_TAG_COLON = "__colon__"; | ||
const ESCAPE_TAG_DASH = "__dash__"; | ||
const ESCAPE_TAG_COLON_REGEX = /<(\s*\/\s*)?(\w+):(\w)/g; | ||
const ESCAPE_TAG_DASH_REGEX = /<(\s*\/\s*)?(\w+)-(\w)/g; | ||
const ESCAPE_JSP_TAG_REGEX = /<%@([\w\W]+?)%>/g; | ||
const ESCAPE_JSP_COMMENT_REGEX = /<%--([\w\W]+?)--%>/g; | ||
const ESCAPE_ATTRS_REGEX = /<([\w]+)([\s\S]*?)>/g; | ||
const ESCAPE_ATTR_REGEX = /\$\{(.+?)\}/g; | ||
@@ -15,8 +22,9 @@ const parser = { | ||
return text | ||
.replace(/<%@([\w\W]+?)%>/g, "<JSP $1 />") | ||
.replace(/<%--([\w\W]+?)--%>/g, "<!-- $1 -->") | ||
.replace(/<(\s*\/\s*)?(\w+):(\w)/g, `<$1$2${ESCAPE_TOKEN}$3`) | ||
.replace(/<([\w]+)([\s\S]*?)>/g, (_, m1, m2) => { | ||
.replace(ESCAPE_JSP_TAG_REGEX, "<JSP $1 />") | ||
.replace(ESCAPE_JSP_COMMENT_REGEX, "<!-- $1 -->") | ||
.replace(ESCAPE_TAG_COLON_REGEX, `<$1$2${ESCAPE_TAG_COLON}$3`) | ||
.replace(ESCAPE_TAG_DASH_REGEX, `<$1$2${ESCAPE_TAG_DASH}$3`) | ||
.replace(ESCAPE_ATTRS_REGEX, (_, m1, m2) => { | ||
const attrs = m2.replace( | ||
/\$\{(.+?)\}/, | ||
ESCAPE_ATTR_REGEX, | ||
(_, m1) => "${" + quotation.escape(m1) + "}" | ||
@@ -82,5 +90,6 @@ ); | ||
} else { | ||
if (node.type === "element" && node.name.includes(ESCAPE_TOKEN)) { | ||
node.name = node.name.replace(ESCAPE_TOKEN, ":"); | ||
} | ||
if (node.type === "element" && node.name.includes(ESCAPE_TAG_COLON)) | ||
node.name = node.name.replace(ESCAPE_TAG_COLON, ":"); | ||
if (node.type === "element" && node.name.includes(ESCAPE_TAG_DASH)) | ||
node.name = node.name.replace(ESCAPE_TAG_DASH, "-"); | ||
return getPrinter(options).print(path, options, print); | ||
@@ -87,0 +96,0 @@ } |
117
0.86%6250
-76.39%5
-54.55%