@ideasonpurpose/build-tools-wordpress 2.1.4 → 2.1.5
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.
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. Dates are d
|
|
|
4
4
|
|
|
5
5
|
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
6
6
|
|
|
7
|
+
#### v2.1.4
|
|
8
|
+
|
|
9
|
+
> 16 April 2025
|
|
10
|
+
|
|
11
|
+
- use look-behind and look-forward to allow overlaps, simplify replacements
|
|
12
|
+
- fix README
|
|
13
|
+
|
|
7
14
|
#### v2.1.3
|
|
8
15
|
|
|
9
16
|
> 16 April 2025
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @ideasonpurpose/build-tools-wordpress
|
|
2
2
|
|
|
3
|
-
#### Version 2.1.
|
|
3
|
+
#### Version 2.1.5
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@ideasonpurpose/build-tools-wordpress)
|
|
6
6
|
[](https://github.com/ideasonpurpose/build-tools-wordpress#readme)
|
|
@@ -73,6 +73,7 @@ export function tokenizeHTML(htmlContent) {
|
|
|
73
73
|
/**
|
|
74
74
|
* special case followup for open-ended PHP tags at the end of the document
|
|
75
75
|
* TODO: Merge this back up into a single pattern
|
|
76
|
+
* Q. Is the 'm' flag breaking the meaning of ^ and $?
|
|
76
77
|
*/
|
|
77
78
|
tokenizedHTML = tokenizedHTML.replace(
|
|
78
79
|
/(?<=((?:[^\s]|\s|^)\s*))(<\?(?:php|=).*$)/gms,
|
|
@@ -93,10 +94,13 @@ export function tokenizeHTML(htmlContent) {
|
|
|
93
94
|
return { tokenizedHTML, phpCodeBlocks };
|
|
94
95
|
}
|
|
95
96
|
|
|
96
|
-
export function unTokenizeHTML(
|
|
97
|
-
let phpContent =
|
|
98
|
-
for (const token in
|
|
99
|
-
phpContent = phpContent.replace(
|
|
97
|
+
export function unTokenizeHTML(tokenizedHTML, phpCodeBlocks) {
|
|
98
|
+
let phpContent = tokenizedHTML;
|
|
99
|
+
for (const token in phpCodeBlocks) {
|
|
100
|
+
phpContent = phpContent.replace(
|
|
101
|
+
new RegExp(token, "g"),
|
|
102
|
+
phpCodeBlocks[token].replace(/\$/g, "$$$$"),
|
|
103
|
+
);
|
|
100
104
|
}
|
|
101
105
|
return phpContent;
|
|
102
106
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ideasonpurpose/build-tools-wordpress",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.5",
|
|
4
4
|
"description": "Build scripts and dependencies for IOP's WordPress development environments.",
|
|
5
5
|
"homepage": "https://github.com/ideasonpurpose/build-tools-wordpress#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -4,7 +4,7 @@ import { describe, expect, test } from "vitest";
|
|
|
4
4
|
|
|
5
5
|
import { readFile } from "node:fs/promises";
|
|
6
6
|
|
|
7
|
-
import { tokenizeHTML } from "../bin/format-php-prettier.js";
|
|
7
|
+
import { tokenizeHTML, unTokenizeHTML } from "../bin/format-php-prettier.js";
|
|
8
8
|
|
|
9
9
|
describe("HTML-PHP Prettier", () => {
|
|
10
10
|
test("All tokens exist", async () => {
|
|
@@ -48,7 +48,6 @@ describe("HTML-PHP Prettier", () => {
|
|
|
48
48
|
expect(tokens).toHaveLength(1);
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
-
|
|
52
51
|
test("bare attribute in tag", async () => {
|
|
53
52
|
const input = (
|
|
54
53
|
await readFile(
|
|
@@ -68,4 +67,22 @@ describe("HTML-PHP Prettier", () => {
|
|
|
68
67
|
|
|
69
68
|
expect(tokens).toHaveLength(5);
|
|
70
69
|
});
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* If code blocks contain JS capture-group replacement strings
|
|
73
|
+
* those strings will vanish from the output.
|
|
74
|
+
*/
|
|
75
|
+
test("$ capture group references bug", async () => {
|
|
76
|
+
const input = (
|
|
77
|
+
await readFile("./test/fixtures/format-php-prettier/regex-string-bug.php")
|
|
78
|
+
).toString();
|
|
79
|
+
|
|
80
|
+
const { tokenizedHTML, phpCodeBlocks } = tokenizeHTML(input);
|
|
81
|
+
|
|
82
|
+
const formattedContent = unTokenizeHTML(tokenizedHTML, phpCodeBlocks);
|
|
83
|
+
|
|
84
|
+
expect(formattedContent).toContain("'a $'");
|
|
85
|
+
expect(formattedContent).toContain("'b $&'");
|
|
86
|
+
expect(formattedContent).toContain("'$0 $1 $2 $3'");
|
|
87
|
+
});
|
|
71
88
|
});
|