diff --git a/src/distill.js b/src/distill.js index d9274c1..b686a10 100644 --- a/src/distill.js +++ b/src/distill.js @@ -1445,9 +1445,11 @@ function mergeText(blocks) { out.push(b); } } - // Single stray characters (list bullets, separators) cost tokens and say nothing. + // Single stray characters (list bullets, separators) cost tokens and say + // nothing. A single letter or digit is a value, though: a table cell holds + // one as a block of its own, and an infobox read "Children" with no number. return out .filter((b) => b.type !== 'break') - .filter((b) => b.type !== 'text' || b.text.length > 1) + .filter((b) => b.type !== 'text' || b.text.length > 1 || /[\p{L}\p{N}]/u.test(b.text)) .map(({ host, pre, post, ...block }) => block); } diff --git a/tests/distill.test.js b/tests/distill.test.js index d365fda..6ad47f7 100644 --- a/tests/distill.test.js +++ b/tests/distill.test.js @@ -347,6 +347,23 @@ test('an entity does not put spaces inside a word', () => { assert.ok(text.includes('interface & its restraint'), 'a real space was swallowed'); }); +test('a one-character value is kept, a lone bullet or separator is not', () => { + // A Wikipedia infobox puts each value in a cell of its own, so a single + // digit is a whole block: "Children" was printed with no number after it. + const p = distill(`
| Spouse | Michelle Robinson |
|---|---|
| Children | 2 |
| Grade | A |
| Available | 是 |