@kirigami/php-prepros 3.0.0 → 3.0.1
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/README.md +8 -1
- package/package.json +1 -1
- package/src/libraries/str.class.php +23 -1
package/README.md
CHANGED
|
@@ -34,6 +34,7 @@ Part of the **Kirigami** project ecosystem.
|
|
|
34
34
|
|
|
35
35
|
- [@kirigami/php-prepros](#kirigamiphp-prepros)
|
|
36
36
|
- [Overview](#overview)
|
|
37
|
+
- [What's new in 3.0.1](#whats-new-in-301)
|
|
37
38
|
- [What's new in 3.0.0](#whats-new-in-300)
|
|
38
39
|
- [What's new in 2.0.0](#whats-new-in-200)
|
|
39
40
|
- [What's new in 1.9.3](#whats-new-in-193)
|
|
@@ -105,6 +106,12 @@ Part of the **Kirigami** project ecosystem.
|
|
|
105
106
|
|
|
106
107
|
---
|
|
107
108
|
|
|
109
|
+
## What's new in 3.0.1
|
|
110
|
+
|
|
111
|
+
A registered tag written inside Markdown code is no longer processed. `<markdown>`, `<img asset="...">` or a plugin tag shown in an inline code span (`` `<markdown prose>` ``) or a fenced block (` ``` ` / `~~~`) stays example text: before, a `<markdown>` in a code span paired with the real block's closing tag and broke the rest of the page, and an `<img asset>` in one became an empty image. Indented (four-space) code blocks are not recognized, since `<markdown>` bodies are indented; use a fence there.
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
108
115
|
## What's new in 3.0.0
|
|
109
116
|
|
|
110
117
|
This release switches `YAML::` to the native YAML extension, `MD::` to native mdhtml, `SCHEMA` to native jsonk, and `Normalizer` to native norm. It also includes page types and request lifecycle hooks.
|
|
@@ -1602,7 +1609,7 @@ STR::normalize(string $str): string
|
|
|
1602
1609
|
STR::slug(string $str, string $sep = ''): string
|
|
1603
1610
|
```
|
|
1604
1611
|
|
|
1605
|
-
`STR::replaceTags()` is the engine behind `PREPROS::registerTag()`. It finds all occurrences of `<tagname ...>...</tagname>` in an HTML string and replaces each with the return value of `$callback($fullMatch, $attrs, $body)`.
|
|
1612
|
+
`STR::replaceTags()` is the engine behind `PREPROS::registerTag()`. It finds all occurrences of `<tagname ...>...</tagname>` in an HTML string and replaces each with the return value of `$callback($fullMatch, $attrs, $body)`. Occurrences inside Markdown code (an inline code span or a fenced block) are left as written, so a tag shown as an example is not run.
|
|
1606
1613
|
|
|
1607
1614
|
`STR::trimIndent()` strips the common leading whitespace from a multi-line string — handy when pulling content out of indented `<markdown>` blocks.
|
|
1608
1615
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kirigami/php-prepros",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "PHP preprocessor for the Kirigami static site generator. Compile PHP page templates to clean, deployable HTML — with zero server dependency.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kirigami",
|
|
@@ -18,7 +18,27 @@ class STR
|
|
|
18
18
|
. '|<' . $t . '([^>]*)/>'
|
|
19
19
|
. '|<' . $t . '([^>]*)>#msi';
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
// A tag written inside Markdown code (a fenced block or an inline
|
|
22
|
+
// code span) is example text, not a tag: `<markdown>` shown in a
|
|
23
|
+
// code span must not close the real block around it, and
|
|
24
|
+
// `<img asset="...">` shown in one must not become an image. Mask
|
|
25
|
+
// that code before matching and put it back afterwards, both in the
|
|
26
|
+
// output and in what the callback receives.
|
|
27
|
+
$code = [];
|
|
28
|
+
if (!str_contains($contents, "\x1A")) $contents = preg_replace_callback(
|
|
29
|
+
'#^[ \t]*(`{3,}|~{3,})[^\n]*\n.*?^[ \t]*\1[ \t]*$'
|
|
30
|
+
. '|(?<!`)(`+)(?!`)[^\n]*?(?<!`)\2(?!`)#ms',
|
|
31
|
+
function ($m) use (&$code) {
|
|
32
|
+
$code[] = $m[0];
|
|
33
|
+
return "\x1A" . (count($code) - 1) . "\x1A";
|
|
34
|
+
},
|
|
35
|
+
$contents
|
|
36
|
+
);
|
|
37
|
+
$restore = fn(?string $s) => $s === null || !$code ? $s
|
|
38
|
+
: preg_replace_callback("#\x1A(\d+)\x1A#", fn($m) => $code[$m[1]], $s);
|
|
39
|
+
|
|
40
|
+
$result = preg_replace_callback($pattern, function ($m) use ($clb, $restore) {
|
|
41
|
+
$m = array_map($restore, $m);
|
|
22
42
|
if (isset($m[1]) || isset($m[2])) {
|
|
23
43
|
// paired form: <tag>content</tag>
|
|
24
44
|
$attrs = $m[1] ?? '';
|
|
@@ -34,6 +54,8 @@ class STR
|
|
|
34
54
|
}
|
|
35
55
|
return call_user_func($clb, $m[0], self::parseHtmlAttributes($attrs), $inner);
|
|
36
56
|
}, $contents, -1, $count, PREG_UNMATCHED_AS_NULL); // <-- the flag that fixes everything
|
|
57
|
+
|
|
58
|
+
return $restore($result);
|
|
37
59
|
}
|
|
38
60
|
|
|
39
61
|
|