@daz4126/swifty 2.6.0 → 2.6.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/package.json +1 -1
- package/src/partials.js +14 -11
package/package.json
CHANGED
package/src/partials.js
CHANGED
|
@@ -34,7 +34,17 @@ const replacePlaceholders = async (template, values) => {
|
|
|
34
34
|
return str.replace(regex, () => results.shift());
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
//
|
|
37
|
+
// Protect code blocks BEFORE any placeholder replacement
|
|
38
|
+
// Fenced blocks require closing ``` to be at start of line (after newline)
|
|
39
|
+
const codeBlockRegex =
|
|
40
|
+
/```[\s\S]*?\n```|`[^`\n]+`|<(pre|code)[^>]*>[\s\S]*?<\/\1>/g;
|
|
41
|
+
const codeBlocks = [];
|
|
42
|
+
template = template.replace(codeBlockRegex, (match) => {
|
|
43
|
+
codeBlocks.push(match);
|
|
44
|
+
return `{{CODE_BLOCK_${codeBlocks.length - 1}}}`; // Temporary placeholder
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Replace partial includes (now only outside code blocks)
|
|
38
48
|
template = await replaceAsync(
|
|
39
49
|
template,
|
|
40
50
|
partialRegex,
|
|
@@ -44,16 +54,8 @@ const replacePlaceholders = async (template, values) => {
|
|
|
44
54
|
return marked(partialContent); // Convert Markdown to HTML
|
|
45
55
|
},
|
|
46
56
|
);
|
|
47
|
-
|
|
48
|
-
//
|
|
49
|
-
const codeBlockRegex =
|
|
50
|
-
/```[\s\S]*?\n```|`[^`\n]+`|<(pre|code)[^>]*>[\s\S]*?<\/\1>/g;
|
|
51
|
-
const codeBlocks = [];
|
|
52
|
-
template = template.replace(codeBlockRegex, (match) => {
|
|
53
|
-
codeBlocks.push(match);
|
|
54
|
-
return `{{CODE_BLOCK_${codeBlocks.length - 1}}}`; // Temporary placeholder
|
|
55
|
-
});
|
|
56
|
-
// Replace placeholders outside of code blocks
|
|
57
|
+
|
|
58
|
+
// Replace other placeholders outside of code blocks
|
|
57
59
|
template = template.replace(/{{\s*([^}\s]+)\s*}}/g, (match, key) => {
|
|
58
60
|
return values.data && key in values?.data
|
|
59
61
|
? values.data[key]
|
|
@@ -61,6 +63,7 @@ const replacePlaceholders = async (template, values) => {
|
|
|
61
63
|
? values[key]
|
|
62
64
|
: match;
|
|
63
65
|
});
|
|
66
|
+
|
|
64
67
|
// Restore code blocks
|
|
65
68
|
template = template.replace(
|
|
66
69
|
/{{CODE_BLOCK_(\d+)}}/g,
|