shelving 1.187.2 → 1.187.3
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/markup/rule/inline.js +1 -1
- package/package.json +2 -2
- package/util/template.d.ts +1 -1
- package/util/template.js +26 -17
package/markup/rule/inline.js
CHANGED
|
@@ -3,7 +3,7 @@ import { REACT_ELEMENT_TYPE } from "../util/internal.js";
|
|
|
3
3
|
import { getWordRegExp } from "../util/regexp.js";
|
|
4
4
|
import { getMarkupRule } from "../util/rule.js";
|
|
5
5
|
/** Map characters, e.g. `*`, to their coresponding HTML tag, e.g. `strong` */
|
|
6
|
-
const INLINE_CHARS = { "-": "del", "~": "del", "+": "ins", "*": "strong", _: "em", "=": "mark"
|
|
6
|
+
const INLINE_CHARS = { "-": "del", "~": "del", "+": "ins", "*": "strong", _: "em", "=": "mark" }; // Hyphen must be first so it works when we use the keys as a character class.
|
|
7
7
|
const INLINE_REGEXP = getWordRegExp(`(?<wrap>(?<char>[${Object.keys(INLINE_CHARS).join("")}])+)(?<text>(?!\\k<char>)\\S(?:[\\s\\S]*?(?!\\k<char>)\\S)?)\\k<wrap>`);
|
|
8
8
|
/**
|
|
9
9
|
* Inline strong, emphasis, insert, delete, highlight.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shelving",
|
|
3
|
-
"version": "1.187.
|
|
3
|
+
"version": "1.187.3",
|
|
4
4
|
"author": "Dave Houlbrooke <dave@shax.com>",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"@types/bun": "^1.3.12",
|
|
15
15
|
"@types/react": "^19.2.14",
|
|
16
16
|
"@types/react-dom": "^19.2.3",
|
|
17
|
-
"@typescript/native-preview": "^7.0.0-dev.
|
|
17
|
+
"@typescript/native-preview": "^7.0.0-dev.20260418.1",
|
|
18
18
|
"firebase": "^12.12.0",
|
|
19
19
|
"react": "^19.2.5",
|
|
20
20
|
"react-dom": "^19.2.5",
|
package/util/template.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ImmutableArray } from "./array.js";
|
|
2
2
|
import { type ImmutableDictionary } from "./dictionary.js";
|
|
3
3
|
import { type AnyCaller } from "./function.js";
|
|
4
4
|
import { type NotString, type PossibleString } from "./string.js";
|
package/util/template.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { RequiredError } from "../error/RequiredError.js";
|
|
2
2
|
import { ValueError } from "../error/ValueError.js";
|
|
3
|
+
import { isArray } from "./array.js";
|
|
4
|
+
import { getDataProp, isData } from "./data.js";
|
|
3
5
|
import { EMPTY_DICTIONARY } from "./dictionary.js";
|
|
4
6
|
import { isFunction } from "./function.js";
|
|
5
7
|
import { setMapItem } from "./map.js";
|
|
6
|
-
import { isObject } from "./object.js";
|
|
7
8
|
import { getString } from "./string.js";
|
|
8
9
|
// RegExp to find named variables in several formats e.g. `:a`, `${b}`, `{{c}}` or `{d}`
|
|
9
10
|
const R_PLACEHOLDERS = /(\*\*?|:[a-z][a-z0-9]*|\$\{[a-z][a-z0-9]*\}|\{\{[a-z][a-z0-9]*\}\}|\{[a-z][a-z0-9]*\})/i;
|
|
@@ -114,24 +115,32 @@ export function renderTemplate(template, values, caller = renderTemplate) {
|
|
|
114
115
|
if (!chunks.length)
|
|
115
116
|
return template;
|
|
116
117
|
let output = template;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
118
|
+
if (isFunction(values)) {
|
|
119
|
+
for (const { name, placeholder } of chunks)
|
|
120
|
+
output = output.replace(placeholder, values(name));
|
|
121
|
+
}
|
|
122
|
+
else if (isData(values)) {
|
|
123
|
+
for (const { name, placeholder } of chunks) {
|
|
124
|
+
const v = getString(getDataProp(values, name));
|
|
125
|
+
if (v === undefined)
|
|
126
|
+
throw new RequiredError(`Template placeholder "${name}" not found in object`, { received: values, name, caller });
|
|
127
|
+
output = output.replace(placeholder, v);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else if (isArray(values)) {
|
|
131
|
+
for (const { name, placeholder } of chunks) {
|
|
132
|
+
const v = getString(values[Number(name)]);
|
|
133
|
+
if (v === undefined)
|
|
134
|
+
throw new RequiredError(`Template placeholder "${name}" not found in array`, { received: values, name, caller });
|
|
135
|
+
output = output.replace(placeholder, v);
|
|
136
|
+
}
|
|
129
137
|
}
|
|
130
138
|
else {
|
|
131
|
-
// Single value for all placeholders.
|
|
132
139
|
const v = getString(values);
|
|
133
|
-
if (v
|
|
134
|
-
|
|
140
|
+
if (v === undefined)
|
|
141
|
+
throw new RequiredError(`Template value must be string`, { received: values, caller });
|
|
142
|
+
for (const { placeholder } of chunks)
|
|
143
|
+
output = output.replace(placeholder, v);
|
|
135
144
|
}
|
|
136
|
-
|
|
145
|
+
return output;
|
|
137
146
|
}
|