openvibers/openvibe.work Commits
No space before a full stop in a listing's text (#182)
Changes
@@@ -45,7 +45,9 @@ function stripHtml(html) {if (/<\/?(p|div|span|br|ul|ol|li|a|b|i|em|strong|h[1-6]|table|tr|td|section|article|blockquote|pre|code|img|hr|script|style)\b[^>]*>/i.test(s)) s = stripOnce(s);// An unmatched '<' left by broken markup is not something a listing should show.s = s.replace(/<[^>]*$/g, ' ').replace(/[<>]/g, ' ');-- return s.replace(/\s+/g, ' ').trim();++ // A block boundary turned into a space can land before the sentence's own stop ("Operations . Deine Aufgaben" on++ // the home, 2026-11-02): no space before a full stop or comma that ends a word (".NET" keeps its dot).++ return s.replace(/\s+/g, ' ').replace(/ ([.,])(?=\s|$)/g, '$1').trim();}/** The excerpt: the first ~300 characters of the plain text, cut on a word, with a trailing ellipsis. */@@@ -88,6 +88,10 @@ const DAY = 86_400_000;const { stripHtml, excerpt, EXCERPT_CHARS } = require('../server/jobs/text');assert.strictEqual(stripHtml('<p>Hello <b>world</b> — it's 5 & 6 <ok></p>'), "Hello world — it's 5 & 6 ok");assert.strictEqual(stripHtml('<div>a</div><div>b</div>'), 'a b');++ // A block boundary before the sentence's own stop leaves no space before it (2026-11-02, a German listing);++ // a dot that starts a word stays (".NET").++ assert.strictEqual(stripHtml('<p><strong>Application Operations</strong> . Deine Aufgaben</p>'), 'Application Operations. Deine Aufgaben');++ assert.strictEqual(stripHtml('C# and .NET , SQL .'), 'C# and .NET, SQL.');assert.strictEqual(stripHtml('<style>p{color:red}</style><p>real</p>'), 'real');assert.strictEqual(stripHtml('<script>alert(1)</script>'), '');assert.strictEqual(stripHtml(null), '');
@@ -45,7 +45,9 @@ function stripHtml(html) {
@@ -45,7 +45,9 @@ function stripHtml(html) {
if (/<\/?(p|div|span|br|ul|ol|li|a|b|i|em|strong|h[1-6]|table|tr|td|section|article|blockquote|pre|code|img|hr|script|style)\b[^>]*>/i.test(s)) s = stripOnce(s);
if (/<\/?(p|div|span|br|ul|ol|li|a|b|i|em|strong|h[1-6]|table|tr|td|section|article|blockquote|pre|code|img|hr|script|style)\b[^>]*>/i.test(s)) s = stripOnce(s);
// An unmatched '<' left by broken markup is not something a listing should show.
// An unmatched '<' left by broken markup is not something a listing should show.
s = s.replace(/<[^>]*$/g, ' ').replace(/[<>]/g, ' ');
s = s.replace(/<[^>]*$/g, ' ').replace(/[<>]/g, ' ');
- return s.replace(/\s+/g, ' ').trim();
+ // A block boundary turned into a space can land before the sentence's own stop ("Operations . Deine Aufgaben" on
+ // the home, 2026-11-02): no space before a full stop or comma that ends a word (".NET" keeps its dot).
+ return s.replace(/\s+/g, ' ').replace(/ ([.,])(?=\s|$)/g, '$1').trim();
}
}
/** The excerpt: the first ~300 characters of the plain text, cut on a word, with a trailing ellipsis. */
/** The excerpt: the first ~300 characters of the plain text, cut on a word, with a trailing ellipsis. */
@@ -88,6 +88,10 @@ const DAY = 86_400_000;
@@ -88,6 +88,10 @@ const DAY = 86_400_000;
const { stripHtml, excerpt, EXCERPT_CHARS } = require('../server/jobs/text');
const { stripHtml, excerpt, EXCERPT_CHARS } = require('../server/jobs/text');
assert.strictEqual(stripHtml('<p>Hello <b>world</b> — it's 5 & 6 <ok></p>'), "Hello world — it's 5 & 6 ok");
assert.strictEqual(stripHtml('<p>Hello <b>world</b> — it's 5 & 6 <ok></p>'), "Hello world — it's 5 & 6 ok");
assert.strictEqual(stripHtml('<div>a</div><div>b</div>'), 'a b');
assert.strictEqual(stripHtml('<div>a</div><div>b</div>'), 'a b');
+ // A block boundary before the sentence's own stop leaves no space before it (2026-11-02, a German listing);
+ // a dot that starts a word stays (".NET").
+ assert.strictEqual(stripHtml('<p><strong>Application Operations</strong> . Deine Aufgaben</p>'), 'Application Operations. Deine Aufgaben');
+ assert.strictEqual(stripHtml('C# and .NET , SQL .'), 'C# and .NET, SQL.');
assert.strictEqual(stripHtml('<style>p{color:red}</style><p>real</p>'), 'real');
assert.strictEqual(stripHtml('<style>p{color:red}</style><p>real</p>'), 'real');
assert.strictEqual(stripHtml('<script>alert(1)</script>'), '');
assert.strictEqual(stripHtml('<script>alert(1)</script>'), '');
assert.strictEqual(stripHtml(null), '');
assert.strictEqual(stripHtml(null), '');