Skip to content

Commit

Permalink
feat(hiccup-markdown): replace parser
Browse files Browse the repository at this point in the history
BREAKING CHANGE: replace parser implementation

- switch to new parser (non-transducer based):
  - dcb7b19
  - 5d030ad
  - 656b90b
  - 8b215c6
- add/update parser types/interfaces
- add/update tests
- update deps
  • Loading branch information
postspectacular committed Feb 22, 2023
1 parent cf63de8 commit e425e87
Show file tree
Hide file tree
Showing 7 changed files with 756 additions and 962 deletions.
5 changes: 2 additions & 3 deletions packages/hiccup-markdown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,15 @@
"@thi.ng/api": "^8.7.2",
"@thi.ng/arrays": "^2.5.5",
"@thi.ng/checks": "^3.3.9",
"@thi.ng/compose": "^2.1.27",
"@thi.ng/defmulti": "^2.1.30",
"@thi.ng/emoji": "^0.0.1",
"@thi.ng/errors": "^2.2.11",
"@thi.ng/fsm": "^3.1.40",
"@thi.ng/hiccup": "^4.2.32",
"@thi.ng/logger": "^1.4.9",
"@thi.ng/parse": "^2.2.26",
"@thi.ng/strings": "^3.3.26",
"@thi.ng/text-canvas": "^2.4.29",
"@thi.ng/transducers": "^8.3.34"
"@thi.ng/text-canvas": "^2.4.29"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.34.2",
Expand Down
88 changes: 71 additions & 17 deletions packages/hiccup-markdown/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,72 @@
export interface TagFactories {
blockquote(children: any[]): any[];
code(body: string): any[];
codeblock(lang: string, body: string): any[];
em(body: string): any[];
heading(level: number, children: any[]): any[];
hr(): any[];
img(src: string, alt: string): any[];
li(children: any[]): any[];
link(href: string, body: string): any[];
list(type: string, items: any[]): any[];
paragraph(children: any[]): any[];
strike(body: string): any[];
strong(body: string): any[];
table(rows: any[]): any[];
td(i: number, children: any[]): any[];
tr(i: number, cells: any[]): any[];
import type { IObjectOf } from "@thi.ng/api";
import type { ILogger } from "@thi.ng/logger";

export interface TagTransforms {
bold(ctx: MDParseContext, body: string): any;
blockquote(ctx: MDParseContext, body: any[], meta?: any): any;
code(ctx: MDParseContext, body: string): any;
codeblock(
ctx: MDParseContext,
lang: string,
head: string,
body: string,
meta?: any
): any;
custom(ctx: MDParseContext, kind: string, body: string, meta?: any): any;
emoji(ctx: MDParseContext, id: string): any;
footnote(ctx: MDParseContext, id: string, body: any[], meta?: any): any;
footnoteRef(ctx: MDParseContext, id: string): any;
footnoteWrapper(ctx: MDParseContext, notes: IObjectOf<any>): any;
heading(ctx: MDParseContext, level: number, body: any[], meta?: any): any;
hr(ctx: MDParseContext, length: number): any;
img(ctx: MDParseContext, src: string, alt: string): any;
italic(ctx: MDParseContext, body: string): any;
link(ctx: MDParseContext, target: string, body: any[]): any;
linkRef(ctx: MDParseContext, refID: string, body: any[]): any;
meta(ctx: MDParseContext, body: string): any;
ol(ctx: MDParseContext, items: any[], meta?: any): any;
olitem(
ctx: MDParseContext,
attribs: TodoAttribs,
index: number,
...body: any[]
): any;
para(ctx: MDParseContext, body: any[], meta?: any): any;
strike(ctx: MDParseContext, body: string): any;
table(
ctx: MDParseContext,
align: ColumnAlign[],
head: any[],
rows: any[],
meta?: any
): any;
tableCell(ctx: MDParseContext, body: any[]): any;
tableRow(ctx: MDParseContext, cells: any[]): any;
ul(ctx: MDParseContext, items: any[], meta?: any): any;
ulitem(ctx: MDParseContext, attribs: TodoAttribs, ...body: any[]): any;
}

export interface MDParseContext {
logger?: ILogger;
tags: TagTransforms;
linkRefs: IObjectOf<string>;
footnotes: IObjectOf<any>;
headings: { level: number; body: any[] }[];
hasFootnotes: boolean;
meta?: any;
opts: ParseOpts;
}

export interface ParseOpts {
/**
* Line break representation in blockquotes. E.g. Use `["br",{}]` for actual
* line breaks.
*
* @defaultValue `" "`
*/
bqLineBreak: any;
}

export type TodoAttribs = Partial<{ __todo: true; __done: boolean }>;

export type ColumnAlign = "center" | "left" | "right";
1 change: 0 additions & 1 deletion packages/hiccup-markdown/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./api.js";
export * from "./parse.js";
export * from "./parser.js";
export * from "./serialize.js";
Loading

0 comments on commit e425e87

Please sign in to comment.