Massive update to html rendering

This commit is contained in:
Endeavorance 2025-03-12 17:07:19 -04:00
parent d550f057c5
commit 10c84d2dce
5 changed files with 25 additions and 33 deletions

View file

@ -121,12 +121,18 @@ async function main(): Promise<number> {
for await (const event of watcher) {
console.log(`Detected ${event.eventType} on ${event.filename}`);
lastProcessResult = await processBinding(cliArguments);
if (lastProcessResult === ExitCode.Error) {
try {
lastProcessResult = await processBinding(cliArguments);
if (lastProcessResult === ExitCode.Error) {
console.error(`Error processing ${event.filename}`);
} else {
console.log("Reprocessed changes");
}
} catch (error) {
console.error(`Error processing ${event.filename}`);
} else {
console.log("Reprocessed changes");
console.error(error);
}
}
return ExitCode.Success;

View file

@ -1,5 +1,6 @@
import path from "node:path";
import {
IDSchema,
PlaybillSchema,
type Playbill,
type UnknownResource,
@ -14,6 +15,12 @@ const HTMLRenderOptionsSchema = z.object({
styles: z.array(z.string()).optional(),
});
const PageDefinitionSchema = z.object({
id: z.string(),
title: z.string(),
resources: z.array(IDSchema),
});
const BindingFileSchema = z.object({
$binding: z.literal("playbill"),
extends: z.string().optional(),
@ -25,6 +32,8 @@ const BindingFileSchema = z.object({
files: z.array(z.string()).default(["**/*.yaml", "**/*.md"]),
html: HTMLRenderOptionsSchema.optional(),
pages: PageDefinitionSchema.array().optional(),
});
type BindingFileContent = z.infer<typeof BindingFileSchema>;
@ -45,6 +54,7 @@ export interface PlaybillBinding {
description: string;
html?: z.infer<typeof HTMLRenderOptionsSchema>;
pages?: z.infer<typeof PageDefinitionSchema>[];
playbill: Playbill;
}

View file

@ -1,8 +1,3 @@
import rehypeStringify from "rehype-stringify";
import remarkGfm from "remark-gfm";
import remarkParse from "remark-parse";
import remarkRehype from "remark-rehype";
import { unified } from "unified";
import YAML from "yaml";
const FRONTMATTER_REGEX = /^---[\s\S]*?---/gm;
@ -58,20 +53,3 @@ ${YAML.stringify(frontmatterToWrite)}
${markdown.trim()}
`;
}
/**
* Given a string of markdown, convert it to HTML
*
* @param markdown The markdown to convert
* @returns A promise resolving to the HTML representation of the markdown
*/
export async function markdownToHtml(markdown: string): Promise<string> {
const rendered = await unified()
.use(remarkParse)
.use(remarkGfm)
.use(remarkRehype)
.use(rehypeStringify)
.process(markdown);
return String(rendered);
}