@markdoc/markdoc 0.3.5 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.js CHANGED
@@ -15,7 +15,7 @@ Tag.isTag = (tag) => {
15
15
  function tagName(name, components) {
16
16
  return typeof name !== "string" ? name : name[0] !== name[0].toUpperCase() ? name : components instanceof Function ? components(name) : components[name];
17
17
  }
18
- function dynamic(node, React, { components = {} } = {}) {
18
+ function dynamic(node, React, { components = {}, resolveTagName = tagName } = {}) {
19
19
  function deepRender(value) {
20
20
  if (value == null || typeof value !== "object")
21
21
  return value;
@@ -42,7 +42,7 @@ function dynamic(node, React, { components = {} } = {}) {
42
42
  } = node2;
43
43
  if (className)
44
44
  attrs.className = className;
45
- return React.createElement(tagName(name, components), Object.keys(attrs).length == 0 ? null : deepRender(attrs), ...children.map(render));
45
+ return React.createElement(resolveTagName(name, components), Object.keys(attrs).length == 0 ? null : deepRender(attrs), ...children.map(render));
46
46
  }
47
47
  return render(node);
48
48
  }
package/dist/react.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/tag.ts", "../src/renderers/react/react.ts"],
4
- "sourcesContent": ["import type { RenderableTreeNode } from './types';\n\nexport default class Tag<\n N extends string = string,\n A extends Record<string, any> = Record<string, any>\n> {\n readonly $$mdtype = 'Tag' as const;\n\n static isTag = (tag: any): tag is Tag => {\n return !!(tag?.$$mdtype === 'Tag');\n };\n\n name: N;\n attributes: A;\n children: RenderableTreeNode[];\n\n constructor(\n name = 'div' as N,\n attributes = {} as A,\n children: RenderableTreeNode[] = []\n ) {\n this.name = name;\n this.attributes = attributes;\n this.children = children;\n }\n}\n", "import Tag from '../../tag';\nimport { RenderableTreeNodes, Scalar } from '../../types';\n\nimport type { createElement, ComponentType, Fragment, ReactNode } from 'react';\n\ntype ReactShape = Readonly<{\n createElement: typeof createElement;\n Fragment: typeof Fragment;\n}>;\n\ntype Component = ComponentType<unknown>;\n\nfunction tagName(\n name: string,\n components: Record<string, Component> | ((string: string) => Component)\n): string | Component {\n return typeof name !== 'string'\n ? name // This can be an object, e.g. when React.forwardRef is used\n : name[0] !== name[0].toUpperCase()\n ? name\n : components instanceof Function\n ? components(name)\n : components[name];\n}\n\nexport default function dynamic(\n node: RenderableTreeNodes,\n React: ReactShape,\n { components = {} } = {}\n) {\n function deepRender(value: any): any {\n if (value == null || typeof value !== 'object') return value;\n\n if (Array.isArray(value)) return value.map((item) => deepRender(item));\n\n if (value.$$mdtype === 'Tag') return render(value);\n\n if (typeof value !== 'object') return value;\n\n const output: Record<string, Scalar> = {};\n for (const [k, v] of Object.entries(value)) output[k] = deepRender(v);\n return output;\n }\n\n function render(node: RenderableTreeNodes): ReactNode {\n if (Array.isArray(node))\n return React.createElement(React.Fragment, null, ...node.map(render));\n\n if (node === null || typeof node !== 'object' || !Tag.isTag(node))\n return node;\n\n const {\n name,\n attributes: { class: className, ...attrs } = {},\n children = [],\n } = node;\n\n if (className) attrs.className = className;\n\n return React.createElement(\n tagName(name, components),\n Object.keys(attrs).length == 0 ? null : deepRender(attrs),\n ...children.map(render)\n );\n }\n\n return render(node);\n}\n"],
5
- "mappings": ";AAEA,gBAGE;AAAA,EAWA,YACE,OAAO,OACP,aAAa,IACb,WAAiC,IACjC;AAdO,oBAAW;AAelB,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,WAAW;AAAA;AAAA;AAfX,AANT,IAMS,QAAQ,CAAC,QAAyB;AACvC,SAAO,CAAC,CAAE,MAAK,aAAa;AAAA;;;ACGhC,iBACE,MACA,YACoB;AACpB,SAAO,OAAO,SAAS,WACnB,OACA,KAAK,OAAO,KAAK,GAAG,gBACpB,OACA,sBAAsB,WACtB,WAAW,QACX,WAAW;AAAA;AAGF,iBACb,MACA,OACA,EAAE,aAAa,OAAO,IACtB;AACA,sBAAoB,OAAiB;AACnC,QAAI,SAAS,QAAQ,OAAO,UAAU;AAAU,aAAO;AAEvD,QAAI,MAAM,QAAQ;AAAQ,aAAO,MAAM,IAAI,CAAC,SAAS,WAAW;AAEhE,QAAI,MAAM,aAAa;AAAO,aAAO,OAAO;AAE5C,QAAI,OAAO,UAAU;AAAU,aAAO;AAEtC,UAAM,SAAiC;AACvC,eAAW,CAAC,GAAG,MAAM,OAAO,QAAQ;AAAQ,aAAO,KAAK,WAAW;AACnE,WAAO;AAAA;AAGT,kBAAgB,OAAsC;AACpD,QAAI,MAAM,QAAQ;AAChB,aAAO,MAAM,cAAc,MAAM,UAAU,MAAM,GAAG,MAAK,IAAI;AAE/D,QAAI,UAAS,QAAQ,OAAO,UAAS,YAAY,CAAC,IAAI,MAAM;AAC1D,aAAO;AAET,UAAM;AAAA,MACJ;AAAA,MACA,YAAY,EAAE,OAAO,cAAc,UAAU;AAAA,MAC7C,WAAW;AAAA,QACT;AAEJ,QAAI;AAAW,YAAM,YAAY;AAEjC,WAAO,MAAM,cACX,QAAQ,MAAM,aACd,OAAO,KAAK,OAAO,UAAU,IAAI,OAAO,WAAW,QACnD,GAAG,SAAS,IAAI;AAAA;AAIpB,SAAO,OAAO;AAAA;",
4
+ "sourcesContent": ["import type { RenderableTreeNode } from './types';\n\nexport default class Tag<\n N extends string = string,\n A extends Record<string, any> = Record<string, any>\n> {\n readonly $$mdtype = 'Tag' as const;\n\n static isTag = (tag: any): tag is Tag => {\n return !!(tag?.$$mdtype === 'Tag');\n };\n\n name: N;\n attributes: A;\n children: RenderableTreeNode[];\n\n constructor(\n name = 'div' as N,\n attributes = {} as A,\n children: RenderableTreeNode[] = []\n ) {\n this.name = name;\n this.attributes = attributes;\n this.children = children;\n }\n}\n", "import Tag from '../../tag';\nimport { RenderableTreeNodes, Scalar } from '../../types';\n\nimport type { createElement, ComponentType, Fragment, ReactNode } from 'react';\n\ntype ReactShape = Readonly<{\n createElement: typeof createElement;\n Fragment: typeof Fragment;\n}>;\n\ntype Component = ComponentType<unknown>;\n\nfunction tagName(\n name: string,\n components: Record<string, Component> | ((string: string) => Component)\n): string | Component {\n return typeof name !== 'string'\n ? name // This can be an object, e.g. when React.forwardRef is used\n : name[0] !== name[0].toUpperCase()\n ? name\n : components instanceof Function\n ? components(name)\n : components[name];\n}\n\nexport type RenderOpts = {\n components?: Record<string, Component> | ((string: string) => Component);\n resolveTagName?: typeof tagName;\n};\nexport default function dynamic(\n node: RenderableTreeNodes,\n React: ReactShape,\n { components = {}, resolveTagName = tagName }: RenderOpts = {}\n) {\n function deepRender(value: any): any {\n if (value == null || typeof value !== 'object') return value;\n\n if (Array.isArray(value)) return value.map((item) => deepRender(item));\n\n if (value.$$mdtype === 'Tag') return render(value);\n\n if (typeof value !== 'object') return value;\n\n const output: Record<string, Scalar> = {};\n for (const [k, v] of Object.entries(value)) output[k] = deepRender(v);\n return output;\n }\n\n function render(node: RenderableTreeNodes): ReactNode {\n if (Array.isArray(node))\n return React.createElement(React.Fragment, null, ...node.map(render));\n\n if (node === null || typeof node !== 'object' || !Tag.isTag(node))\n return node;\n\n const {\n name,\n attributes: { class: className, ...attrs } = {},\n children = [],\n } = node;\n\n if (className) attrs.className = className;\n\n return React.createElement(\n resolveTagName(name, components),\n Object.keys(attrs).length == 0 ? null : deepRender(attrs),\n ...children.map(render)\n );\n }\n\n return render(node);\n}\n"],
5
+ "mappings": ";AAEA,gBAGE;AAAA,EAWA,YACE,OAAO,OACP,aAAa,IACb,WAAiC,IACjC;AAdO,oBAAW;AAelB,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,WAAW;AAAA;AAAA;AAfX,AANT,IAMS,QAAQ,CAAC,QAAyB;AACvC,SAAO,CAAC,CAAE,MAAK,aAAa;AAAA;;;ACGhC,iBACE,MACA,YACoB;AACpB,SAAO,OAAO,SAAS,WACnB,OACA,KAAK,OAAO,KAAK,GAAG,gBACpB,OACA,sBAAsB,WACtB,WAAW,QACX,WAAW;AAAA;AAOF,iBACb,MACA,OACA,EAAE,aAAa,IAAI,iBAAiB,YAAwB,IAC5D;AACA,sBAAoB,OAAiB;AACnC,QAAI,SAAS,QAAQ,OAAO,UAAU;AAAU,aAAO;AAEvD,QAAI,MAAM,QAAQ;AAAQ,aAAO,MAAM,IAAI,CAAC,SAAS,WAAW;AAEhE,QAAI,MAAM,aAAa;AAAO,aAAO,OAAO;AAE5C,QAAI,OAAO,UAAU;AAAU,aAAO;AAEtC,UAAM,SAAiC;AACvC,eAAW,CAAC,GAAG,MAAM,OAAO,QAAQ;AAAQ,aAAO,KAAK,WAAW;AACnE,WAAO;AAAA;AAGT,kBAAgB,OAAsC;AACpD,QAAI,MAAM,QAAQ;AAChB,aAAO,MAAM,cAAc,MAAM,UAAU,MAAM,GAAG,MAAK,IAAI;AAE/D,QAAI,UAAS,QAAQ,OAAO,UAAS,YAAY,CAAC,IAAI,MAAM;AAC1D,aAAO;AAET,UAAM;AAAA,MACJ;AAAA,MACA,YAAY,EAAE,OAAO,cAAc,UAAU;AAAA,MAC7C,WAAW;AAAA,QACT;AAEJ,QAAI;AAAW,YAAM,YAAY;AAEjC,WAAO,MAAM,cACX,eAAe,MAAM,aACrB,OAAO,KAAK,OAAO,UAAU,IAAI,OAAO,WAAW,QACnD,GAAG,SAAS,IAAI;AAAA;AAIpB,SAAO,OAAO;AAAA;",
6
6
  "names": []
7
7
  }
@@ -10,7 +10,7 @@ declare const _default: {
10
10
  isVariable(value?: any): value is Variable;
11
11
  getAstValues(value: any): Generator<AstType, void, unknown>;
12
12
  resolve(value: any, config?: Readonly<Partial<{
13
- nodes: Partial<Record<import("../types").NodeType, import("../types").Schema<Readonly<Partial<any>>, string>>>;
13
+ nodes: Partial<Record<import("../types").NodeType, import("../types").Schema<Partial<any>, string>>>;
14
14
  tags: Record<string, import("../types").Schema<Readonly<Partial<any>>, string>>;
15
15
  variables: Record<string, any>;
16
16
  functions: Record<string, import("../types").ConfigFunction>;
@@ -2,6 +2,7 @@ import type { Node, Value } from './types';
2
2
  declare type Options = {
3
3
  allowIndentation?: boolean;
4
4
  maxTagOpeningWidth?: number;
5
+ orderedListMode?: 'increment' | 'repeat';
5
6
  parent?: Node;
6
7
  indent?: number;
7
8
  };
@@ -1 +1 @@
1
- {"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/formatter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA4B,IAAI,EAAE,KAAK,EAAY,MAAM,SAAS,CAAC;AAE/E,aAAK,OAAO,GAAG;IACb,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAsdF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAIlE"}
1
+ {"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/formatter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA4B,IAAI,EAAE,KAAK,EAAY,MAAM,SAAS,CAAC;AAE/E,aAAK,OAAO,GAAG;IACb,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,eAAe,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAC;IACzC,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAmeF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAIlE"}
@@ -1,11 +1,15 @@
1
1
  import { RenderableTreeNodes } from '../../types';
2
- import type { createElement, Fragment, ReactNode } from 'react';
2
+ import type { createElement, ComponentType, Fragment, ReactNode } from 'react';
3
3
  declare type ReactShape = Readonly<{
4
4
  createElement: typeof createElement;
5
5
  Fragment: typeof Fragment;
6
6
  }>;
7
- export default function dynamic(node: RenderableTreeNodes, React: ReactShape, { components }?: {
8
- components?: {} | undefined;
9
- }): ReactNode;
7
+ declare type Component = ComponentType<unknown>;
8
+ declare function tagName(name: string, components: Record<string, Component> | ((string: string) => Component)): string | Component;
9
+ export declare type RenderOpts = {
10
+ components?: Record<string, Component> | ((string: string) => Component);
11
+ resolveTagName?: typeof tagName;
12
+ };
13
+ export default function dynamic(node: RenderableTreeNodes, React: ReactShape, { components, resolveTagName }?: RenderOpts): ReactNode;
10
14
  export {};
11
15
  //# sourceMappingURL=react.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../../../src/renderers/react/react.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAU,MAAM,aAAa,CAAC;AAE1D,OAAO,KAAK,EAAE,aAAa,EAAiB,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE/E,aAAK,UAAU,GAAG,QAAQ,CAAC;IACzB,aAAa,EAAE,OAAO,aAAa,CAAC;IACpC,QAAQ,EAAE,OAAO,QAAQ,CAAC;CAC3B,CAAC,CAAC;AAiBH,MAAM,CAAC,OAAO,UAAU,OAAO,CAC7B,IAAI,EAAE,mBAAmB,EACzB,KAAK,EAAE,UAAU,EACjB,EAAE,UAAe,EAAE;;CAAK,aAuCzB"}
1
+ {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../../../src/renderers/react/react.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAU,MAAM,aAAa,CAAC;AAE1D,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE/E,aAAK,UAAU,GAAG,QAAQ,CAAC;IACzB,aAAa,EAAE,OAAO,aAAa,CAAC;IACpC,QAAQ,EAAE,OAAO,QAAQ,CAAC;CAC3B,CAAC,CAAC;AAEH,aAAK,SAAS,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;AAExC,iBAAS,OAAO,CACd,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,KAAK,SAAS,CAAC,GACtE,MAAM,GAAG,SAAS,CAQpB;AAED,oBAAY,UAAU,GAAG;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC;IACzE,cAAc,CAAC,EAAE,OAAO,OAAO,CAAC;CACjC,CAAC;AACF,MAAM,CAAC,OAAO,UAAU,OAAO,CAC7B,IAAI,EAAE,mBAAmB,EACzB,KAAK,EAAE,UAAU,EACjB,EAAE,UAAe,EAAE,cAAwB,EAAE,GAAE,UAAe,aAuC/D"}
@@ -1,3 +1,9 @@
1
1
  import { RenderableTreeNodes } from '../../types';
2
- export default function reactStatic(node: RenderableTreeNodes): string;
2
+ import type { ComponentType } from 'react';
3
+ declare type Component = ComponentType<unknown>;
4
+ declare function tagName(name: string, components: Record<string, Component> | ((string: string) => Component)): string | Component;
5
+ export default function reactStatic(node: RenderableTreeNodes, { resolveTagName }?: {
6
+ resolveTagName?: typeof tagName;
7
+ }): string;
8
+ export {};
3
9
  //# sourceMappingURL=static.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../../../../src/renderers/react/static.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,mBAAmB,EAAE,MAAM,aAAa,CAAC;AA6DtE,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,mBAAmB,GAAG,MAAM,CAOrE"}
1
+ {"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../../../../src/renderers/react/static.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,aAAK,SAAS,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;AAExC,iBAAS,OAAO,CACd,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,KAAK,SAAS,CAAC,GACtE,MAAM,GAAG,SAAS,CAQpB;AA4CD,MAAM,CAAC,OAAO,UAAU,WAAW,CACjC,IAAI,EAAE,mBAAmB,EACzB,EAAE,cAAwB,EAAE,GAAE;IAAE,cAAc,CAAC,EAAE,OAAO,OAAO,CAAA;CAAO,GACrE,MAAM,CAYR"}
@@ -1,6 +1,6 @@
1
1
  declare const _default: {
2
2
  else: import("../types").Schema<Readonly<Partial<{
3
- nodes: Partial<Record<import("../types").NodeType, import("../types").Schema<Readonly<Partial<any>>, string>>>;
3
+ nodes: Partial<Record<import("../types").NodeType, import("../types").Schema<Partial<any>, string>>>;
4
4
  tags: Record<string, import("../types").Schema<Readonly<Partial<any>>, string>>;
5
5
  variables: Record<string, any>;
6
6
  functions: Record<string, import("../types").ConfigFunction>;
@@ -12,7 +12,7 @@ declare const _default: {
12
12
  } | undefined;
13
13
  }>>, string>;
14
14
  if: import("../types").Schema<Readonly<Partial<{
15
- nodes: Partial<Record<import("../types").NodeType, import("../types").Schema<Readonly<Partial<any>>, string>>>;
15
+ nodes: Partial<Record<import("../types").NodeType, import("../types").Schema<Partial<any>, string>>>;
16
16
  tags: Record<string, import("../types").Schema<Readonly<Partial<any>>, string>>;
17
17
  variables: Record<string, any>;
18
18
  functions: Record<string, import("../types").ConfigFunction>;
@@ -24,7 +24,7 @@ declare const _default: {
24
24
  } | undefined;
25
25
  }>>, string>;
26
26
  partial: import("../types").Schema<Readonly<Partial<{
27
- nodes: Partial<Record<import("../types").NodeType, import("../types").Schema<Readonly<Partial<any>>, string>>>;
27
+ nodes: Partial<Record<import("../types").NodeType, import("../types").Schema<Partial<any>, string>>>;
28
28
  tags: Record<string, import("../types").Schema<Readonly<Partial<any>>, string>>;
29
29
  variables: Record<string, any>;
30
30
  functions: Record<string, import("../types").ConfigFunction>;
@@ -36,7 +36,7 @@ declare const _default: {
36
36
  } | undefined;
37
37
  }>>, string>;
38
38
  slot: import("../types").Schema<Readonly<Partial<{
39
- nodes: Partial<Record<import("../types").NodeType, import("../types").Schema<Readonly<Partial<any>>, string>>>;
39
+ nodes: Partial<Record<import("../types").NodeType, import("../types").Schema<Partial<any>, string>>>;
40
40
  tags: Record<string, import("../types").Schema<Readonly<Partial<any>>, string>>;
41
41
  variables: Record<string, any>;
42
42
  functions: Record<string, import("../types").ConfigFunction>;
@@ -48,7 +48,7 @@ declare const _default: {
48
48
  } | undefined;
49
49
  }>>, string>;
50
50
  table: import("../types").Schema<Readonly<Partial<{
51
- nodes: Partial<Record<import("../types").NodeType, import("../types").Schema<Readonly<Partial<any>>, string>>>;
51
+ nodes: Partial<Record<import("../types").NodeType, import("../types").Schema<Partial<any>, string>>>;
52
52
  tags: Record<string, import("../types").Schema<Readonly<Partial<any>>, string>>;
53
53
  variables: Record<string, any>;
54
54
  functions: Record<string, import("../types").ConfigFunction>;
@@ -15,9 +15,9 @@ export declare type AttributeValue = {
15
15
  name: string;
16
16
  value: any;
17
17
  };
18
- export declare type Config = Readonly<ConfigType>;
19
- export declare type ConfigType = Partial<{
20
- nodes: Partial<Record<NodeType, Schema>>;
18
+ export declare type Config<R = string> = Readonly<ConfigType<R>>;
19
+ export declare type ConfigType<R = string> = Partial<{
20
+ nodes: Partial<Record<NodeType, Schema<ConfigType, R>>>;
21
21
  tags: Record<string, Schema>;
22
22
  variables: Record<string, any>;
23
23
  functions: Record<string, ConfigFunction>;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,GAA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,mBAAmB,CAAC,CAAC;IACpE,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5D,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,kBAAkB,EAAE,CAAC;CAC5D;AAED,oBAAY,eAAe,GAAG;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,UAAU,CAAC;IAC3D,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,CAAC;AAEF,oBAAY,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,KAAK,EAAE,eAAe,CAAC;CACxB,CAAC;AAEF,oBAAY,cAAc,GACtB,mBAAmB,GACnB,OAAO,MAAM,GACb,OAAO,MAAM,GACb,OAAO,OAAO,GACd,OAAO,MAAM,GACb,OAAO,KAAK,GACZ,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,OAAO,CAAC;AAEZ,oBAAY,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;AAErC,oBAAY,UAAU,GAAG;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC"}
package/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import Ast from './src/ast';
2
+ import Node from './src/ast/node';
2
3
  import format from './src/formatter';
3
4
  import functions from './src/functions';
4
5
  import parser from './src/parser';
@@ -13,7 +14,7 @@ import transforms from './src/transforms';
13
14
  import { parseTags } from './src/utils';
14
15
  import validator, { validateTree } from './src/validator';
15
16
 
16
- import type { Node, ParserArgs } from './src/types';
17
+ import type { ParserArgs } from './src/types';
17
18
  import type Token from 'markdown-it/lib/token';
18
19
  import type { Config, RenderableTreeNode, ValidateError } from './src/types';
19
20
 
@@ -113,6 +114,7 @@ export {
113
114
  transforms,
114
115
  renderers,
115
116
  Ast,
117
+ Node,
116
118
  Tag,
117
119
  Tokenizer,
118
120
  parseTags,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@markdoc/markdoc",
3
3
  "author": "Ryan Paul",
4
- "version": "0.3.5",
4
+ "version": "0.5.0",
5
5
  "description": "A text markup language for documentation",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -33,7 +33,8 @@
33
33
  "node": ">=14.7.0"
34
34
  },
35
35
  "optionalDependencies": {
36
- "@types/markdown-it": "12.2.3"
36
+ "@types/markdown-it": "12.2.3",
37
+ "@types/linkify-it": "^3.0.1"
37
38
  },
38
39
  "peerDependencies": {
39
40
  "@types/react": "*",
@@ -162,8 +162,10 @@ regular_word_with_underscores
162
162
  {% table %}
163
163
  - **[Link](https://example.com?q=()**
164
164
  - **[Link](https://example.com?q=\\()**
165
+ - **[Link](https://example.com?q=\\(\\))**
165
166
  - ![Image](https://example.com?q=()
166
167
  - ![Image](https://example.com?q=\\()
168
+ - ![Image](https://example.com?q=\\(\\))
167
169
  {% /table %}
168
170
 
169
171
  paragraph 1
@@ -504,6 +506,48 @@ Yes!
504
506
  stable(expected);
505
507
  });
506
508
 
509
+ it('ordered lists with incrementing numbers', () => {
510
+ const source = `
511
+ - foo
512
+ - bar
513
+ * baz
514
+ * qux
515
+
516
+
517
+ 7) foo
518
+ 1) bar
519
+ 1) baz
520
+ 3. foo
521
+ 1. bar
522
+ 1. baz
523
+ 1) foo
524
+ 4) bar
525
+ 9) baz
526
+ `;
527
+ const expected = `
528
+ - foo
529
+ - bar
530
+
531
+ * baz
532
+ * qux
533
+
534
+ 7) foo
535
+ 8) bar
536
+ 9) baz
537
+
538
+ 3. foo
539
+ 4. bar
540
+ 5. baz
541
+
542
+ 1) foo
543
+ 2) bar
544
+ 3) baz
545
+ `;
546
+ const options = { orderedListMode: 'increment' };
547
+ check(source, expected, options);
548
+ stable(expected, options);
549
+ });
550
+
507
551
  it('"loose" lists', () => {
508
552
  const source = `
509
553
  - a
@@ -799,4 +843,9 @@ ${'`'.repeat(4)}
799
843
  const d = diff(expected, b.trim());
800
844
  if (d && d.includes('Compared values have no visual difference.')) return;
801
845
  });
846
+
847
+ it('makes sure fences are formatted correctly if content has no ending newline', () => {
848
+ const node = new Markdoc.Ast.Node('fence', { content: 'foo' });
849
+ expect(format(node)).toEqual('```\nfoo\n```\n');
850
+ });
802
851
  });
package/src/formatter.ts CHANGED
@@ -5,6 +5,7 @@ import type { AttributeValue, Function, Node, Value, Variable } from './types';
5
5
  type Options = {
6
6
  allowIndentation?: boolean;
7
7
  maxTagOpeningWidth?: number;
8
+ orderedListMode?: 'increment' | 'repeat';
8
9
  parent?: Node;
9
10
  indent?: number;
10
11
  };
@@ -180,7 +181,7 @@ function* formatNode(n: Node, o: Options = {}) {
180
181
  yield ']';
181
182
  yield '(';
182
183
  yield* typeof n.attributes.src === 'string'
183
- ? escapeMarkdownCharacters(n.attributes.src, /[()]/)
184
+ ? escapeMarkdownCharacters(n.attributes.src, /[()]/g)
184
185
  : formatValue(n.attributes.src, no);
185
186
  if (n.attributes.title) {
186
187
  yield SPACE + `"${n.attributes.title}"`;
@@ -247,6 +248,7 @@ function* formatNode(n: Node, o: Options = {}) {
247
248
  .reduce(max, 0);
248
249
 
249
250
  const boundary = '`'.repeat(innerFenceLength ? innerFenceLength + 1 : 3);
251
+ const needsNlBeforeEndBoundary = !n.attributes.content.endsWith(NL);
250
252
 
251
253
  yield boundary;
252
254
  if (n.attributes.language) yield n.attributes.language;
@@ -255,6 +257,9 @@ function* formatNode(n: Node, o: Options = {}) {
255
257
  yield NL;
256
258
  yield indent;
257
259
  yield n.attributes.content.split(NL).join(NL + indent); // yield* formatChildren(n, no);
260
+ if (needsNlBeforeEndBoundary) {
261
+ yield NL;
262
+ }
258
263
  yield boundary;
259
264
  yield NL;
260
265
  break;
@@ -302,11 +307,20 @@ function* formatNode(n: Node, o: Options = {}) {
302
307
  );
303
308
 
304
309
  for (let i = 0; i < n.children.length; i++) {
305
- const prefix = n.attributes.ordered
306
- ? `${i === 0 ? n.attributes.start ?? '1' : '1'}${
307
- n.attributes.marker ?? OL
308
- }`
309
- : n.attributes.marker ?? UL;
310
+ const prefix = (() => {
311
+ if (!n.attributes.ordered) return n.attributes.marker ?? UL;
312
+
313
+ // Must be an ordered list now
314
+ let number = '1';
315
+ const startNumber = n.attributes.start ?? 1;
316
+ if (i === 0) number = startNumber.toString();
317
+
318
+ if (o.orderedListMode === 'increment') {
319
+ number = (parseInt(startNumber) + i).toString();
320
+ }
321
+
322
+ return `${number}${n.attributes.marker ?? OL}`;
323
+ })();
310
324
  let d = format(n.children[i], increment(no, prefix.length + 1));
311
325
 
312
326
  if (!isLoose || i === n.children.length - 1) {
@@ -171,6 +171,9 @@ function peg$parse(input, options) {
171
171
  var peg$c15 = '-';
172
172
  var peg$c16 = '"';
173
173
  var peg$c17 = '\\';
174
+ var peg$c18 = 'n';
175
+ var peg$c19 = 'r';
176
+ var peg$c20 = 't';
174
177
 
175
178
  var peg$r0 = /^[$@]/;
176
179
  var peg$r1 = /^[0-9]/;
@@ -300,7 +303,16 @@ function peg$parse(input, options) {
300
303
  var peg$f28 = function (value) {
301
304
  return value.join('');
302
305
  };
303
- var peg$f29 = function (sequence) {
306
+ var peg$f29 = function () {
307
+ return '\n';
308
+ };
309
+ var peg$f30 = function () {
310
+ return '\r';
311
+ };
312
+ var peg$f31 = function () {
313
+ return '\t';
314
+ };
315
+ var peg$f32 = function (sequence) {
304
316
  return sequence;
305
317
  };
306
318
 
@@ -1711,7 +1723,7 @@ function peg$parse(input, options) {
1711
1723
  }
1712
1724
 
1713
1725
  function peg$parseValueStringEscapes() {
1714
- var s0, s1, s2;
1726
+ var s0, s1, s2, s3;
1715
1727
 
1716
1728
  var rule$expects = function (expected) {
1717
1729
  if (peg$silentFails === 0) peg$expect(expected);
@@ -1738,10 +1750,52 @@ function peg$parse(input, options) {
1738
1750
  } else {
1739
1751
  s2 = peg$FAILED;
1740
1752
  }
1753
+ if (s2 === peg$FAILED) {
1754
+ s2 = peg$currPos;
1755
+ if (input.charCodeAt(peg$currPos) === 110) {
1756
+ s3 = peg$c18;
1757
+ peg$currPos++;
1758
+ } else {
1759
+ s3 = peg$FAILED;
1760
+ }
1761
+ if (s3 !== peg$FAILED) {
1762
+ peg$savedPos = s2;
1763
+ s3 = peg$f29();
1764
+ }
1765
+ s2 = s3;
1766
+ if (s2 === peg$FAILED) {
1767
+ s2 = peg$currPos;
1768
+ if (input.charCodeAt(peg$currPos) === 114) {
1769
+ s3 = peg$c19;
1770
+ peg$currPos++;
1771
+ } else {
1772
+ s3 = peg$FAILED;
1773
+ }
1774
+ if (s3 !== peg$FAILED) {
1775
+ peg$savedPos = s2;
1776
+ s3 = peg$f30();
1777
+ }
1778
+ s2 = s3;
1779
+ if (s2 === peg$FAILED) {
1780
+ s2 = peg$currPos;
1781
+ if (input.charCodeAt(peg$currPos) === 116) {
1782
+ s3 = peg$c20;
1783
+ peg$currPos++;
1784
+ } else {
1785
+ s3 = peg$FAILED;
1786
+ }
1787
+ if (s3 !== peg$FAILED) {
1788
+ peg$savedPos = s2;
1789
+ s3 = peg$f31();
1790
+ }
1791
+ s2 = s3;
1792
+ }
1793
+ }
1794
+ }
1741
1795
  }
1742
1796
  if (s2 !== peg$FAILED) {
1743
1797
  peg$savedPos = s0;
1744
- s0 = peg$f29(s2);
1798
+ s0 = peg$f32(s2);
1745
1799
  } else {
1746
1800
  peg$currPos = s0;
1747
1801
  s0 = peg$FAILED;
@@ -162,7 +162,13 @@ ValueStringChars =
162
162
  [^\0-\x1F\x22\x5C] / ValueStringEscapes
163
163
 
164
164
  ValueStringEscapes =
165
- '\\' sequence:('"' / '\\') { return sequence; }
165
+ '\\' sequence:(
166
+ '"' /
167
+ '\\' /
168
+ 'n' { return '\n' } /
169
+ 'r' { return '\r' } /
170
+ 't' { return '\t' }
171
+ ) { return sequence; }
166
172
 
167
173
  Identifier 'identifier' =
168
174
  $([a-zA-Z0-9_-]+)
@@ -61,6 +61,23 @@ describe('React dynamic renderer', function () {
61
61
  });
62
62
  });
63
63
 
64
+ it('rendering with a custom tag resolution function', function () {
65
+ function tagName(name, components) {
66
+ return components.Foo;
67
+ }
68
+ const components = { Foo: 'bar' };
69
+ const example = new Tag('Foo', undefined, ['test']);
70
+ const output = dynamic(example, React, {
71
+ components,
72
+ resolveTagName: tagName,
73
+ });
74
+
75
+ expect(output).toDeepEqualSubset({
76
+ name: 'bar',
77
+ children: ['test'],
78
+ });
79
+ });
80
+
64
81
  describe('attributes', function () {
65
82
  it('with an id attribute', function () {
66
83
  const example = {
@@ -167,6 +184,21 @@ describe('React static renderer', function () {
167
184
  });
168
185
  });
169
186
 
187
+ it('rendering with a custom tag resolution function', function () {
188
+ function tagName(name, components) {
189
+ return components.Foo;
190
+ }
191
+ const components = { Foo: 'bar' };
192
+ const example = new Tag('Foo', undefined, ['test']);
193
+ const code = renderStatic(example, { resolveTagName: tagName });
194
+ const output = eval(code)({ components });
195
+
196
+ expect(output).toDeepEqualSubset({
197
+ name: 'bar',
198
+ children: ['test'],
199
+ });
200
+ });
201
+
170
202
  describe('attributes', function () {
171
203
  it('with an id attribute', function () {
172
204
  const example = {
@@ -23,10 +23,14 @@ function tagName(
23
23
  : components[name];
24
24
  }
25
25
 
26
+ export type RenderOpts = {
27
+ components?: Record<string, Component> | ((string: string) => Component);
28
+ resolveTagName?: typeof tagName;
29
+ };
26
30
  export default function dynamic(
27
31
  node: RenderableTreeNodes,
28
32
  React: ReactShape,
29
- { components = {} } = {}
33
+ { components = {}, resolveTagName = tagName }: RenderOpts = {}
30
34
  ) {
31
35
  function deepRender(value: any): any {
32
36
  if (value == null || typeof value !== 'object') return value;
@@ -58,7 +62,7 @@ export default function dynamic(
58
62
  if (className) attrs.className = className;
59
63
 
60
64
  return React.createElement(
61
- tagName(name, components),
65
+ resolveTagName(name, components),
62
66
  Object.keys(attrs).length == 0 ? null : deepRender(attrs),
63
67
  ...children.map(render)
64
68
  );
@@ -60,10 +60,18 @@ function render(node: RenderableTreeNodes): string {
60
60
  ${renderArray(children)})`;
61
61
  }
62
62
 
63
- export default function reactStatic(node: RenderableTreeNodes): string {
63
+ export default function reactStatic(
64
+ node: RenderableTreeNodes,
65
+ { resolveTagName = tagName }: { resolveTagName?: typeof tagName } = {}
66
+ ): string {
67
+ // the resolveTagName function *must* be called tagName
68
+ // throw an error if it does not
69
+ if (resolveTagName.name !== 'tagName') {
70
+ throw new Error('resolveTagName must be named tagName');
71
+ }
64
72
  return `
65
73
  (({components = {}} = {}) => {
66
- ${tagName}
74
+ ${resolveTagName}
67
75
  return ${render(node)};
68
76
  })
69
77
  `;
package/src/schema.ts CHANGED
@@ -145,7 +145,7 @@ export const td: Schema = {
145
145
  export const th: Schema = {
146
146
  render: 'th',
147
147
  attributes: {
148
- width: { type: Number },
148
+ width: { type: String },
149
149
  align: { type: String },
150
150
  colspan: { type: Number, render: 'colSpan' },
151
151
  rowspan: { type: Number, render: 'rowSpan' },
package/src/types.ts CHANGED
@@ -20,10 +20,10 @@ export type AttributeValue = {
20
20
  value: any;
21
21
  };
22
22
 
23
- export type Config = Readonly<ConfigType>;
23
+ export type Config<R = string> = Readonly<ConfigType<R>>;
24
24
 
25
- export type ConfigType = Partial<{
26
- nodes: Partial<Record<NodeType, Schema>>;
25
+ export type ConfigType<R = string> = Partial<{
26
+ nodes: Partial<Record<NodeType, Schema<ConfigType, R>>>;
27
27
  tags: Record<string, Schema>;
28
28
  variables: Record<string, any>;
29
29
  functions: Record<string, ConfigFunction>;