Fix docx import missing lesson content — include h1-h6 block elements

mammoth outputs week/quiz headings as <h2>/<h1>, not <p><strong>. The
block-element regex only matched <p>, so all headings were skipped and no
lessons were ever created. Expand regex to h[1-6]|p|ul|ol and treat any
h-tag as a heading unconditionally.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
nmemmertandClaude Sonnet 4.6 committed 2026-08-03 10:13:56 -04:00
1 parent 3197d29a28
commit eb4b713e9d
1 file changed
+4 -4
+4 -4
View File
@@ -44,15 +44,15 @@ async function parseUnitDocxBuffer(buffer, filename) {
// Walk the HTML and collect typed elements // Walk the HTML and collect typed elements
const elements = []; const elements = [];
for (const m of stripped.matchAll(/<(p|ul|ol)(?:\s[^>]*)?>[\s\S]*?<\/\1>/gi)) { for (const m of stripped.matchAll(/<(h[1-6]|p|ul|ol)(?:\s[^>]*)?>[\s\S]*?<\/\1>/gi)) {
const tag = m[0].match(/^<(\w+)/)[1].toLowerCase(); const tag = m[0].match(/^<(\w+)/)[1].toLowerCase();
const inner = m[0].replace(/^<[^>]+>/, '').replace(/<\/\w+>\s*$/, ''); const inner = m[0].replace(/^<[^>]+>/, '').replace(/<\/\w+>\s*$/, '');
if (tag === 'p') { if (tag === 'p' || /^h[1-6]$/.test(tag)) {
const text = htmlToText(inner); const text = htmlToText(inner);
if (!text) continue; if (!text) continue;
// A paragraph whose only non-whitespace content is wrapped in <strong> is a heading // h1-h6 are always headings; <p> is a heading only if its sole content is <strong>
const isHeading = /^<strong>[^<]+<\/strong>\s*$/.test(inner.trim()); const isHeading = /^h[1-6]$/.test(tag) || /^<strong>[^<]+<\/strong>\s*$/.test(inner.trim());
elements.push({ kind: isHeading ? 'heading' : 'para', text }); elements.push({ kind: isHeading ? 'heading' : 'para', text });
} else { } else {
const items = [...inner.matchAll(/<li[^>]*>([\s\S]*?)<\/li>/gi)] const items = [...inner.matchAll(/<li[^>]*>([\s\S]*?)<\/li>/gi)]