doc: add daletpack formats overview

This commit is contained in:
Artemy Egorov 2024-07-27 17:44:34 +03:00
parent 6236a8f916
commit 4273bc851a
8 changed files with 66 additions and 35 deletions

View file

@ -16,10 +16,6 @@ export function parseTag(raw_tag: RawTag): Tag {
return new El(raw_tag);
}
if (typeof raw_tag === "number") {
return TagNormalizers[raw_tag]([raw_tag, null]);
}
if (Array.isArray(raw_tag)) {
if (Array.isArray(raw_tag[0])) {
raw_tag = raw_tag as RawTag[];

View file

@ -4,13 +4,12 @@ import Heading from "./tags/heading";
import { RawTagAsArray } from "./types";
import { z } from "zod";
const textOrTag = z.custom((b) => b !== null);
const text = z.string();
const TagNormalizers = [
n(
z.custom((b) => b !== null),
z.any(),
El
),
n(z.string(), z.number().int().min(1).max(6), Heading),
n(textOrTag, z.any(), El),
n(text, z.number().int().min(1).max(6).nullable(), Heading),
];
export { TagNormalizers };

View file

@ -2,14 +2,14 @@ import { chtml } from "../../utils";
import { Tag } from "../types";
export default class Heading extends Tag {
constructor(body: string, argument: number) {
super(1, body, argument);
constructor(body: string, argument?: number | null) {
super(1, body, argument || null);
}
toHtml(classes?: boolean): string {
return chtml(
`h${this.argument}`,
`h hl${this.argument}`,
`h${this.argument || 1}`,
`h hl${this.argument || 1}`,
classes,
this.body
);

View file

@ -38,7 +38,10 @@ export abstract class Tag {
encode(): Uint8Array {
return encode(this.raw);
}
abstract toHtml(classes?: boolean): string;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
toHtml(classes?: boolean): string {
return "";
}
}
export type Body = string | Tag[] | null;