@videinfra/static-website-builder 1.15.4 → 1.15.6
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 +4 -0
- package/init/test/config/config.js +3 -0
- package/init/test/src/html/preposition.twig +4 -0
- package/package.json +1 -1
- package/plugins/twig/symfony-filters/filters.js +16 -0
- package/plugins/twig/symfony-filters/preposition_nbsp.js +28 -0
- package/tests/preposition_nbsp.test.js +28 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,10 @@ 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.5] - 2025-05-16
|
|
8
|
+
### Added
|
|
9
|
+
- "preposition_nbsp" TWIG filter
|
|
10
|
+
|
|
7
11
|
## [1.15.0] - 2025-01-20
|
|
8
12
|
### Added
|
|
9
13
|
- Env file support
|
package/package.json
CHANGED
|
@@ -78,5 +78,21 @@ module.exports.push({
|
|
|
78
78
|
}
|
|
79
79
|
});
|
|
80
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Preposition filter
|
|
83
|
+
* Adds a non-breaking space between prepositions and other words
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* {{ 'hello at world' | preposition_nbsp }}
|
|
87
|
+
* Output: hello at world
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
const preposition_nbsp = require('./preposition_nbsp');
|
|
81
91
|
|
|
92
|
+
module.exports.push({
|
|
93
|
+
name: 'preposition_nbsp',
|
|
94
|
+
func: function (text) {
|
|
95
|
+
return preposition_nbsp(text);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
82
98
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const prepositions = [
|
|
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
|
+
'в', 'на', 'по', 'к', 'у', 'от', 'из', 'с', 'над', 'под', 'при', 'без', 'до', 'для', 'за', 'через', 'перед', 'около', 'вокруг', 'о', 'об', 'обо', 'про', 'среди', 'между', 'ради', 'вдоль', 'вне', 'кроме', 'сквозь', 'вследствие', 'благодаря', 'согласно', 'вопреки', 'вроде', 'насчёт', 'касательно', 'против', 'со', 'во', 'ко', 'ото', 'изо', 'надо', 'подо', 'передо', 'передо', 'и'
|
|
4
|
+
];
|
|
5
|
+
|
|
6
|
+
// Word boundary regex
|
|
7
|
+
// (?<= # Lookbehind, but don't consume
|
|
8
|
+
// (^| # Start of string or
|
|
9
|
+
// [^\\p{L}] # Non-letter, works with unicode characters too
|
|
10
|
+
const regexWordBoundary = '(?<=(^|[^\\p{L}]))';
|
|
11
|
+
const regexEscape = /[.*+?^${}()|[\]\\]/g;
|
|
12
|
+
|
|
13
|
+
let prepositionsRegex = null;
|
|
14
|
+
|
|
15
|
+
function escapeRegExp(string) {
|
|
16
|
+
return string.replace(regexEscape, '\\$&'); // $& means the whole matched string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function prepositionNbsp(text) {
|
|
20
|
+
if (!prepositionsRegex) {
|
|
21
|
+
const prepositionsEscaped = prepositions.map(preposition => escapeRegExp(preposition));
|
|
22
|
+
prepositionsRegex = new RegExp(`${regexWordBoundary}(${prepositionsEscaped.join('|')})\\s+`, 'uig');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return text.replace(prepositionsRegex, '$2 ');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = prepositionNbsp;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const publicPath = path.resolve(__dirname, 'build', 'public');
|
|
3
|
+
const fs = require('fs')
|
|
4
|
+
const fsPromises = fs.promises;
|
|
5
|
+
|
|
6
|
+
const preposition_nbsp = require('../plugins/twig/symfony-filters/preposition_nbsp');
|
|
7
|
+
|
|
8
|
+
test('preposition_nbsp english', () => {
|
|
9
|
+
expect(preposition_nbsp('hello world')).toEqual('hello world');
|
|
10
|
+
expect(preposition_nbsp('hello at')).toEqual('hello at');
|
|
11
|
+
expect(preposition_nbsp('hello at. world')).toEqual('hello at. world');
|
|
12
|
+
expect(preposition_nbsp('hello at world')).toEqual('hello at world');
|
|
13
|
+
expect(preposition_nbsp('hello before at world')).toEqual('hello before at world');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('preposition_nbsp russian', () => {
|
|
17
|
+
expect(preposition_nbsp('ппппп дддд')).toEqual('ппппп дддд');
|
|
18
|
+
expect(preposition_nbsp('ппппп над')).toEqual('ппппп над');
|
|
19
|
+
expect(preposition_nbsp('ппппп над. дддд')).toEqual('ппппп над. дддд');
|
|
20
|
+
expect(preposition_nbsp('ппппп над дддд')).toEqual('ппппп над дддд');
|
|
21
|
+
expect(preposition_nbsp('ппппп before над дддд')).toEqual('ппппп before над дддд');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('Preposition TWIG filter applied', () => {
|
|
25
|
+
return fsPromises.readFile(path.resolve(publicPath, 'preposition.html'), {'encoding': 'utf8'}).then((html) => {
|
|
26
|
+
expect(html).toBe('<html><body>hello at world</body></html>');
|
|
27
|
+
});
|
|
28
|
+
});
|