prettier-plugin-ejs 0.0.13 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +18 -2
  2. package/index.js +21 -17
  3. package/package.json +10 -17
package/README.md CHANGED
@@ -8,6 +8,16 @@ This plugin formats [EJS](https://ejs.co/) markup in `html` files. It uses the d
8
8
  npm install --save-dev prettier-plugin-ejs
9
9
  ```
10
10
 
11
+ For Prettier v2, the plugin will be loaded automatically.
12
+
13
+ For Prettier v3, you'll need to manually load the plugin:
14
+
15
+ ```sh
16
+ prettier --plugin=prettier-plugin-ejs --write .
17
+ ```
18
+
19
+ Please check [Prettier Docs](https://prettier.io/docs/en/plugins.html) for other loading methods.
20
+
11
21
  ## Example
12
22
 
13
23
  ### Before
@@ -21,12 +31,13 @@ npm install --save-dev prettier-plugin-ejs
21
31
 
22
32
  <!-- prettier-ignore -->
23
33
  <div>
24
- <%
34
+ <%
25
35
  const a = 0;
26
36
  %>
27
37
  </div>
28
38
 
29
39
  <div class="<%= red %>"><%= 1 > 0 %></div>
40
+
30
41
  <textarea><%= text %></textarea>
31
42
  <code><%= text %></code>
32
43
  <pre><%= text %></pre>
@@ -43,9 +54,14 @@ npm install --save-dev prettier-plugin-ejs
43
54
  <% } %>
44
55
  </div>
45
56
 
46
- <div><% const a = 0; %></div>
57
+ <div>
58
+ <%
59
+ const a = 0;
60
+ %>
61
+ </div>
47
62
 
48
63
  <div class="<%= red %>"><%= 1 > 0 %></div>
64
+
49
65
  <textarea><%= text %></textarea>
50
66
  <code><%= text %></code>
51
67
  <pre><%= text %></pre>
package/index.js CHANGED
@@ -1,22 +1,26 @@
1
- 'use strict';
1
+ const { parsers } = require("prettier/parser-html");
2
2
 
3
- var parserHtml = require('prettier/parser-html');
3
+ const regex =
4
+ /"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|<(?:title|textarea).*?<\/|(<%([^>]*?)%>)/gs;
4
5
 
5
- const regex = /"[^"]*"|<textarea.*?<\/textarea|(<%([^>]*?)%>)/gs;
6
- function parse(text, parsers, options) {
7
- return parserHtml.parsers.html.parse(text.replace(regex, (m, t, c) => (!t ? m : `<?${c}?>`)), parsers, options);
6
+ const replacer = (m, t, c) => (!t ? m : `<!${c}!>`);
7
+
8
+ function parse(text, options, legacy) {
9
+ return parsers.html.parse(text.replace(regex, replacer), options, legacy);
8
10
  }
9
- var index = {
10
- languages: [
11
- {
12
- name: "EJS",
13
- parsers: ["html"],
14
- extensions: [".ejs"],
15
- },
16
- ],
17
- parsers: {
18
- html: Object.assign(Object.assign({}, parserHtml.parsers.html), { parse }),
11
+
12
+ module.exports = {
13
+ languages: [
14
+ {
15
+ name: "EJS",
16
+ parsers: ["html"],
17
+ extensions: [".ejs"],
19
18
  },
19
+ ],
20
+ parsers: {
21
+ html: {
22
+ ...parsers.html,
23
+ parse,
24
+ },
25
+ },
20
26
  };
21
-
22
- module.exports = index;
package/package.json CHANGED
@@ -1,43 +1,36 @@
1
1
  {
2
2
  "name": "prettier-plugin-ejs",
3
3
  "displayName": "Prettier EJS Plugin",
4
- "version": "0.0.13",
5
- "description": "A prettier plugin for Embedded JavaScript Templating.",
4
+ "version": "0.0.15",
5
+ "description": "A Prettier plugin for Embedded JavaScript Templating (EJS).",
6
6
  "keywords": [
7
7
  "prettier",
8
8
  "plugin",
9
9
  "ejs",
10
10
  "html"
11
11
  ],
12
- "repository": {
13
- "type": "git",
14
- "url": "https://github.com/ecmel/prettier-plugin-ejs.git"
15
- },
16
12
  "author": {
17
13
  "name": "Ecmel Ercan",
18
14
  "url": "https://github.com/ecmel"
19
15
  },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/ecmel/prettier-plugin-ejs.git"
19
+ },
20
20
  "license": "MIT",
21
21
  "files": [
22
22
  "index.js"
23
23
  ],
24
24
  "main": "index.js",
25
+ "type": "commonjs",
25
26
  "scripts": {
26
27
  "clean": "git clean -Xdf",
27
- "format": "prettier --ignore-path .gitignore --write .",
28
- "build": "rollup -c",
29
- "prepack": "npm run clean && npm install && npm run build"
28
+ "format": "prettier --ignore-path=.gitignore --plugin=./index.js --write ."
30
29
  },
31
30
  "devDependencies": {
32
- "@rollup/plugin-typescript": "^11.1.2",
33
- "@types/prettier": "^2.7.3",
34
- "prettier": "^2.8.8",
35
- "prettier-plugin-ejs": "file:../prettier-plugin-ejs",
36
- "rollup": "^3.27.0",
37
- "tslib": "^2.6.1",
38
- "typescript": "^5.1.6"
31
+ "prettier": "^2.8.8"
39
32
  },
40
33
  "peerDependencies": {
41
- "prettier": "2.x"
34
+ "prettier": "2.x - 3.x"
42
35
  }
43
36
  }