import * as assert from 'node:assert/strict' import { test } from 'node:test' import { extractStructuredContent, isNonContentHeading, tableToText, } from '../../app/utils/zim_html.js' import * as cheerio from 'cheerio' test('isNonContentHeading flags boilerplate headings, case-insensitive', () => { assert.equal(isNonContentHeading('References'), true) assert.equal(isNonContentHeading('see also'), true) assert.equal(isNonContentHeading('EXTERNAL LINKS'), true) assert.equal(isNonContentHeading('Further reading'), true) }) test('isNonContentHeading keeps real content headings', () => { assert.equal(isNonContentHeading('Uses'), false) assert.equal(isNonContentHeading('Side effects'), false) assert.equal(isNonContentHeading('History'), false) }) test('extractStructuredContent drops non-content sections at emit time (#902)', () => { const html = `
Aspirin is a medication used to reduce pain and fever.
It is used to treat fever, pain, and inflammation.
Ibuprofen, Paracetamol
https://example.com/aspirin
` const { sections } = extractStructuredContent(html) const headings = sections.map((s) => s.heading) assert.deepEqual(headings, ['Introduction', 'Uses']) assert.equal( sections.some((s) => /Smith 2020|Ibuprofen|example\.com/.test(s.text)), false, 'boilerplate-section content must not reach any emitted chunk' ) }) test('extractStructuredContent keeps real sections including their content', () => { const html = `Intro text here.
May cause stomach upset.
` const { sections } = extractStructuredContent(html) const sideEffects = sections.find((s) => s.heading === 'Side effects') assert.ok(sideEffects, 'real content section should be emitted') assert.match(sideEffects.text, /stomach upset/) }) test('tableToText renders rows as delimited text, not concatenated cell soup (#902)', () => { const html = `| Age | Dose |
|---|---|
| Adult | 500 mg |
| Child | 250 mg |
| Age | Dose |
|---|---|
| Adult | 500 mg |