@ideasonpurpose/build-tools-wordpress 2.1.3 → 2.1.4

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,12 @@ 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.3
8
+
9
+ > 16 April 2025
10
+
11
+ - Use self-closing html tags as tokens. Closes #11
12
+
7
13
  #### v2.1.2
8
14
 
9
15
  > 14 April 2025
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @ideasonpurpose/build-tools-wordpress
2
2
 
3
- #### Version 2.1.3
3
+ #### Version 2.1.4
4
4
 
5
5
  [![NPM Version](https://img.shields.io/npm/v/%40ideasonpurpose%2Fbuild-tools-wordpress?logo=npm)](https://www.npmjs.com/package/@ideasonpurpose/build-tools-wordpress)
6
6
  [![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ideasonpurpose/build-tools-wordpress/npm-publish.yml?logo=github&logoColor=white)](https://github.com/ideasonpurpose/build-tools-wordpress#readme)
@@ -44,7 +44,7 @@ Running a simple watch script to re-install on changes will make things somewhat
44
44
  ```sh
45
45
  cd dev-project-working-dir
46
46
  npm chokidar-cli "../../build-tools-wordpress/**/*" -c "npm install"
47
-
47
+ ```
48
48
 
49
49
  ### Additional Notes
50
50
 
@@ -46,27 +46,50 @@ export function tokenizeHTML(htmlContent) {
46
46
  // const pattern = /<\?(?:php|=)[\s\S]*?\?>/gs;
47
47
  // const pattern =
48
48
  // /(?<before>(?:[^\s]|\s|^)\s*)(?<php><\?(?:php|=).*?(?:\?>|$))(?<after>(?:\s*)[^\s]|$)/gs;
49
+ // const pattern =
50
+ // /((?:[^\s]|\s|^)\s*)(<\?(?:php|=).*?(?:\?>|$))((?:\s*)[^\s]|$)/gms;
51
+ // // const pattern = /([^\s]+)\s*(<\?(?:php|=).*?(?:\?>|$))\s*([^\s]*)/gms;
52
+ // const pattern =
53
+ // /([^\s]?\s*)?(<\?(?:php|=).*?(?:\?>|$))((?:\s*)[^\s]|$)/gms;
49
54
  const pattern =
50
- /((?:[^\s]|\s|^)\s*)(<\?(?:php|=).*?(?:\?>|$))((?:\s*)[^\s]|$)/gs;
55
+ /(?<=((?:[^\s]|\s|^)\s*))(<\?(?:php|=).*?\?>)(?=((?:\s*)[^\s]|$))/gms;
51
56
 
52
- const tokenizedHTML = htmlContent.replace(
57
+ let tokenizedHTML = htmlContent.replace(
53
58
  pattern,
54
59
  (string, before, phpCodeBlock, after, offset) => {
55
60
  const start = [">", ""].includes(before.trim()) ? "<" : "_";
56
61
  const end = ["<", ""].includes(after.trim()) ? " />" : "___";
57
62
 
58
- console.log({offset, string, before, phpCodeBlock, after, offset });
63
+ // end-pad the token to the length of the span, up to 80 characters
64
+ const codeLength = Math.min(phpCodeBlock.length, 80 - end.length);
65
+ const token =
66
+ `${start}php_${tokenCount++}__`.padEnd(codeLength, "_") + end;
67
+ phpCodeBlocks[token] = phpCodeBlock;
68
+
69
+ return token;
70
+ },
71
+ );
72
+
73
+ /**
74
+ * special case followup for open-ended PHP tags at the end of the document
75
+ * TODO: Merge this back up into a single pattern
76
+ */
77
+ tokenizedHTML = tokenizedHTML.replace(
78
+ /(?<=((?:[^\s]|\s|^)\s*))(<\?(?:php|=).*$)/gms,
79
+
80
+ (string, before, phpCodeBlock, offset) => {
81
+ const start = [">", ""].includes(before.trim()) ? "<" : "_";
82
+ const end = start === "<" ? " />" : "___";
59
83
 
60
- // end-pad the token to the lengh of the span, up to 80 characters
61
84
  const codeLength = Math.min(phpCodeBlock.length, 80 - end.length);
62
85
  const token =
63
86
  `${start}php_${tokenCount++}__`.padEnd(codeLength, "_") + end;
64
87
  phpCodeBlocks[token] = phpCodeBlock;
65
- return `${before}${token}${after}`;
88
+
89
+ return token;
66
90
  },
67
91
  );
68
92
 
69
- console.log({ tokenizedHTML, phpCodeBlocks });
70
93
  return { tokenizedHTML, phpCodeBlocks };
71
94
  }
72
95
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ideasonpurpose/build-tools-wordpress",
3
- "version": "2.1.3",
3
+ "version": "2.1.4",
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": {
@@ -0,0 +1,20 @@
1
+
2
+
3
+
4
+ <!-- START template-parts/items/card.php -->
5
+
6
+ <a
7
+ href="<?php the_permalink(); ?>"
8
+ <?php post_class('card col-12 col-md-6'); ?>
9
+ data-ga-action="Article"
10
+ >
11
+ <?php get_template_part('template-parts/partials/card-media'); ?>
12
+ <div class="card__details">
13
+ <h4 class="card__title"><?= $cardTitle ?></h4>
14
+ <h5 class="card__desc"><?= $cardDesc ?></h5>
15
+ </div>
16
+ </a>
17
+
18
+ <!-- END template-parts/items/card.php -->
19
+
20
+
@@ -34,18 +34,38 @@ describe("HTML-PHP Prettier", () => {
34
34
  expect(tokens[3]).toMatch(/^<php_\d+_* \/>$/);
35
35
  });
36
36
 
37
- test("single open PHP code block #11"),
38
- async () => {
39
- const input = (
40
- await readFile(
41
- "./test/fixtures/format-php-prettier/single-open-php-block.php",
42
- )
43
- ).toString();
37
+ test("single open PHP code block #11", async () => {
38
+ const input = (
39
+ await readFile(
40
+ "./test/fixtures/format-php-prettier/single-open-php-block.php",
41
+ )
42
+ ).toString();
43
+
44
+ const { phpCodeBlocks: codeBlocks } = tokenizeHTML(input);
45
+
46
+ const tokens = Object.keys(codeBlocks);
47
+
48
+ expect(tokens).toHaveLength(1);
49
+ });
44
50
 
45
- const { phpCodeBlocks: codeBlocks } = tokenizeHTML(input);
46
51
 
47
- const tokens = Object.keys(codeBlocks);
52
+ test("bare attribute in tag", async () => {
53
+ const input = (
54
+ await readFile(
55
+ "./test/fixtures/format-php-prettier/card-attribute-bug.php",
56
+ )
57
+ ).toString();
48
58
 
49
- expect(tokens).toHaveLength(1);
50
- };
59
+ const { phpCodeBlocks: codeBlocks } = tokenizeHTML(input);
60
+
61
+ const tokens = Object.keys(codeBlocks);
62
+
63
+ expect(tokens[0]).toMatch(/^_php_\d+_*$/);
64
+ expect(tokens[1]).toMatch(/^_php_\d+_*$/);
65
+ expect(tokens[2]).toMatch(/^<php_\d+_* \/>$/);
66
+ expect(tokens[3]).toMatch(/^<php_\d+_* \/>$/);
67
+ expect(tokens[4]).toMatch(/^<php_\d+_* \/>$/);
68
+
69
+ expect(tokens).toHaveLength(5);
70
+ });
51
71
  });