Page MenuHomeSealhub

markdown-value.ts
No OneTemporary

Authored By
Unknown
Size
663 B
Referenced Files
None
Subscribers
None

markdown-value.ts

import { Parser, HtmlRenderer } from "commonmark";
import type { FieldValue } from "./field-value.js";
const parser = new Parser();
const renderer = new HtmlRenderer();
export class MarkdownValue implements FieldValue {
private htmlCache: string | null = null;
constructor(private readonly markdown: string) {}
toMarkdown(): string {
return this.markdown;
}
toHtml(): string {
if (this.htmlCache === null) {
const parsed = parser.parse(this.markdown);
this.htmlCache = renderer.render(parsed);
}
return this.htmlCache;
}
toString(): string {
return this.toMarkdown();
}
getRestAPIValue(): string {
return this.toMarkdown();
}
}

File Metadata

Mime Type
application/javascript
Expires
Fri, Nov 27, 18:16 (1 d, 8 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1213100
Default Alt Text
markdown-value.ts (663 B)

Event Timeline