refactor: Use super() in Tag class constructor
This commit is contained in:
parent
d0bc4a4eb0
commit
a02916d76a
@ -1,21 +1,11 @@
|
|||||||
// Workaround about undefined import only in production build
|
|
||||||
|
|
||||||
import type { RenderableTreeNode } from "@markdoc/markdoc";
|
import type { RenderableTreeNode } from "@markdoc/markdoc";
|
||||||
|
import type { ReactNode } from "react";
|
||||||
|
|
||||||
export class Tag<N extends string = string, A extends Record<string, any> = Record<string, any>> {
|
import { Tag as MarkdocTag } from "@markdoc/markdoc";
|
||||||
readonly $$mdtype = "Tag" as const;
|
|
||||||
|
|
||||||
static isTag = (tag: any): tag is Tag => {
|
export class Tag extends MarkdocTag {
|
||||||
return !!(tag?.$$mdtype === "Tag");
|
constructor(name: string | ReactNode, attributes: Record<string, any>, children: RenderableTreeNode[]) {
|
||||||
};
|
// Workaround for TypeScript's type system
|
||||||
|
super(name as unknown as string, attributes, children);
|
||||||
name: N;
|
|
||||||
attributes: A;
|
|
||||||
children: RenderableTreeNode[];
|
|
||||||
|
|
||||||
constructor(name = "div" as N, attributes = {} as A, children: RenderableTreeNode[] = []) {
|
|
||||||
this.name = name;
|
|
||||||
this.attributes = attributes;
|
|
||||||
this.children = children;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,12 @@
|
|||||||
import type { Config, Node } from "@markdoc/markdoc";
|
import type { Config, Node } from "@markdoc/markdoc";
|
||||||
|
|
||||||
import { slugifyWithCounter } from "@sindresorhus/slugify";
|
import { slugifyWithCounter } from "@sindresorhus/slugify";
|
||||||
|
import { nodes as defaultNodes } from "@markdoc/markdoc";
|
||||||
import { DocsLayout } from "@syntax/DocsLayout";
|
import { DocsLayout } from "@syntax/DocsLayout";
|
||||||
import Markdoc from "@markdoc/markdoc";
|
|
||||||
import { Fence } from "@syntax/Fence";
|
|
||||||
import yaml from "js-yaml";
|
|
||||||
import { Link } from "@/components/common/Link";
|
import { Link } from "@/components/common/Link";
|
||||||
|
import { Fence } from "@syntax/Fence";
|
||||||
const { nodes: defaultNodes, Tag } = Markdoc;
|
import { Tag } from "./Tag";
|
||||||
|
import yaml from "js-yaml";
|
||||||
|
|
||||||
let documentSlugifyMap = new Map();
|
let documentSlugifyMap = new Map();
|
||||||
|
|
||||||
@ -19,7 +18,7 @@ const nodes = {
|
|||||||
documentSlugifyMap.set(config, slugifyWithCounter());
|
documentSlugifyMap.set(config, slugifyWithCounter());
|
||||||
|
|
||||||
return new Tag(
|
return new Tag(
|
||||||
this.render,
|
this.render as unknown as string,
|
||||||
{
|
{
|
||||||
frontmatter: yaml.load(node.attributes.frontmatter),
|
frontmatter: yaml.load(node.attributes.frontmatter),
|
||||||
estimatedReadingTime: config?.variables?.estimatedReadingTime,
|
estimatedReadingTime: config?.variables?.estimatedReadingTime,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user