Add option to compile markdown
This commit is contained in:
parent
e7218143ec
commit
c1f3c6cade
7 changed files with 62 additions and 237 deletions
|
@ -1,6 +1,6 @@
|
|||
import { Playbill, type TaggedComponent } from "@proscenium/playbill";
|
||||
import { Playbill } from "@proscenium/playbill";
|
||||
import sortBy from "lodash-es/sortBy";
|
||||
import { createMarkdownRenderer, type BoundPlaybill } from "#lib";
|
||||
import { compileMarkdownInPlaybill, type BoundPlaybill } from "#lib";
|
||||
import { GlossaryTable } from "./component/glossary";
|
||||
import { PageHeader } from "./component/header";
|
||||
import { ItemCard } from "./component/item";
|
||||
|
@ -17,31 +17,7 @@ export async function renderPlaybillToHTML(
|
|||
// Make a copy of the playbill to avoid modifying the original
|
||||
// and compile all description markdown
|
||||
const playbill = Playbill.fromSerialized(boundPlaybill.playbill.serialize());
|
||||
|
||||
// Prepare a rendering function for markdown that is aware of the playbill binding
|
||||
const renderMarkdown = createMarkdownRenderer(boundPlaybill);
|
||||
|
||||
// Define a processor function to iterate over all components and process their markdown
|
||||
const processMarkdownInComponent = async (entry: TaggedComponent) => {
|
||||
entry.component.description = await renderMarkdown(
|
||||
entry.component.description,
|
||||
);
|
||||
|
||||
if (entry.type === "resource" && entry.component.type === "table") {
|
||||
const newData: string[][] = [];
|
||||
for (const row of entry.component.data) {
|
||||
const newRow: string[] = [];
|
||||
for (const cell of row) {
|
||||
newRow.push(await renderMarkdown(cell));
|
||||
}
|
||||
newData.push(newRow);
|
||||
}
|
||||
entry.component.data = newData;
|
||||
}
|
||||
};
|
||||
|
||||
// Process all components
|
||||
await playbill.processComponents(processMarkdownInComponent);
|
||||
await compileMarkdownInPlaybill(boundPlaybill);
|
||||
|
||||
// Soprt rules by their order prop
|
||||
const rulesByOrder = sortBy(Object.values(playbill.rules), "order");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue