openvibers/openvibe.work Commits

No space before a full stop in a listing's text (#182)

OP OpenVibers committed 11 days ago · bd81cad294 · 2 files, +7 −1

A block tag turned into a space can land before the sentence's own stop: the
home showed 'Application Operations . Deine Aufgaben' (a German listing,
2026-11-02). stripHtml drops a space before a full stop or comma that ends a
word; a dot that starts one ('.NET') stays.

Changes

ddiff --git a/server/jobs/text.js b/server/jobs/text.js
iindex cc8deb9..ba5311f 100644
---- a/server/jobs/text.js
++++ b/server/jobs/text.js
@@@ -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. */
ddiff --git a/test/ingest.test.js b/test/ingest.test.js
iindex a5513e1..d9065f5 100644
---- a/test/ingest.test.js
++++ b/test/ingest.test.js
@@@ -88,6 +88,10 @@ const DAY = 86_400_000;
const { stripHtml, excerpt, EXCERPT_CHARS } = require('../server/jobs/text');
assert.strictEqual(stripHtml('<p>Hello&nbsp;<b>world</b> — it&#39;s 5 &amp; 6 &lt;ok&gt;</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), '');