mirror of
https://github.com/TxtDot/dalet.git
synced 2025-02-24 13:21:27 +03:00
doc: add daletpack formats overview
This commit is contained in:
parent
6236a8f916
commit
4273bc851a
8 changed files with 66 additions and 35 deletions
|
@ -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[];
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -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
|
||||
);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue