Featured event card beside the hero text; Word import: tabs, quotes, callouts, dividers, videos, buttons

From lg up the featured event's photo sits beside its words, so the card
is about as tall as the hero text. Word import turns a 'Tab:' line into a
tab, the Quote and Intense Quote styles into quotes and callouts, '---'
into a divider, a lone video link into a video and 'Button: label' into
a button; Blog posts shows the whole mapping beside Import from Word.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aidan Dona 2026-10-16 20:43:25 -05:00
parent 3b034eb00e
commit 56acedf926
8 changed files with 143 additions and 16 deletions

View file

@ -14,6 +14,17 @@
cells split by |)
bold, italic, links **bold**, *italic*, [text](url)
And a few lines written a certain way (docs/importing.md), any
style:
"Tab: Overview" a tab block (079): the post
is split into tabs there
the Quote style a quote block
the Intense Quote style a callout block
"---" alone a divider
a YouTube, Vimeo or Facebook link a video block
alone on its line
"Button: [Register](https://…)" a button block
Images, text boxes, footnotes and comments aren't carried over;
the result counts what was skipped so the editor can say so.
@ -216,7 +227,7 @@ export function readDocx(buf) {
if (!text) continue;
const level = style === "title" ? 0 : Number(/^heading (\d)/.exec(style)?.[1] ?? NaN);
if (!title && (level === 0 || level === 1)) {
if (!title && (level === 0 || level === 1) && !lineBlock(text, style)) {
close();
title = text.replace(/\*/g, "");
continue;
@ -231,6 +242,12 @@ export function readDocx(buf) {
continue;
}
}
const special = lineBlock(text, style);
if (special) {
close();
blocks.push(special);
continue;
}
if (level >= 1) {
close();
blocks.push({ type: level <= 2 ? "heading" : "subheading", text: text.replace(/\*/g, "") });
@ -248,3 +265,37 @@ export function readDocx(buf) {
return { title, date, blocks, skipped: counts };
}
/* ── Lines written a certain way ──────────────────────────────── */
const VIDEO_HOST = /^https?:\/\/(www\.)?(youtube\.com|youtu\.be|m\.youtube\.com|vimeo\.com|player\.vimeo\.com|facebook\.com|fb\.watch)\//i;
/* The one link a line is made of, "[text](url)" or a bare url, or null. */
function loneLink(text) {
const md = /^\[[^\]]*\]\(([^)\s]+)\)$/.exec(text);
if (md) return md[1];
return /^https?:\/\/\S+$/.test(text) ? text : null;
}
/* A block a paragraph stands for by how it's written, or null for an
ordinary one (docs/importing.md). */
function lineBlock(text, style) {
const plain = text.replace(/\*/g, "").trim();
const tab = /^tab:\s*(.+)$/i.exec(plain);
if (tab) return { type: "tab", text: tab[1].trim().slice(0, 80) };
if (/^(-{3,}|_{3,})$/.test(plain)) return { type: "divider" };
const button = /^button:\s*\[([^\]]+)\]\(([^)\s]+)\)$/i.exec(text.trim());
if (button) return { type: "button", text: button[1].replace(/\*/g, ""), href: button[2] };
const link = loneLink(text.trim());
if (link && VIDEO_HOST.test(link)) return { type: "video", href: link };
if (style === "intense quote") return { type: "callout", text };
if (style === "quote") {
// A dash and a name at the end ("… - Jane Doe", any dash) is who said it.
const said = /^(.*\S)\s+[—–-]\s*([^—–-]{2,80})$/.exec(text);
return said ? { type: "quote", text: said[1], cite: said[2].trim() } : { type: "quote", text };
}
return null;
}

View file

@ -74,6 +74,8 @@ export function importDocx(db, buffer, fileName, byEmail) {
slot: "body",
type: block.type,
text: block.text ?? null,
href: block.href ?? null,
cite: block.cite ?? null,
items: block.items ?? [],
})),
});
@ -87,6 +89,9 @@ export function importDocx(db, buffer, fileName, byEmail) {
paragraphs: count("paragraph"),
lists: count("list"),
tables: count("table"),
tabs: count("tab"),
// Quotes, callouts, dividers, videos and buttons.
others: doc.blocks.filter((b) => ["quote", "callout", "divider", "video", "button"].includes(b.type)).length,
skipped: doc.skipped,
},
};