Page MenuHomeSealhub

No OneTemporary

diff --git a/src/jdd-context.ts b/src/jdd-context.ts
index 81bb7d7..d2259be 100644
--- a/src/jdd-context.ts
+++ b/src/jdd-context.ts
@@ -1,86 +1,87 @@
import {
FileManager,
FilePointer,
PathFilePointer,
} from "@sealcode/file-manager";
import type { KoaResponsiveImageRouter } from "koa-responsive-image-router";
import { Renderer, marked } from "marked";
import { FlatTemplatable } from "tempstream";
import { insert_nbsp } from "./utils/insert_nbsp.js";
import { get_hyphenator } from "./hyphenation.js";
import { Token } from "marked";
import slug from "slug";
import { decode } from "html-entities";
import type * as Koa from "koa";
export interface JDDContext {
render_image: (
file_id: FilePointer | string | null,
args: Parameters<KoaResponsiveImageRouter["image"]>[1]
) => FlatTemplatable;
render_markdown: (
language: string,
markdown: string
) => string | Promise<string>;
hyphenate: (language: string, text: string) => Promise<string>;
encode_file: (photo: FilePointer, persistent: boolean) => Promise<string>;
decode_file: (token: string) => Promise<PathFilePointer | null>;
file_manager: FileManager;
language: string;
ctx: Koa.Context;
}
class RendererWithHeadings extends Renderer {
heading(text: string, depth: number): string {
const id = slug(decode(text));
return /* HTML */ ` <h${depth} id="${id}">
<a class="anchor" href="#${id}">
<span class="markdown-header-link"></span>
</a>
${text}
</h${depth}>`;
}
}
export const makeSimpleJDDContext: (
file_manager: FileManager
) => Omit<JDDContext, "language"> = (file_manager) => ({
render_image: async (file) => {
if (typeof file == "string") {
file = await file_manager.fromToken(file);
}
const path = (await file?.getPath()) || "/some-path";
return file ? /* HTML */ `<img src="file://${path}}" />` : "";
},
hyphenate: async (language: string, text: string) => {
const hyphenator = await get_hyphenator(language);
return hyphenator(text);
},
render_markdown: async (language, string) => {
const hyphenator = await get_hyphenator(language);
return string
? marked.parse(insert_nbsp(string), {
walkTokens: (token: Token) => {
if (token.type == "text") {
token.text = hyphenator(token.text as string);
}
},
renderer: new RendererWithHeadings(),
})
: "";
},
encode_file: (photo: FilePointer, persistent: boolean) => {
return photo.save(persistent);
},
decode_file: (token: string) => {
return file_manager.fromToken(token);
},
file_manager,
+ ctx: {} as unknown as Koa.Context,
});
export const makeSimpleEnglishJDDContext: (
file_manager: FileManager
) => JDDContext = (file_manager) => ({
...makeSimpleJDDContext(file_manager),
language: "en-us",
});

File Metadata

Mime Type
text/x-diff
Expires
Mon, Dec 23, 13:27 (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
555409
Default Alt Text
(2 KB)

Event Timeline