@videinfra/static-website-builder 1.15.9 → 1.15.11
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.
|
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [1.15.11] - 2025-10-08
|
|
8
|
+
- Updated "preposition_nbsp" TWIG filter
|
|
9
|
+
|
|
10
|
+
## [1.15.10] - 2025-09-26
|
|
11
|
+
- Updated "preposition_nbsp" TWIG filter
|
|
12
|
+
|
|
7
13
|
## [1.15.9] - 2025-09-10
|
|
8
14
|
- Added dashes to the "preposition_nbsp" TWIG filter
|
|
9
15
|
|
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
const prepositions = [
|
|
2
2
|
'about', 'above', 'across', 'after', 'against', 'along', 'amid', 'among', 'around', 'as', 'at', 'before', 'behind', 'below', 'beneath', 'beside', 'besides', 'between', 'beyond', 'by', 'concerning', 'despite', 'down', 'during', 'except', 'for', 'from', 'in', 'inside', 'into', 'like', 'near', 'of', 'off', 'on', 'onto', 'out', 'outside', 'over', 'past', 'regarding', 'round', 'since', 'through', 'throughout', 'to', 'toward', 'towards', 'under', 'underneath', 'until', 'unto', 'up', 'upon', 'with', 'within', 'without', 'a', 'an', 'the',
|
|
3
|
-
'в', 'на', 'по', 'к', 'у', 'от', 'из', 'с', 'над', 'под', 'при', 'без', 'до', 'для', 'за', 'через', 'перед', 'около', 'вокруг', 'о', 'об', 'обо', 'про', 'среди', 'между', 'ради', 'вдоль', 'вне', 'кроме', 'сквозь', 'вследствие', 'благодаря', 'согласно', 'вопреки', 'вроде', 'насчёт', 'касательно', '
|
|
3
|
+
'в', 'на', 'по', 'к', 'у', 'от', 'из', 'с', 'над', 'под', 'при', 'без', 'до', 'для', 'за', 'через', 'перед', 'около', 'вокруг', 'о', 'об', 'обо', 'про', 'среди', 'между', 'ради', 'вдоль', 'вне', 'кроме', 'сквозь', 'вследствие', 'благодаря', 'согласно', 'вопреки', 'вроде', 'насчёт', 'касательно', 'со', 'против', 'во', 'ко', 'ото', 'изо', 'надо', 'подо', 'передо', 'передо', 'из-за', 'чтобы', 'когда', 'его', 'которое', 'как', 'и', 'ей', 'они', 'мы', 'или', 'всё', 'я', 'которое', 'вашей', 'эти', 'что', 'вам', 'не уверены', 'а', 'вы', 'этим', 'вашим', 'все', 'если', 'о которой', 'в этом', 'но', 'которые', 'же', 'ваш', 'этой'
|
|
4
4
|
];
|
|
5
5
|
|
|
6
|
+
|
|
6
7
|
// Word boundary regex
|
|
7
8
|
// (?<= # Lookbehind, but don't consume
|
|
8
9
|
// (^| # Start of string or
|
|
9
10
|
// [^\\p{L}] # Non-letter, works with unicode characters too
|
|
10
11
|
const regexWordBoundary = '(?<=(^|[^\\p{L}]))';
|
|
11
12
|
const regexEscape = /[.*+?^${}()|[\]\\]/g;
|
|
13
|
+
const regexSplitTags = /<[^>]+>/ug;
|
|
12
14
|
|
|
13
15
|
const regexMdash = /\s+—/uig;
|
|
14
16
|
const regexNdash = /\s+–/uig;
|
|
@@ -21,6 +23,7 @@ const regexNdashEntity = /\s+–/uig;
|
|
|
21
23
|
const regexHyphenEntity = /\s+-/uig;
|
|
22
24
|
const regexHyphen2Entity = /\s+‐/uig;
|
|
23
25
|
const regexFigureDashEntity = /\s+‒/uig;
|
|
26
|
+
const regexDashEntity = /\s+‐/uig;
|
|
24
27
|
|
|
25
28
|
let prepositionsRegex = null;
|
|
26
29
|
|
|
@@ -29,26 +32,46 @@ function escapeRegExp(string) {
|
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
function prepositionNbsp(text) {
|
|
35
|
+
if (!text) {
|
|
36
|
+
return '';
|
|
37
|
+
}
|
|
38
|
+
|
|
32
39
|
if (!prepositionsRegex) {
|
|
33
40
|
const prepositionsEscaped = prepositions.map(preposition => escapeRegExp(preposition));
|
|
34
41
|
prepositionsRegex = new RegExp(`${regexWordBoundary}(${prepositionsEscaped.join('|')})\\s+`, 'uig');
|
|
35
42
|
}
|
|
36
43
|
|
|
37
|
-
text
|
|
44
|
+
// Split text into regular text and HTML tags
|
|
45
|
+
const textTags = text.match(regexSplitTags) || [];
|
|
46
|
+
const textNoTags = text.split(regexSplitTags);
|
|
47
|
+
|
|
48
|
+
// Replace prepositions in regular text
|
|
49
|
+
for (let i = 0; i < textNoTags.length; i++) {
|
|
50
|
+
let textPart = textNoTags[i];
|
|
38
51
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
text = text.replace(regexHyphen, ' -', text);
|
|
42
|
-
text = text.replace(regexHyphen2, ' ‐', text);
|
|
43
|
-
text = text.replace(regexFigureDash, ' ‒', text);
|
|
52
|
+
// Replace prepositions with non-breaking space
|
|
53
|
+
textPart = textPart.replace(prepositionsRegex, '$2 ');
|
|
44
54
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
55
|
+
textPart = textPart.replace(regexMdash, ' —', textPart);
|
|
56
|
+
textPart = textPart.replace(regexNdash, ' –', textPart);
|
|
57
|
+
textPart = textPart.replace(regexHyphen, ' -', textPart);
|
|
58
|
+
textPart = textPart.replace(regexHyphen2, ' ‐', textPart);
|
|
59
|
+
textPart = textPart.replace(regexFigureDash, ' ‒', textPart);
|
|
60
|
+
|
|
61
|
+
textPart = textPart.replace(regexMdashEntity, ' —', textPart);
|
|
62
|
+
textPart = textPart.replace(regexNdashEntity, ' –', textPart);
|
|
63
|
+
textPart = textPart.replace(regexHyphenEntity, ' -', textPart);
|
|
64
|
+
textPart = textPart.replace(regexHyphen2Entity, ' ‐', textPart);
|
|
65
|
+
textPart = textPart.replace(regexFigureDashEntity, ' ‒', textPart);
|
|
66
|
+
textPart = textPart.replace(regexDashEntity, ' ‐', textPart);
|
|
67
|
+
|
|
68
|
+
textNoTags[i] = textPart;
|
|
69
|
+
}
|
|
50
70
|
|
|
51
|
-
|
|
71
|
+
// Iterate over regular text and and join back together with tags
|
|
72
|
+
return textNoTags.map((text, index) => {
|
|
73
|
+
return text + (textTags[index] || '');
|
|
74
|
+
}).join('');
|
|
52
75
|
}
|
|
53
76
|
|
|
54
77
|
module.exports = prepositionNbsp;
|
|
@@ -27,6 +27,7 @@ test('preposition_nbsp hyphens', () => {
|
|
|
27
27
|
expect(preposition_nbsp('hello - world')).toEqual('hello - world');
|
|
28
28
|
expect(preposition_nbsp('hello ‐ world')).toEqual('hello ‐ world');
|
|
29
29
|
expect(preposition_nbsp('hello ‒ world')).toEqual('hello ‒ world');
|
|
30
|
+
expect(preposition_nbsp('hello ‐ world')).toEqual('hello ‐ world');
|
|
30
31
|
|
|
31
32
|
// Don't replace hyphens with entities if not needed
|
|
32
33
|
expect(preposition_nbsp('hello— world')).toEqual('hello— world');
|
|
@@ -35,6 +36,12 @@ test('preposition_nbsp hyphens', () => {
|
|
|
35
36
|
expect(preposition_nbsp('hello ‒ at world')).toEqual('hello ‒ at world');
|
|
36
37
|
});
|
|
37
38
|
|
|
39
|
+
test('preposition_nbsp skip tags', () => {
|
|
40
|
+
expect(preposition_nbsp('<a href="https://www.google.com">A nice day</a>')).toEqual('<a href="https://www.google.com">A nice day</a>');
|
|
41
|
+
expect(preposition_nbsp('Start <a download>This is a nice day</a> at <a download>another nice day</a>')).toEqual('Start <a download>This is a nice day</a> at <a download>another nice day</a>');
|
|
42
|
+
expect(preposition_nbsp('<link rel="preload" href="/assets/fonts/...ttf" as="font" type="font/ttf" crossorigin>')).toEqual('<link rel="preload" href="/assets/fonts/...ttf" as="font" type="font/ttf" crossorigin>');
|
|
43
|
+
});
|
|
44
|
+
|
|
38
45
|
test('Preposition TWIG filter applied', () => {
|
|
39
46
|
return fsPromises.readFile(path.resolve(publicPath, 'preposition.html'), {'encoding': 'utf8'}).then((html) => {
|
|
40
47
|
expect(html).toBe('<html><body>hello at world</body></html>');
|