diff --git a/Makefile b/Makefile index 7b4d044..ddbc508 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,6 @@ +dev: build + npm run test:dev + build: clean npm run build @@ -5,7 +8,7 @@ clean: rm -rf dist test: build - npm run test:dev + npm run test publish: test npm publish --access public diff --git a/dist/document.js b/dist/document.js index 4ab37b0..8369c37 100644 --- a/dist/document.js +++ b/dist/document.js @@ -1,5 +1,4 @@ import { Element } from "./element"; -import { ParseNodes } from "./parse_nodes"; import { v4 as uuidv4 } from 'uuid'; export class Document extends Element { constructor(el) { @@ -14,13 +13,21 @@ export class Document extends Element { this.file = "module.md"; } this.id = el.id ? el.id : uuidv4(); - this.nodes = ParseNodes(el.nodes); + this.nodes = el.nodes; + // this.nodes = ParseNodes(el.nodes); } toString() { var _a; let s = ""; (_a = this.nodes) === null || _a === void 0 ? void 0 : _a.forEach((n) => { - s += n.toString(); + if (Array.isArray(n)) { + n.forEach((n) => { + s += n.toString(); + }); + } + else { + s += n.toString(); + } }); return s; } diff --git a/dist/element.js b/dist/element.js index cbbdb4a..7676c13 100644 --- a/dist/element.js +++ b/dist/element.js @@ -17,7 +17,14 @@ export class Element { (_a = this.nodes) === null || _a === void 0 ? void 0 : _a.forEach((n) => { if (n === undefined) return; - s += n.toString(); + if (Array.isArray(n)) { + n.forEach((n) => { + s += n.toString(); + }); + } + else { + s += n.toString(); + } }); if (this.atom === undefined) return s; diff --git a/dist/empty_mod.d.ts b/dist/empty_mod.d.ts new file mode 100644 index 0000000..d9f3cf7 --- /dev/null +++ b/dist/empty_mod.d.ts @@ -0,0 +1,2 @@ +import { Module } from "./module"; +export declare function EmptyModule(): Module; diff --git a/dist/empty_mod.js b/dist/empty_mod.js new file mode 100644 index 0000000..eb116b1 --- /dev/null +++ b/dist/empty_mod.js @@ -0,0 +1,11 @@ +import { Module } from "./module"; +import { Document } from "./document"; +export function EmptyModule() { + return new Module({ + id: "", + doc: new Document({}), + dir: "", + filepath: "", + name: "", + }); +} diff --git a/dist/index.d.ts b/dist/index.d.ts index d4b6bce..8984bc3 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,7 +1,8 @@ -export type { Node } from "./node"; export { Cmd } from "./cmd"; export { CmdResult } from "./cmd_result"; export { Document } from "./document"; +export { Element } from "./element"; +export { EmptyModule } from "./empty_mod"; export { FencedCode } from "./fenced_code"; export { FigCaption } from "./fig_caption"; export { Figure } from "./figure"; @@ -10,20 +11,24 @@ export { Image } from "./image"; export { Include } from "./include"; export { InlineCode } from "./inline_code"; export { LI } from "./li"; -export { Link, NewLink } from "./link"; -export { NewElement, Element } from "./element"; -export { NewText, Text } from "./text"; -export { NewUL, UL } from "./ul"; +export { Link } from "./link"; +export { Module } from "./module"; +export { NewElement } from "./element"; +export { NewLink } from "./link"; +export { NewText } from "./text"; +export { NewUL } from "./ul"; +export { Node } from "./node"; export { OL } from "./ol"; export { Page } from "./page"; -export { PostMarshaller } from "./callbacks"; +export { Parser } from "./parser"; export { Ref } from "./ref"; export { Snippet } from "./snippet"; export { SourceCode } from "./source_code"; export { Table } from "./table"; +export { Text } from "./text"; export { Toc } from "./toc"; -export type { VisitNode } from "./visit_node"; -export { ParseNodes } from "./parse_nodes"; +export { UL } from "./ul"; export { VisitAtom } from "./visit_atom"; +export { VisitNode } from "./visit_node"; export { atoms } from "./atoms"; export { gotypes } from "./gotypes"; diff --git a/dist/index.js b/dist/index.js index f21b61b..717b033 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,6 +1,5 @@ -'use strict'; - -var uuid = require('uuid'); +import { v4 } from 'uuid'; +import path from 'path-browserify'; let gotypes = { Body: "*hype.Body", @@ -49,7 +48,14 @@ class Element { (_a = this.nodes) === null || _a === void 0 ? void 0 : _a.forEach((n) => { if (n === undefined) return; - s += n.toString(); + if (Array.isArray(n)) { + n.forEach((n) => { + s += n.toString(); + }); + } + else { + s += n.toString(); + } }); if (this.atom === undefined) return s; @@ -90,32 +96,44 @@ class CmdResult extends Element { } } -class FencedCode extends Element { - constructor(fc) { - super(fc); - this.lang = fc.lang; +class Document extends Element { + constructor(el) { + super(el); + this.id = ""; + this.file = "module.md"; + this.root = el.root; + this.title = el.title; + this.parser = el.parser; + this.file = el.file; + if (this.file === undefined) { + this.file = "module.md"; + } + this.id = el.id ? el.id : v4(); + this.nodes = el.nodes; + // this.nodes = ParseNodes(el.nodes); } -} - -class FigCaption extends Element { - constructor(fc) { - super(fc); + toString() { + var _a; + let s = ""; + (_a = this.nodes) === null || _a === void 0 ? void 0 : _a.forEach((n) => { + if (Array.isArray(n)) { + n.forEach((n) => { + s += n.toString(); + }); + } + else { + s += n.toString(); + } + }); + return s; } -} - -class Figure extends Element { - constructor(f) { - super(f); - if (f.style === "") { - f.style = "listing"; - } - if (f.pos < 1) { - f.pos = 1; - } - f.section_id ? f.section_id : 1; - this.pos = f.pos; - this.style = f.style; - this.section_id = f.section_id; + toHtml() { + var _a; + let s = ""; + (_a = this.nodes) === null || _a === void 0 ? void 0 : _a.forEach((n) => { + s += n.toHtml(); + }); + return s; } } @@ -130,31 +148,6 @@ class Heading extends Element { } } -class Image extends Element { - constructor(img) { - super(img); - } -} - -class Include extends Element { - constructor(el) { - super(el); - this.dir = el.dir; - } -} - -class InlineCode extends Element { - constructor(t) { - super(t); - } -} - -class LI extends Element { - constructor(li) { - super(li); - } -} - // Code generated by gen.go. DO NOT EDIT. let atoms = { A: "a", @@ -557,6 +550,118 @@ function NewLink(url, attrs) { }); } +function VisitAtom(atom, n, fn) { + var _a; + if (n === undefined) { + return; + } + (_a = n.nodes) === null || _a === void 0 ? void 0 : _a.forEach((e) => { + VisitAtom(atom, e, fn); + }); + let atoms = []; + if (Array.isArray(atom)) { + atoms = atom; + } + else { + atoms.push(atom); + } + atoms.forEach((a) => { + if (a === n.atom) { + fn(n); + } + }); + return; +} + +class Toc extends Element { + constructor() { + super({ + nodes: [], + atom: atoms.Ul, + type: gotypes.UL, + attributes: { + class: "hype-toc", + } + }); + this.ids = []; + this.nodes = []; + } + perform(doc, gen) { + VisitAtom(atoms.Headings, doc, (n) => { + let h = new Heading(n); + // this.headings.push(h); + let id = gen ? gen() : newUUID(); + this.ids.push(id); + let a = NewLink(`#${id}`); + let li = NewElement(atoms.Li, { class: `hype-toc-lvl-${h.level}` }); + a.nodes = h.nodes; + li.nodes = [a]; + this.nodes.push(li); + let nodes = n.nodes; + let b = NewElement(atoms.A); + b.attributes = { name: id }; + n.nodes = [b, ...nodes]; + }); + } +} +function newUUID() { + return `heading-${v4()}`; +} + +class FencedCode extends Element { + constructor(fc) { + super(fc); + this.lang = fc.lang; + } +} + +class FigCaption extends Element { + constructor(fc) { + super(fc); + } +} + +class Figure extends Element { + constructor(f) { + super(f); + if (f.style === "") { + f.style = "listing"; + } + if (f.pos < 1) { + f.pos = 1; + } + f.section_id ? f.section_id : 1; + this.pos = f.pos; + this.style = f.style; + this.section_id = f.section_id; + } +} + +class Image extends Element { + constructor(img) { + super(img); + } +} + +class Include extends Element { + constructor(el) { + super(el); + this.dir = el.dir; + } +} + +class InlineCode extends Element { + constructor(t) { + super(t); + } +} + +class LI extends Element { + constructor(li) { + super(li); + } +} + class OL extends Element { constructor(ol) { super(ol); @@ -584,6 +689,9 @@ class Snippet extends Element { this.start = s.start; this.end = s.end; } + toString() { + return this.content; + } } class SourceCode extends Element { @@ -634,230 +742,114 @@ function NewUL(attrs) { }); } -function ParseNodes(nodes = []) { - let ret = []; - nodes.forEach((n) => { - if (n == null) { - return; - } - n.nodes = ParseNodes(n.nodes); - switch (n.type) { - case gotypes.Body: - case gotypes.Element: - case gotypes.Paragraph: - case gotypes.TD: - case gotypes.TH: - case gotypes.THead: - case gotypes.TR: - ret.push(new Element(n)); - break; - case gotypes.Page: - ret.push(new Page(n)); - break; - case gotypes.Text: - ret.push(new Text(n)); - break; - case gotypes.Heading: - ret.push(new Heading(n)); - break; - case gotypes.InlineCode: - ret.push(new InlineCode(n)); - break; - case gotypes.Include: - ret.push(new Include(n)); - break; - case gotypes.Link: - ret.push(new Link(n)); - break; - case gotypes.Figure: - ret.push(new Figure(n)); - break; - case gotypes.Table: - ret.push(new Table(n)); - break; - case gotypes.Ref: - ret.push(new Ref(n)); - break; - case gotypes.Cmd: - ret.push(new Cmd(n)); - break; - case gotypes.CmdResult: - ret.push(new CmdResult(n)); - break; - case gotypes.Snippet: - ret.push(new Snippet(n)); - break; - case gotypes.FencedCode: - ret.push(new FencedCode(n)); - break; - case gotypes.SourceCode: - ret.push(new SourceCode(n)); - break; - case gotypes.OL: - ret.push(new OL(n)); - break; - case gotypes.UL: - ret.push(new UL(n)); - break; - case gotypes.LI: - ret.push(new LI(n)); - break; - case gotypes.Image: - ret.push(new Image(n)); - break; - case gotypes.Figcaption: - case "*hype.FigCaption": - ret.push(new FigCaption(n)); - break; - default: - if (Array.isArray(n)) { - nodes = ParseNodes(n); - ret.push(...nodes); - break; +class Parser { + constructor() { + this.handlers = {}; + this.handlers[gotypes.Body] = newElement; + this.handlers[gotypes.Element] = newElement; + this.handlers[gotypes.Paragraph] = newElement; + this.handlers[gotypes.TD] = newElement; + this.handlers[gotypes.TH] = newElement; + this.handlers[gotypes.THead] = newElement; + this.handlers[gotypes.TR] = newElement; + this.handlers[gotypes.CmdResult] = (n) => new CmdResult(n); + this.handlers[gotypes.Cmd] = (n) => new Cmd(n); + this.handlers[gotypes.FencedCode] = (n) => new FencedCode(n); + this.handlers[gotypes.Figcaption] = (n) => new FigCaption(n); + this.handlers[gotypes.Figure] = (n) => new Figure(n); + this.handlers[gotypes.Heading] = (n) => new Heading(n); + this.handlers[gotypes.Image] = (n) => new Image(n); + this.handlers[gotypes.Include] = (n) => new Include(n); + this.handlers[gotypes.InlineCode] = (n) => new InlineCode(n); + this.handlers[gotypes.LI] = (n) => new LI(n); + this.handlers[gotypes.Link] = (n) => new Link(n); + this.handlers[gotypes.OL] = (n) => new OL(n); + this.handlers[gotypes.Page] = (n) => new Page(n); + this.handlers[gotypes.Ref] = (n) => new Ref(n); + this.handlers[gotypes.Snippet] = (n) => new Snippet(n); + this.handlers[gotypes.SourceCode] = (n) => new SourceCode(n); + this.handlers[gotypes.Table] = (n) => new Table(n); + this.handlers[gotypes.Text] = (n) => new Text(n); + this.handlers[gotypes.UL] = (n) => new UL(n); + } + parse(data) { + data = structuredClone(data); + data.nodes = this.parseNodes(data.nodes); + return new Document(data); + } + parseNodes(nodes = []) { + let ret = []; + nodes.forEach((n) => { + if (n == null) { + return; + } + if (Array.isArray(n)) { + let nodes = this.parseNodes(n); + ret.push(...nodes); + } + else { + n.nodes = this.parseNodes(n.nodes); + let fn = this.handlers[n.type]; + if (fn === undefined) { + console.warn("unknown node type: " + n.type); + fn = newElement; } - console.log("unknown node type", n.type, n); - throw new Error("Unknown node type: " + n.type); - } - }); - return ret; + ret.push(fn(n)); + } + }); + return ret; + } +} +function newElement(n) { + return new Element(n); } -class Document extends Element { - constructor(el) { - super(el); +class Module { + constructor(mod, parser) { this.id = ""; - this.file = "module.md"; - this.root = el.root; - this.title = el.title; - this.parser = el.parser; - this.file = el.file; - if (this.file === undefined) { - this.file = "module.md"; + this.dir = ""; + this.filepath = ""; + this.name = ""; + this.id = v4(); + if (mod.id) { + this.id = mod.id; } - this.id = el.id ? el.id : uuid.v4(); - this.nodes = ParseNodes(el.nodes); + if (mod.file === undefined) { + mod.file = "module.md"; + } + if (mod.root === undefined) { + mod.root = ""; + } + this.filepath = path.join(mod.root, mod.file); + this.dir = mod.root; + this.name = mod.file ? mod.file : "module.md"; + this.parser = parser ? parser : new Parser(); + this.doc = this.parser.parse(mod.doc ? mod.doc : mod); + this.toc = new Toc(); + this.toc.perform(this.doc); + } + title() { + if (this.doc === undefined) { + return this.name; + } + return this.doc.title; } toString() { - var _a; - let s = ""; - (_a = this.nodes) === null || _a === void 0 ? void 0 : _a.forEach((n) => { - s += n.toString(); - }); - return s; - } - toHtml() { - var _a; - let s = ""; - (_a = this.nodes) === null || _a === void 0 ? void 0 : _a.forEach((n) => { - s += n.toHtml(); - }); - return s; + if (this.doc === undefined) { + return ""; + } + return this.doc.toString(); } } -function VisitAtom(atom, n, fn) { - var _a; - if (n === undefined) { - return; - } - (_a = n.nodes) === null || _a === void 0 ? void 0 : _a.forEach((e) => { - VisitAtom(atom, e, fn); - }); - let atoms = []; - if (Array.isArray(atom)) { - atoms = atom; - } - else { - atoms.push(atom); - } - atoms.forEach((a) => { - if (a === n.atom) { - fn(n); - } +function EmptyModule() { + return new Module({ + id: "", + doc: new Document({}), + dir: "", + filepath: "", + name: "", }); - return; - // func ByAtom[T ~string](nodes Nodes, want ...T) []AtomableNode { - // var res []AtomableNode - // for _, n := range nodes { - // an, ok := n.(AtomableNode) - // if !ok { - // res = append(res, ByAtom(n.Children(), want...)...) - // continue - // } - // for _, w := range want { - // if an.Atom().String() == string(w) { - // res = append(res, an) - // break - // } - // } - // res = append(res, ByAtom(n.Children(), want...)...) - // } - // return res - // } -} - -class Toc extends Element { - constructor() { - super({ - nodes: [], - atom: atoms.Ul, - type: gotypes.UL, - attributes: { - class: "hype-toc", - } - }); - this.ids = []; - this.nodes = []; - } - perform(doc, gen) { - VisitAtom(atoms.Headings, doc, (n) => { - let h = new Heading(n); - // this.headings.push(h); - let id = gen ? gen() : newUUID(); - this.ids.push(id); - let a = NewLink(`#${id}`); - let li = NewElement(atoms.Li, { class: `hype-toc-lvl-${h.level}` }); - a.nodes = h.nodes; - li.nodes = [a]; - this.nodes.push(li); - let nodes = n.nodes; - let b = NewElement(atoms.A); - b.attributes = { name: id }; - n.nodes = [b, ...nodes]; - }); - } -} -function newUUID() { - return `heading-${uuid.v4()}`; } -exports.Cmd = Cmd; -exports.CmdResult = CmdResult; -exports.Document = Document; -exports.Element = Element; -exports.FencedCode = FencedCode; -exports.FigCaption = FigCaption; -exports.Figure = Figure; -exports.Heading = Heading; -exports.Image = Image; -exports.Include = Include; -exports.InlineCode = InlineCode; -exports.LI = LI; -exports.Link = Link; -exports.NewElement = NewElement; -exports.NewLink = NewLink; -exports.NewText = NewText; -exports.NewUL = NewUL; -exports.OL = OL; -exports.Page = Page; -exports.ParseNodes = ParseNodes; -exports.Ref = Ref; -exports.Snippet = Snippet; -exports.SourceCode = SourceCode; -exports.Table = Table; -exports.Text = Text; -exports.Toc = Toc; -exports.UL = UL; -exports.VisitAtom = VisitAtom; -exports.atoms = atoms; -exports.gotypes = gotypes; +export { Cmd, CmdResult, Document, Element, EmptyModule, FencedCode, FigCaption, Figure, Heading, Image, Include, InlineCode, LI, Link, Module, NewElement, NewLink, NewText, NewUL, OL, Page, Parser, Ref, Snippet, SourceCode, Table, Text, Toc, UL, VisitAtom, atoms, gotypes }; diff --git a/dist/module.d.ts b/dist/module.d.ts new file mode 100644 index 0000000..0f364c9 --- /dev/null +++ b/dist/module.d.ts @@ -0,0 +1,15 @@ +import { Document } from "./document"; +import { Toc } from "./toc"; +import { Parser } from "./parser"; +export declare class Module { + id: string; + dir: string; + filepath: string; + name: string; + parser: Parser; + doc: Document; + toc: Toc; + constructor(mod: any, parser?: Parser); + title(): string; + toString(): string; +} diff --git a/dist/module.js b/dist/module.js new file mode 100644 index 0000000..0896fb3 --- /dev/null +++ b/dist/module.js @@ -0,0 +1,41 @@ +import { Toc } from "./toc"; +import { v4 as uuid } from "uuid"; +import path from "path-browserify"; +import { Parser } from "./parser"; +export class Module { + constructor(mod, parser) { + this.id = ""; + this.dir = ""; + this.filepath = ""; + this.name = ""; + this.id = uuid(); + if (mod.id) { + this.id = mod.id; + } + if (mod.file === undefined) { + mod.file = "module.md"; + } + if (mod.root === undefined) { + mod.root = ""; + } + this.filepath = path.join(mod.root, mod.file); + this.dir = mod.root; + this.name = mod.file ? mod.file : "module.md"; + this.parser = parser ? parser : new Parser(); + this.doc = this.parser.parse(mod.doc ? mod.doc : mod); + this.toc = new Toc(); + this.toc.perform(this.doc); + } + title() { + if (this.doc === undefined) { + return this.name; + } + return this.doc.title; + } + toString() { + if (this.doc === undefined) { + return ""; + } + return this.doc.toString(); + } +} diff --git a/dist/parse_nodes.d.ts b/dist/parse_nodes.d.ts deleted file mode 100644 index 87a5e9b..0000000 --- a/dist/parse_nodes.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import type { Node } from "./node"; -export declare function ParseNodes(nodes?: Node[]): Node[]; diff --git a/dist/parse_nodes.js b/dist/parse_nodes.js deleted file mode 100644 index d0a0212..0000000 --- a/dist/parse_nodes.js +++ /dev/null @@ -1,109 +0,0 @@ -import { Cmd } from "./cmd"; -import { CmdResult } from "./cmd_result"; -import { Element } from "./element"; -import { FencedCode } from "./fenced_code"; -import { FigCaption } from "./fig_caption"; -import { Figure } from "./figure"; -import { Heading } from "./heading"; -import { Image } from "./image"; -import { Include } from "./include"; -import { InlineCode } from "./inline_code"; -import { LI } from "./li"; -import { Link } from "./link"; -import { OL } from "./ol"; -import { Page } from "./page"; -import { Ref } from "./ref"; -import { Snippet } from "./snippet"; -import { SourceCode } from "./source_code"; -import { Table } from "./table"; -import { Text } from "./text"; -import { UL } from "./ul"; -import { gotypes } from "./gotypes"; -export function ParseNodes(nodes = []) { - let ret = []; - nodes.forEach((n) => { - if (n == null) { - return; - } - n.nodes = ParseNodes(n.nodes); - switch (n.type) { - case gotypes.Body: - case gotypes.Element: - case gotypes.Paragraph: - case gotypes.TD: - case gotypes.TH: - case gotypes.THead: - case gotypes.TR: - ret.push(new Element(n)); - break; - case gotypes.Page: - ret.push(new Page(n)); - break; - case gotypes.Text: - ret.push(new Text(n)); - break; - case gotypes.Heading: - ret.push(new Heading(n)); - break; - case gotypes.InlineCode: - ret.push(new InlineCode(n)); - break; - case gotypes.Include: - ret.push(new Include(n)); - break; - case gotypes.Link: - ret.push(new Link(n)); - break; - case gotypes.Figure: - ret.push(new Figure(n)); - break; - case gotypes.Table: - ret.push(new Table(n)); - break; - case gotypes.Ref: - ret.push(new Ref(n)); - break; - case gotypes.Cmd: - ret.push(new Cmd(n)); - break; - case gotypes.CmdResult: - ret.push(new CmdResult(n)); - break; - case gotypes.Snippet: - ret.push(new Snippet(n)); - break; - case gotypes.FencedCode: - ret.push(new FencedCode(n)); - break; - case gotypes.SourceCode: - ret.push(new SourceCode(n)); - break; - case gotypes.OL: - ret.push(new OL(n)); - break; - case gotypes.UL: - ret.push(new UL(n)); - break; - case gotypes.LI: - ret.push(new LI(n)); - break; - case gotypes.Image: - ret.push(new Image(n)); - break; - case gotypes.Figcaption: - case "*hype.FigCaption": - ret.push(new FigCaption(n)); - break; - default: - if (Array.isArray(n)) { - nodes = ParseNodes(n); - ret.push(...nodes); - break; - } - console.log("unknown node type", n.type, n); - throw new Error("Unknown node type: " + n.type); - break; - } - }); - return ret; -} diff --git a/dist/parser.d.ts b/dist/parser.d.ts new file mode 100644 index 0000000..1489ef7 --- /dev/null +++ b/dist/parser.d.ts @@ -0,0 +1,7 @@ +import { Document } from "./document"; +export declare class Parser { + handlers: any; + constructor(); + parse(data: any): Document; + private parseNodes; +} diff --git a/dist/parser.js b/dist/parser.js new file mode 100644 index 0000000..4d0c2c3 --- /dev/null +++ b/dist/parser.js @@ -0,0 +1,84 @@ +import { Document } from "./document"; +import { Cmd } from "./cmd"; +import { CmdResult } from "./cmd_result"; +import { Element } from "./element"; +import { FencedCode } from "./fenced_code"; +import { FigCaption } from "./fig_caption"; +import { Figure } from "./figure"; +import { Heading } from "./heading"; +import { Image } from "./image"; +import { Include } from "./include"; +import { InlineCode } from "./inline_code"; +import { LI } from "./li"; +import { Link } from "./link"; +import { OL } from "./ol"; +import { Page } from "./page"; +import { Ref } from "./ref"; +import { Snippet } from "./snippet"; +import { SourceCode } from "./source_code"; +import { Table } from "./table"; +import { Text } from "./text"; +import { UL } from "./ul"; +import { gotypes } from "./gotypes"; +export class Parser { + constructor() { + this.handlers = {}; + this.handlers[gotypes.Body] = newElement; + this.handlers[gotypes.Element] = newElement; + this.handlers[gotypes.Paragraph] = newElement; + this.handlers[gotypes.TD] = newElement; + this.handlers[gotypes.TH] = newElement; + this.handlers[gotypes.THead] = newElement; + this.handlers[gotypes.TR] = newElement; + this.handlers[gotypes.CmdResult] = (n) => new CmdResult(n); + this.handlers[gotypes.Cmd] = (n) => new Cmd(n); + this.handlers[gotypes.FencedCode] = (n) => new FencedCode(n); + this.handlers[gotypes.Figcaption] = (n) => new FigCaption(n); + this.handlers[gotypes.Figure] = (n) => new Figure(n); + this.handlers[gotypes.Heading] = (n) => new Heading(n); + this.handlers[gotypes.Image] = (n) => new Image(n); + this.handlers[gotypes.Include] = (n) => new Include(n); + this.handlers[gotypes.InlineCode] = (n) => new InlineCode(n); + this.handlers[gotypes.LI] = (n) => new LI(n); + this.handlers[gotypes.Link] = (n) => new Link(n); + this.handlers[gotypes.OL] = (n) => new OL(n); + this.handlers[gotypes.Page] = (n) => new Page(n); + this.handlers[gotypes.Ref] = (n) => new Ref(n); + this.handlers[gotypes.Snippet] = (n) => new Snippet(n); + this.handlers[gotypes.SourceCode] = (n) => new SourceCode(n); + this.handlers[gotypes.Table] = (n) => new Table(n); + this.handlers[gotypes.Text] = (n) => new Text(n); + this.handlers[gotypes.UL] = (n) => new UL(n); + } + parse(data) { + let doc; + data = structuredClone(data); + data.nodes = this.parseNodes(data.nodes); + return new Document(data); + } + parseNodes(nodes = []) { + let ret = []; + nodes.forEach((n) => { + if (n == null) { + return; + } + if (Array.isArray(n)) { + let nodes = this.parseNodes(n); + ret.push(...nodes); + } + else { + n.nodes = this.parseNodes(n.nodes); + let fn = this.handlers[n.type]; + if (fn === undefined) { + console.warn("unknown node type: " + n.type); + fn = newElement; + } + ret.push(fn(n)); + } + }); + return ret; + } +} +function newElement(n) { + return new Element(n); +} diff --git a/dist/snippet.d.ts b/dist/snippet.d.ts index 62fb14e..aa5b9f4 100644 --- a/dist/snippet.d.ts +++ b/dist/snippet.d.ts @@ -6,4 +6,5 @@ export declare class Snippet extends Element { start?: number; end?: number; constructor(s: any); + toString(): string; } diff --git a/dist/snippet.js b/dist/snippet.js index 1aaebfa..2ad0214 100644 --- a/dist/snippet.js +++ b/dist/snippet.js @@ -8,4 +8,7 @@ export class Snippet extends Element { this.start = s.start; this.end = s.end; } + toString() { + return this.content; + } } diff --git a/dist/visit_atom.js b/dist/visit_atom.js index 00863ce..11c74e8 100644 --- a/dist/visit_atom.js +++ b/dist/visit_atom.js @@ -19,22 +19,4 @@ export function VisitAtom(atom, n, fn) { } }); return; - // func ByAtom[T ~string](nodes Nodes, want ...T) []AtomableNode { - // var res []AtomableNode - // for _, n := range nodes { - // an, ok := n.(AtomableNode) - // if !ok { - // res = append(res, ByAtom(n.Children(), want...)...) - // continue - // } - // for _, w := range want { - // if an.Atom().String() == string(w) { - // res = append(res, an) - // break - // } - // } - // res = append(res, ByAtom(n.Children(), want...)...) - // } - // return res - // } } diff --git a/index.d.ts b/index.d.ts index 88bdffa..c5b98ae 100644 --- a/index.d.ts +++ b/index.d.ts @@ -55,6 +55,35 @@ declare class Document extends Element { toHtml(): string; } +declare class Toc extends Element { + ids: string[]; + nodes: Node[]; + constructor(); + perform(doc: Document, gen?: () => string): void; +} + +declare class Parser { + handlers: any; + constructor(); + parse(data: any): Document; + private parseNodes; +} + +declare class Module { + id: string; + dir: string; + filepath: string; + name: string; + parser: Parser; + doc: Document; + toc: Toc; + constructor(mod: any, parser?: Parser); + title(): string; + toString(): string; +} + +declare function EmptyModule(): Module; + declare class FencedCode extends Element { lang: string; constructor(fc: any); @@ -124,10 +153,6 @@ declare class Page extends Element { constructor(n: any); } -interface PostMarshaller { - postMarshal(doc: Document): void; -} - declare class Ref extends Element { constructor(r: any); } @@ -139,6 +164,7 @@ declare class Snippet extends Element { start?: number; end?: number; constructor(s: any); + toString(): string; } declare class SourceCode extends Element { @@ -150,17 +176,8 @@ declare class Table extends Element { constructor(t: any); } -declare class Toc extends Element { - ids: string[]; - nodes: Node[]; - constructor(); - perform(doc: Document, gen?: () => string): void; -} - type VisitNode = (n: Node) => void; -declare function ParseNodes(nodes?: Node[]): Node[]; - declare function VisitAtom(atom: string | string[], n: Node, fn: VisitNode): void; declare let atoms: { @@ -573,4 +590,4 @@ declare let gotypes: { UL: string; }; -export { Cmd, CmdResult, Document, Element, FencedCode, FigCaption, Figure, Heading, Image, Include, InlineCode, LI, Link, NewElement, NewLink, NewText, NewUL, type Node, OL, Page, ParseNodes, type PostMarshaller, Ref, Snippet, SourceCode, Table, Text, Toc, UL, VisitAtom, type VisitNode, atoms, gotypes }; +export { Cmd, CmdResult, Document, Element, EmptyModule, FencedCode, FigCaption, Figure, Heading, Image, Include, InlineCode, LI, Link, Module, NewElement, NewLink, NewText, NewUL, type Node, OL, Page, Parser, Ref, Snippet, SourceCode, Table, Text, Toc, UL, VisitAtom, type VisitNode, atoms, gotypes }; diff --git a/package-lock.json b/package-lock.json index 7580119..fd9375c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "fs": "^0.0.1-security", "jest-cucumber": "^3.0.1", + "path-browserify": "^1.0.1", "rollup-plugin-dts": "^6.1.0", "uuid": "^9.0.1" }, @@ -18,6 +19,7 @@ "@rollup/plugin-typescript": "^11.1.6", "@types/jest": "^28.1.8", "@types/node": "^18.6.1", + "@types/path-browserify": "^1.0.2", "@typescript-eslint/eslint-plugin": "^5.31.0", "@typescript-eslint/parser": "^5.31.0", "eslint": "^8.20.0", @@ -30,6 +32,7 @@ "onchange": "^7.1.0", "prettier": "^2.7.1", "rimraf": "^3.0.2", + "rollup": "^4.10.0", "run-script-os": "^1.1.6", "ts-jest": "^28.0.7", "ts-node": "^10.9.1", @@ -1341,173 +1344,160 @@ } }, "node_modules/@rollup/rollup-android-arm-eabi": { - "version": "4.9.6", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.9.6.tgz", - "integrity": "sha512-MVNXSSYN6QXOulbHpLMKYi60ppyO13W9my1qogeiAqtjb2yR4LSmfU2+POvDkLzhjYLXz9Rf9+9a3zFHW1Lecg==", + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.10.0.tgz", + "integrity": "sha512-/MeDQmcD96nVoRumKUljsYOLqfv1YFJps+0pTrb2Z9Nl/w5qNUysMaWQsrd1mvAlNT4yza1iVyIu4Q4AgF6V3A==", "cpu": [ "arm" ], "optional": true, "os": [ "android" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-android-arm64": { - "version": "4.9.6", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.9.6.tgz", - "integrity": "sha512-T14aNLpqJ5wzKNf5jEDpv5zgyIqcpn1MlwCrUXLrwoADr2RkWA0vOWP4XxbO9aiO3dvMCQICZdKeDrFl7UMClw==", + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.10.0.tgz", + "integrity": "sha512-lvu0jK97mZDJdpZKDnZI93I0Om8lSDaiPx3OiCk0RXn3E8CMPJNS/wxjAvSJJzhhZpfjXsjLWL8LnS6qET4VNQ==", "cpu": [ "arm64" ], "optional": true, "os": [ "android" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-darwin-arm64": { - "version": "4.9.6", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.9.6.tgz", - "integrity": "sha512-CqNNAyhRkTbo8VVZ5R85X73H3R5NX9ONnKbXuHisGWC0qRbTTxnF1U4V9NafzJbgGM0sHZpdO83pLPzq8uOZFw==", + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.10.0.tgz", + "integrity": "sha512-uFpayx8I8tyOvDkD7X6n0PriDRWxcqEjqgtlxnUA/G9oS93ur9aZ8c8BEpzFmsed1TH5WZNG5IONB8IiW90TQg==", "cpu": [ "arm64" ], "optional": true, "os": [ "darwin" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-darwin-x64": { - "version": "4.9.6", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.9.6.tgz", - "integrity": "sha512-zRDtdJuRvA1dc9Mp6BWYqAsU5oeLixdfUvkTHuiYOHwqYuQ4YgSmi6+/lPvSsqc/I0Omw3DdICx4Tfacdzmhog==", + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.10.0.tgz", + "integrity": "sha512-nIdCX03qFKoR/MwQegQBK+qZoSpO3LESurVAC6s6jazLA1Mpmgzo3Nj3H1vydXp/JM29bkCiuF7tDuToj4+U9Q==", "cpu": [ "x64" ], "optional": true, "os": [ "darwin" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-linux-arm-gnueabihf": { - "version": "4.9.6", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.9.6.tgz", - "integrity": "sha512-oNk8YXDDnNyG4qlNb6is1ojTOGL/tRhbbKeE/YuccItzerEZT68Z9gHrY3ROh7axDc974+zYAPxK5SH0j/G+QQ==", + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.10.0.tgz", + "integrity": "sha512-Fz7a+y5sYhYZMQFRkOyCs4PLhICAnxRX/GnWYReaAoruUzuRtcf+Qnw+T0CoAWbHCuz2gBUwmWnUgQ67fb3FYw==", "cpu": [ "arm" ], "optional": true, "os": [ "linux" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-linux-arm64-gnu": { - "version": "4.9.6", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.9.6.tgz", - "integrity": "sha512-Z3O60yxPtuCYobrtzjo0wlmvDdx2qZfeAWTyfOjEDqd08kthDKexLpV97KfAeUXPosENKd8uyJMRDfFMxcYkDQ==", + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.10.0.tgz", + "integrity": "sha512-yPtF9jIix88orwfTi0lJiqINnlWo6p93MtZEoaehZnmCzEmLL0eqjA3eGVeyQhMtxdV+Mlsgfwhh0+M/k1/V7Q==", "cpu": [ "arm64" ], "optional": true, "os": [ "linux" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-linux-arm64-musl": { - "version": "4.9.6", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.9.6.tgz", - "integrity": "sha512-gpiG0qQJNdYEVad+1iAsGAbgAnZ8j07FapmnIAQgODKcOTjLEWM9sRb+MbQyVsYCnA0Im6M6QIq6ax7liws6eQ==", + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.10.0.tgz", + "integrity": "sha512-9GW9yA30ib+vfFiwjX+N7PnjTnCMiUffhWj4vkG4ukYv1kJ4T9gHNg8zw+ChsOccM27G9yXrEtMScf1LaCuoWQ==", "cpu": [ "arm64" ], "optional": true, "os": [ "linux" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-linux-riscv64-gnu": { - "version": "4.9.6", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.9.6.tgz", - "integrity": "sha512-+uCOcvVmFUYvVDr27aiyun9WgZk0tXe7ThuzoUTAukZJOwS5MrGbmSlNOhx1j80GdpqbOty05XqSl5w4dQvcOA==", + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.10.0.tgz", + "integrity": "sha512-X1ES+V4bMq2ws5fF4zHornxebNxMXye0ZZjUrzOrf7UMx1d6wMQtfcchZ8SqUnQPPHdOyOLW6fTcUiFgHFadRA==", "cpu": [ "riscv64" ], "optional": true, "os": [ "linux" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-linux-x64-gnu": { - "version": "4.9.6", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.9.6.tgz", - "integrity": "sha512-HUNqM32dGzfBKuaDUBqFB7tP6VMN74eLZ33Q9Y1TBqRDn+qDonkAUyKWwF9BR9unV7QUzffLnz9GrnKvMqC/fw==", + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.10.0.tgz", + "integrity": "sha512-w/5OpT2EnI/Xvypw4FIhV34jmNqU5PZjZue2l2Y3ty1Ootm3SqhI+AmfhlUYGBTd9JnpneZCDnt3uNOiOBkMyw==", "cpu": [ "x64" ], "optional": true, "os": [ "linux" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-linux-x64-musl": { - "version": "4.9.6", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.9.6.tgz", - "integrity": "sha512-ch7M+9Tr5R4FK40FHQk8VnML0Szi2KRujUgHXd/HjuH9ifH72GUmw6lStZBo3c3GB82vHa0ZoUfjfcM7JiiMrQ==", + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.10.0.tgz", + "integrity": "sha512-q/meftEe3QlwQiGYxD9rWwB21DoKQ9Q8wA40of/of6yGHhZuGfZO0c3WYkN9dNlopHlNT3mf5BPsUSxoPuVQaw==", "cpu": [ "x64" ], "optional": true, "os": [ "linux" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-win32-arm64-msvc": { - "version": "4.9.6", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.9.6.tgz", - "integrity": "sha512-VD6qnR99dhmTQ1mJhIzXsRcTBvTjbfbGGwKAHcu+52cVl15AC/kplkhxzW/uT0Xl62Y/meBKDZvoJSJN+vTeGA==", + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.10.0.tgz", + "integrity": "sha512-NrR6667wlUfP0BHaEIKgYM/2va+Oj+RjZSASbBMnszM9k+1AmliRjHc3lJIiOehtSSjqYiO7R6KLNrWOX+YNSQ==", "cpu": [ "arm64" ], "optional": true, "os": [ "win32" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-win32-ia32-msvc": { - "version": "4.9.6", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.9.6.tgz", - "integrity": "sha512-J9AFDq/xiRI58eR2NIDfyVmTYGyIZmRcvcAoJ48oDld/NTR8wyiPUu2X/v1navJ+N/FGg68LEbX3Ejd6l8B7MQ==", + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.10.0.tgz", + "integrity": "sha512-FV0Tpt84LPYDduIDcXvEC7HKtyXxdvhdAOvOeWMWbQNulxViH2O07QXkT/FffX4FqEI02jEbCJbr+YcuKdyyMg==", "cpu": [ "ia32" ], "optional": true, "os": [ "win32" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-win32-x64-msvc": { - "version": "4.9.6", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.9.6.tgz", - "integrity": "sha512-jqzNLhNDvIZOrt69Ce4UjGRpXJBzhUBzawMwnaDAwyHriki3XollsewxWzOzz+4yOFDkuJHtTsZFwMxhYJWmLQ==", + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.10.0.tgz", + "integrity": "sha512-OZoJd+o5TaTSQeFFQ6WjFCiltiYVjIdsXxwu/XZ8qRpsvMQr4UsVrE5UyT9RIvsnuF47DqkJKhhVZ2Q9YW9IpQ==", "cpu": [ "x64" ], "optional": true, "os": [ "win32" - ], - "peer": true + ] }, "node_modules/@sinclair/typebox": { "version": "0.24.51", @@ -1683,6 +1673,12 @@ "resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.4.tgz", "integrity": "sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA==" }, + "node_modules/@types/path-browserify": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@types/path-browserify/-/path-browserify-1.0.2.tgz", + "integrity": "sha512-ZkC5IUqqIFPXx3ASTTybTzmQdwHwe2C0u3eL75ldQ6T9E9IWFJodn6hIfbZGab73DfyiHN4Xw15gNxUq2FbvBA==", + "dev": true + }, "node_modules/@types/prettier": { "version": "2.7.3", "resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.7.3.tgz", @@ -7547,6 +7543,11 @@ "node": ">=0.10.0" } }, + "node_modules/path-browserify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz", + "integrity": "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==" + }, "node_modules/path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -8084,10 +8085,9 @@ } }, "node_modules/rollup": { - "version": "4.9.6", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.9.6.tgz", - "integrity": "sha512-05lzkCS2uASX0CiLFybYfVkwNbKZG5NFQ6Go0VWyogFTXXbR039UVsegViTntkk4OglHBdF54ccApXRRuXRbsg==", - "peer": true, + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.10.0.tgz", + "integrity": "sha512-t2v9G2AKxcQ8yrG+WGxctBes1AomT0M4ND7jTFBCVPXQ/WFTvNSefIrNSmLKhIKBrvN8SG+CZslimJcT3W2u2g==", "dependencies": { "@types/estree": "1.0.5" }, @@ -8099,19 +8099,19 @@ "npm": ">=8.0.0" }, "optionalDependencies": { - "@rollup/rollup-android-arm-eabi": "4.9.6", - "@rollup/rollup-android-arm64": "4.9.6", - "@rollup/rollup-darwin-arm64": "4.9.6", - "@rollup/rollup-darwin-x64": "4.9.6", - "@rollup/rollup-linux-arm-gnueabihf": "4.9.6", - "@rollup/rollup-linux-arm64-gnu": "4.9.6", - "@rollup/rollup-linux-arm64-musl": "4.9.6", - "@rollup/rollup-linux-riscv64-gnu": "4.9.6", - "@rollup/rollup-linux-x64-gnu": "4.9.6", - "@rollup/rollup-linux-x64-musl": "4.9.6", - "@rollup/rollup-win32-arm64-msvc": "4.9.6", - "@rollup/rollup-win32-ia32-msvc": "4.9.6", - "@rollup/rollup-win32-x64-msvc": "4.9.6", + "@rollup/rollup-android-arm-eabi": "4.10.0", + "@rollup/rollup-android-arm64": "4.10.0", + "@rollup/rollup-darwin-arm64": "4.10.0", + "@rollup/rollup-darwin-x64": "4.10.0", + "@rollup/rollup-linux-arm-gnueabihf": "4.10.0", + "@rollup/rollup-linux-arm64-gnu": "4.10.0", + "@rollup/rollup-linux-arm64-musl": "4.10.0", + "@rollup/rollup-linux-riscv64-gnu": "4.10.0", + "@rollup/rollup-linux-x64-gnu": "4.10.0", + "@rollup/rollup-linux-x64-musl": "4.10.0", + "@rollup/rollup-win32-arm64-msvc": "4.10.0", + "@rollup/rollup-win32-ia32-msvc": "4.10.0", + "@rollup/rollup-win32-x64-msvc": "4.10.0", "fsevents": "~2.3.2" } }, diff --git a/package.json b/package.json index de8b385..964c7db 100644 --- a/package.json +++ b/package.json @@ -34,8 +34,10 @@ }, "keywords": [], "devDependencies": { + "@rollup/plugin-typescript": "^11.1.6", "@types/jest": "^28.1.8", "@types/node": "^18.6.1", + "@types/path-browserify": "^1.0.2", "@typescript-eslint/eslint-plugin": "^5.31.0", "@typescript-eslint/parser": "^5.31.0", "eslint": "^8.20.0", @@ -48,6 +50,7 @@ "onchange": "^7.1.0", "prettier": "^2.7.1", "rimraf": "^3.0.2", + "rollup": "^4.10.0", "run-script-os": "^1.1.6", "ts-jest": "^28.0.7", "ts-node": "^10.9.1", @@ -56,10 +59,12 @@ "dependencies": { "fs": "^0.0.1-security", "jest-cucumber": "^3.0.1", + "path-browserify": "^1.0.1", + "rollup-plugin-dts": "^6.1.0", "uuid": "^9.0.1" }, "bugs": { "url": "https://github.com/gopherguides/hypejs/issues" }, "homepage": "https://github.com/gopherguides/hypejs#readme" -} \ No newline at end of file +} diff --git a/rollup.config.mjs b/rollup.config.mjs index 75c06da..4e53f56 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -6,7 +6,7 @@ export default [ input: "src/index.ts", output: { dir: "dist", - format: "cjs", + // format: "cjs", }, plugins: [typescript()], }, diff --git a/src/document.spec.ts b/src/document.spec.ts index 7e4b5da..a1022a1 100644 --- a/src/document.spec.ts +++ b/src/document.spec.ts @@ -1,70 +1,70 @@ import exp from "constants"; -import { Document } from "./document" +import { Parser } from "./parser"; +describe('document', () => { -describe('hype', () => { + describe('parsers correctly', () => { - class tc { - name: string = ""; - input: any; - title: string = ""; - } - - let tcs: tc[] = [ - { - name: "arrays", - input: require('./testdata/arrays.json'), - title: "Arrays, Slices, and Iteration" - }, - { - name: "errors", - input: require('./testdata/errors.json'), - title: "Errors", - }, - { - name: "generics", - input: require('./testdata/generics.json'), - title: "Generics", - }, - { - name: "files", - input: require('./testdata/files.json'), - title: "Working With Files", - }, - { - name: "channels", - input: require('./testdata/channels.json'), - title: "Channels", - }, - { - name: "context", - input: require('./testdata/context.json'), - title: "Context", + class tc { + name: string = ""; + input: any; + title: string = ""; } - ] - tcs.forEach(tc => { - test(tc.name, () => { - let d = new Document(tc.input) - expect(d.id).toBeDefined(); + let tcs: tc[] = [ + { + name: "arrays", + input: require('./testdata/arrays.json'), + title: "Arrays, Slices, and Iteration" + }, + { + name: "errors", + input: require('./testdata/errors.json'), + title: "Errors", + }, + { + name: "generics", + input: require('./testdata/generics.json'), + title: "Generics", + }, + { + name: "files", + input: require('./testdata/files.json'), + title: "Working With Files", + }, + { + name: "channels", + input: require('./testdata/channels.json'), + title: "Channels", + }, + { + name: "context", + input: require('./testdata/context.json'), + title: "Context", + } + ] + + tcs.forEach(tc => { + let p: Parser = new Parser(); + test(tc.name, () => { + let d = p.parse(tc.input) + expect(d.id).toBeDefined(); - expect(d.atom).toBeUndefined(); - expect(d.type).toEqual("*hype.Document"); - expect(d.title).toEqual(tc.title); - expect(d.nodes?.length).toEqual(1); + expect(d.atom).toBeUndefined(); + expect(d.type).toEqual("*hype.Document"); + expect(d.title).toEqual(tc.title); + expect(d.nodes?.length).toEqual(1); - let html = d.nodes ? d.nodes[0] : undefined; + let html = d.nodes ? d.nodes[0] : undefined; - expect(html).toBeDefined(); - expect(html?.nodes?.length).toEqual(1); + expect(html).toBeDefined(); + expect(html?.nodes?.length).toEqual(1); - // expect(d.toString()).toEqual("Document: " + tc.title); + // expect(d.toString()).toEqual("Document: " + tc.title); + }) }) - }) - test('simple document', () => { - let d = new Document(require("./testdata/simple.json")) - expect(d.title).toEqual("Simple") - }) + + }); }); \ No newline at end of file diff --git a/src/document.ts b/src/document.ts index 6c27832..dd98fca 100644 --- a/src/document.ts +++ b/src/document.ts @@ -1,5 +1,4 @@ import { Element } from "./element"; -import { ParseNodes } from "./parse_nodes"; import { v4 as uuidv4 } from 'uuid'; export class Document extends Element { @@ -23,18 +22,27 @@ export class Document extends Element { this.title = el.title; this.parser = el.parser; this.file = el.file; + if (this.file === undefined) { this.file = "module.md" } this.id = el.id ? el.id : uuidv4(); - this.nodes = ParseNodes(el.nodes); + this.nodes = el.nodes; + // this.nodes = ParseNodes(el.nodes); + } toString(): string { let s: string = ""; this.nodes?.forEach((n: any) => { - s += n.toString(); + if (Array.isArray(n)) { + n.forEach((n: any) => { + s += n.toString(); + }); + } else { + s += n.toString(); + } }); return s; } diff --git a/src/element.ts b/src/element.ts index 8db1c10..221b0ec 100644 --- a/src/element.ts +++ b/src/element.ts @@ -26,7 +26,14 @@ export class Element implements Node { this.nodes?.forEach((n: any) => { if (n === undefined) return; - s += n.toString(); + + if (Array.isArray(n)) { + n.forEach((n: any) => { + s += n.toString(); + }); + } else { + s += n.toString(); + } }); if (this.atom === undefined) diff --git a/src/empty_mod.ts b/src/empty_mod.ts new file mode 100644 index 0000000..244ac71 --- /dev/null +++ b/src/empty_mod.ts @@ -0,0 +1,12 @@ +import { Module } from "./module"; +import { Document } from "./document" + +export function EmptyModule(): Module { + return new Module({ + id: "", + doc: new Document({}), + dir: "", + filepath: "", + name: "", + }); +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 8932c5a..d347cb4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,45 @@ -export type { Node } from "./node" +// export type { Node } from "./node" +// export { Cmd } from "./cmd" +// export { CmdResult } from "./cmd_result" +// export { Document } from "./document" +// export { FencedCode } from "./fenced_code" +// export { FigCaption } from "./fig_caption" +// export { Figure } from "./figure" +// export { Heading } from "./heading" +// export { Image } from "./image" +// export { Include } from "./include" +// export { InlineCode } from "./inline_code" +// export { LI } from "./li" +// export { Link, NewLink } from "./link" +// export { NewElement, Element } from "./element" +// export { NewText, Text } from "./text" +// export { NewUL, UL } from "./ul" +// export { OL } from "./ol" +// export { Page } from "./page" +// export { Ref } from "./ref" +// export { Snippet } from "./snippet" +// export { SourceCode } from "./source_code" +// export { Table } from "./table" +// export { Toc } from "./toc" +// export { Module } from "./module" +// export { Parser } from "./parser" +// export { EmptyModule } from "./empty_mod" + +// export type { VisitNode } from "./visit_node" + +// export { ParseNodes } from "./parse_nodes" +// export { VisitAtom } from "./visit_atom" + +// export { atoms } from "./atoms" +// export { gotypes } from "./gotypes + + + export { Cmd } from "./cmd" export { CmdResult } from "./cmd_result" export { Document } from "./document" +export { Element } from "./element" +export { EmptyModule } from "./empty_mod" export { FencedCode } from "./fenced_code" export { FigCaption } from "./fig_caption" export { Figure } from "./figure" @@ -10,23 +48,24 @@ export { Image } from "./image" export { Include } from "./include" export { InlineCode } from "./inline_code" export { LI } from "./li" -export { Link, NewLink } from "./link" -export { NewElement, Element } from "./element" -export { NewText, Text } from "./text" -export { NewUL, UL } from "./ul" +export { Link } from "./link" +export { Module } from "./module" +export { NewElement } from "./element" +export { NewLink } from "./link" +export { NewText } from "./text" +export { NewUL } from "./ul" +export { Node } from "./node" export { OL } from "./ol" export { Page } from "./page" -export { PostMarshaller } from "./callbacks" +export { Parser } from "./parser" export { Ref } from "./ref" export { Snippet } from "./snippet" export { SourceCode } from "./source_code" export { Table } from "./table" +export { Text } from "./text" export { Toc } from "./toc" - -export type { VisitNode } from "./visit_node" - -export { ParseNodes } from "./parse_nodes" +export { UL } from "./ul" export { VisitAtom } from "./visit_atom" - +export { VisitNode } from "./visit_node" export { atoms } from "./atoms" -export { gotypes } from "./gotypes" +export { gotypes } from "./gotypes" \ No newline at end of file diff --git a/src/module.spec.ts b/src/module.spec.ts new file mode 100644 index 0000000..58b746c --- /dev/null +++ b/src/module.spec.ts @@ -0,0 +1,27 @@ +import exp from "constants"; +import { Document } from "./document" +import { Module } from "./module" +import { Toc } from "./toc" + +describe('module', () => { + + let data = require("./testdata/context.json") + + test("should parse", () => { + let mod: Module = new Module(data) + + expect(mod).toBeDefined(); + expect(mod.id).toBeDefined(); + expect(mod.name).toEqual("module.md"); + expect(mod.title()).toEqual("Context"); + + let doc: Document = mod.doc; + expect(doc).toBeDefined(); + expect(doc.title).toEqual("Context"); + + let toc: Toc = mod.toc; + expect(toc).toBeDefined(); + expect(toc.ids.length).toEqual(42); + expect(toc.nodes.length).toEqual(42); + }) +}) \ No newline at end of file diff --git a/src/module.ts b/src/module.ts new file mode 100644 index 0000000..040e98a --- /dev/null +++ b/src/module.ts @@ -0,0 +1,57 @@ + +import { Document } from "./document" +import { Toc } from "./toc" +import { v4 as uuid } from "uuid" +import path from "path-browserify" +import { Parser } from "./parser" + +export class Module { + id: string = ""; + dir: string = ""; + filepath: string = ""; + name: string = ""; + + parser: Parser; + doc: Document; + toc: Toc; + + constructor(mod: any, parser?: Parser) { + this.id = uuid(); + if (mod.id) { + this.id = mod.id; + } + + if (mod.file === undefined) { + mod.file = "module.md" + } + + if (mod.root === undefined) { + mod.root = ""; + } + + this.filepath = path.join(mod.root, mod.file); + this.dir = mod.root + this.name = mod.file ? mod.file : "module.md"; + + this.parser = parser ? parser : new Parser(); + + this.doc = this.parser.parse(mod.doc ? mod.doc : mod); + this.toc = new Toc(); + this.toc.perform(this.doc); + } + + title(): string { + if (this.doc === undefined) { + return this.name; + } + return this.doc.title; + } + + toString(): string { + if (this.doc === undefined) { + return ""; + } + return this.doc.toString(); + } + +} diff --git a/src/parse_nodes.ts b/src/parse_nodes.ts deleted file mode 100644 index f9b71c9..0000000 --- a/src/parse_nodes.ts +++ /dev/null @@ -1,116 +0,0 @@ -import type { Node } from "./node"; -import { Cmd } from "./cmd"; -import { CmdResult } from "./cmd_result"; -import { Element } from "./element"; -import { FencedCode } from "./fenced_code"; -import { FigCaption } from "./fig_caption"; -import { Figure } from "./figure"; -import { Heading } from "./heading"; -import { Image } from "./image"; -import { Include } from "./include"; -import { InlineCode } from "./inline_code"; -import { LI } from "./li"; -import { Link } from "./link"; -import { OL } from "./ol"; -import { Page } from "./page"; -import { Ref } from "./ref"; -import { Snippet } from "./snippet"; -import { SourceCode } from "./source_code"; -import { Table } from "./table"; -import { Text } from "./text"; -import { UL } from "./ul"; -import { gotypes } from "./gotypes"; - -export function ParseNodes(nodes: Node[] = []): Node[] { - let ret: Node[] = []; - - nodes.forEach((n: any) => { - if (n == null) { - return - } - - n.nodes = ParseNodes(n.nodes); - switch (n.type) { - case gotypes.Body: - case gotypes.Element: - case gotypes.Paragraph: - case gotypes.TD: - case gotypes.TH: - case gotypes.THead: - case gotypes.TR: - ret.push(new Element(n)) - break; - case gotypes.Page: - ret.push(new Page(n)) - break; - case gotypes.Text: - ret.push(new Text(n)) - break; - case gotypes.Heading: - ret.push(new Heading(n)) - break; - case gotypes.InlineCode: - ret.push(new InlineCode(n)) - break; - case gotypes.Include: - ret.push(new Include(n)) - break; - case gotypes.Link: - ret.push(new Link(n)) - break; - case gotypes.Figure: - ret.push(new Figure(n)) - break; - case gotypes.Table: - ret.push(new Table(n)) - break; - case gotypes.Ref: - ret.push(new Ref(n)) - break; - case gotypes.Cmd: - ret.push(new Cmd(n)) - break; - case gotypes.CmdResult: - ret.push(new CmdResult(n)) - break; - case gotypes.Snippet: - ret.push(new Snippet(n)) - break; - case gotypes.FencedCode: - ret.push(new FencedCode(n)) - break; - case gotypes.SourceCode: - ret.push(new SourceCode(n)) - break; - case gotypes.OL: - ret.push(new OL(n)) - break; - case gotypes.UL: - ret.push(new UL(n)) - break; - case gotypes.LI: - ret.push(new LI(n)) - break; - case gotypes.Image: - ret.push(new Image(n)) - break; - case gotypes.Figcaption: - case "*hype.FigCaption": - ret.push(new FigCaption(n)) - break; - default: - if (Array.isArray(n)) { - nodes = ParseNodes(n); - ret.push(...nodes); - break; - } - - console.log("unknown node type", n.type, n); - throw new Error("Unknown node type: " + n.type); - - break; - } - }); - - return ret; -} \ No newline at end of file diff --git a/src/parser.spec.ts b/src/parser.spec.ts new file mode 100644 index 0000000..5f58b55 --- /dev/null +++ b/src/parser.spec.ts @@ -0,0 +1,28 @@ +import exp from "constants"; +import { Parser } from "./parser"; +import { Element } from "./element"; + +describe('parser', () => { + + class CustomTag extends Element { + constructor(n: any) { + super(n); + } + } + + test('custom tags', () => { + let data = require("./testdata/custom.json") + + let p: Parser = new Parser(); + p.handlers["CustomTag"] = (n: any) => new CustomTag(n) + + let d = p.parse(data); + + expect(d.id).toBeDefined(); + expect(d.atom).toBeUndefined(); + expect(d.type).toEqual("*hype.Document"); + expect(d.title).toEqual("Custom Tags"); + expect(d.nodes?.length).toEqual(1); + }) + +}); \ No newline at end of file diff --git a/src/parser.ts b/src/parser.ts new file mode 100644 index 0000000..edac6ef --- /dev/null +++ b/src/parser.ts @@ -0,0 +1,101 @@ +import { Document } from "./document"; +import type { Node } from "./node"; +import { Cmd } from "./cmd"; +import { CmdResult } from "./cmd_result"; +import { Element } from "./element"; +import { FencedCode } from "./fenced_code"; +import { FigCaption } from "./fig_caption"; +import { Figure } from "./figure"; +import { Heading } from "./heading"; +import { Image } from "./image"; +import { Include } from "./include"; +import { InlineCode } from "./inline_code"; +import { LI } from "./li"; +import { Link } from "./link"; +import { OL } from "./ol"; +import { Page } from "./page"; +import { Ref } from "./ref"; +import { Snippet } from "./snippet"; +import { SourceCode } from "./source_code"; +import { Table } from "./table"; +import { Text } from "./text"; +import { UL } from "./ul"; +import { gotypes } from "./gotypes"; + +export class Parser { + + handlers: any = {} + + constructor() { + this.handlers[gotypes.Body] = newElement + this.handlers[gotypes.Element] = newElement + this.handlers[gotypes.Paragraph] = newElement + this.handlers[gotypes.TD] = newElement + this.handlers[gotypes.TH] = newElement + this.handlers[gotypes.THead] = newElement + this.handlers[gotypes.TR] = newElement + this.handlers[gotypes.CmdResult] = (n: any) => new CmdResult(n) + this.handlers[gotypes.Cmd] = (n: any) => new Cmd(n) + this.handlers[gotypes.FencedCode] = (n: any) => new FencedCode(n) + this.handlers[gotypes.Figcaption] = (n: any) => new FigCaption(n) + this.handlers[gotypes.Figure] = (n: any) => new Figure(n) + this.handlers[gotypes.Heading] = (n: any) => new Heading(n) + this.handlers[gotypes.Image] = (n: any) => new Image(n) + this.handlers[gotypes.Include] = (n: any) => new Include(n) + this.handlers[gotypes.InlineCode] = (n: any) => new InlineCode(n) + this.handlers[gotypes.LI] = (n: any) => new LI(n) + this.handlers[gotypes.Link] = (n: any) => new Link(n) + this.handlers[gotypes.OL] = (n: any) => new OL(n) + this.handlers[gotypes.Page] = (n: any) => new Page(n) + this.handlers[gotypes.Ref] = (n: any) => new Ref(n) + this.handlers[gotypes.Snippet] = (n: any) => new Snippet(n) + this.handlers[gotypes.SourceCode] = (n: any) => new SourceCode(n) + this.handlers[gotypes.Table] = (n: any) => new Table(n) + this.handlers[gotypes.Text] = (n: any) => new Text(n) + this.handlers[gotypes.UL] = (n: any) => new UL(n) + } + + parse(data: any): Document { + let doc: Document; + + data = structuredClone(data); + + data.nodes = this.parseNodes(data.nodes); + + return new Document(data); + } + + private parseNodes(nodes: Node[] = []): Node[] { + let ret: Node[] = []; + + nodes.forEach((n: any) => { + if (n == null) { + return + } + + if (Array.isArray(n)) { + let nodes = this.parseNodes(n); + ret.push(...nodes); + } else { + + n.nodes = this.parseNodes(n.nodes); + + let fn = this.handlers[n.type]; + if (fn === undefined) { + console.warn("unknown node type: " + n.type) + fn = newElement + } + + ret.push(fn(n)) + } + + }); + + return ret; + + } +} + +function newElement(n: any): Element { + return new Element(n) +} \ No newline at end of file diff --git a/src/snippet.ts b/src/snippet.ts index 8896b7e..5824f99 100644 --- a/src/snippet.ts +++ b/src/snippet.ts @@ -16,4 +16,8 @@ export class Snippet extends Element { this.start = s.start; this.end = s.end; } + + toString(): string { + return this.content + } } \ No newline at end of file diff --git a/src/testdata/arrays.json b/src/testdata/arrays.json index 5afe384..c8a8d5e 100644 --- a/src/testdata/arrays.json +++ b/src/testdata/arrays.json @@ -14135,5 +14135,6 @@ "section_id": 1, "snippets": {}, "title": "Arrays, Slices, and Iteration", - "type": "*hype.Document" -} + "type": "*hype.Document", + "filename": "module.md" +} \ No newline at end of file diff --git a/src/testdata/channels.json b/src/testdata/channels.json index b8c8f4b..19e80fe 100644 --- a/src/testdata/channels.json +++ b/src/testdata/channels.json @@ -14374,5 +14374,6 @@ "section_id": 1, "snippets": {}, "title": "Channels", - "type": "*hype.Document" -} + "type": "*hype.Document", + "filename": "module.md" +} \ No newline at end of file diff --git a/src/testdata/context.json b/src/testdata/context.json index 67ba317..a5cae88 100644 --- a/src/testdata/context.json +++ b/src/testdata/context.json @@ -19893,5 +19893,6 @@ "section_id": 1, "snippets": {}, "title": "Context", - "type": "*hype.Document" -} + "type": "*hype.Document", + "filename": "module.md" +} \ No newline at end of file diff --git a/src/testdata/custom.json b/src/testdata/custom.json new file mode 100644 index 0000000..5ceb3f9 --- /dev/null +++ b/src/testdata/custom.json @@ -0,0 +1,15 @@ +{ + "nodes": [ + { + "type": "CustomTag", + "atom": "custom", + "file": "custom.md", + "nodes": [] + } + ], + "parser": {}, + "root": "testdata", + "title": "Custom Tags", + "type": "*hype.Document", + "filename": "module.md" +} \ No newline at end of file diff --git a/src/testdata/errors.json b/src/testdata/errors.json index 76ba32a..6a5a13a 100644 --- a/src/testdata/errors.json +++ b/src/testdata/errors.json @@ -23052,5 +23052,6 @@ "section_id": 1, "snippets": {}, "title": "Errors", - "type": "*hype.Document" -} + "type": "*hype.Document", + "filename": "module.md" +} \ No newline at end of file diff --git a/src/testdata/files.json b/src/testdata/files.json index 7a9456d..9a0398e 100644 --- a/src/testdata/files.json +++ b/src/testdata/files.json @@ -26134,5 +26134,6 @@ "section_id": 1, "snippets": {}, "title": "Working With Files", - "type": "*hype.Document" -} + "type": "*hype.Document", + "filename": "module.md" +} \ No newline at end of file diff --git a/src/testdata/generics.json b/src/testdata/generics.json index 9d207ee..dfa046f 100644 --- a/src/testdata/generics.json +++ b/src/testdata/generics.json @@ -11716,5 +11716,6 @@ "section_id": 1, "snippets": {}, "title": "Generics", - "type": "*hype.Document" -} + "type": "*hype.Document", + "filename": "module.md" +} \ No newline at end of file diff --git a/src/testdata/simple.json b/src/testdata/simple.json index 08e9ec4..f313b56 100644 --- a/src/testdata/simple.json +++ b/src/testdata/simple.json @@ -3,5 +3,6 @@ "parser": {}, "root": "testdata", "title": "Simple", - "type": "*hype.Document" + "type": "*hype.Document", + "filename": "module.md" } \ No newline at end of file diff --git a/src/toc.spec.ts b/src/toc.spec.ts index 0d0aade..f680601 100644 --- a/src/toc.spec.ts +++ b/src/toc.spec.ts @@ -6,34 +6,17 @@ import { Text } from "./text"; import { Toc } from "./toc"; import { VisitAtom } from "./visit_atom"; import { atoms } from "./atoms" +import { Parser } from "./parser"; describe('toc', () => { + let p: Parser = new Parser(); let data = require("./testdata/errors.json") describe('errors doc', () => { - // test("should build a toc", () => { - // let doc = new Document(structuredClone(data)) - - // let toc = new Toc(doc) - // expect(toc.headings.length).toEqual(33) - - // let act: string = ""; - // toc.headings.forEach((n: Node) => { - // act += NodesToHtml(n.nodes ? n.nodes : []) + "\n"; - // }); - // act = act.trim(); - - - // let buf = fs.readFileSync(__dirname + "/testdata/tocs/errors.txt", "utf-8") - // let exp: string = buf.toString().trim(); - - // expect(act).toEqual(exp); - // }); - test("should generate html", () => { - let doc = new Document(structuredClone(data)) + let doc = p.parse(data); let toc = new Toc() diff --git a/src/visit_atom.spec.ts b/src/visit_atom.spec.ts index 634a049..f6c8dde 100644 --- a/src/visit_atom.spec.ts +++ b/src/visit_atom.spec.ts @@ -4,15 +4,17 @@ import { Node } from "./node"; import { Text } from "./text"; import { VisitAtom } from "./visit_atom"; import { atoms } from "./atoms" +import { Parser } from "./parser"; describe('visitAtom', () => { + let p: Parser = new Parser(); let data = require("./testdata/errors.json") describe('errors doc', () => { test('should find all the pages', () => { - let d = new Document(structuredClone(data)) + let d = p.parse(data); let found: Node[] = [] VisitAtom(atoms.Page, d, (n) => { @@ -29,7 +31,7 @@ describe('visitAtom', () => { }); test('should find all the includes and pages', () => { - let d = new Document(structuredClone(data)) + let d = p.parse(data); let found: Node[] = [] @@ -41,7 +43,7 @@ describe('visitAtom', () => { }); test('should find all the headings', () => { - let d = new Document(structuredClone(data)) + let d = p.parse(data); let found: Node[] = [] diff --git a/src/visit_atom.ts b/src/visit_atom.ts index c2cb425..b54d54e 100644 --- a/src/visit_atom.ts +++ b/src/visit_atom.ts @@ -23,26 +23,6 @@ export function VisitAtom(atom: string | string[], n: Node, fn: VisitNode) { fn(n); } }); - return - - // func ByAtom[T ~string](nodes Nodes, want ...T) []AtomableNode { - // var res []AtomableNode - // for _, n := range nodes { - // an, ok := n.(AtomableNode) - // if !ok { - // res = append(res, ByAtom(n.Children(), want...)...) - // continue - // } - // for _, w := range want { - // if an.Atom().String() == string(w) { - // res = append(res, an) - // break - // } - // } - - // res = append(res, ByAtom(n.Children(), want...)...) - // } - // return res - // } + return } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 63dfcf4..3336b34 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,6 +10,7 @@ "esModuleInterop": true, "types": ["node", "jest"], "skipLibCheck": true, + "moduleResolution": "node", "declaration": true }, "include": ["src/**/*"],