@markdoc/markdoc 0.5.11 → 0.5.12

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
@@ -30,8 +30,9 @@ function dynamic(node, React, { components = {}, resolveTagName = tagName } = {}
30
30
  function render(node2) {
31
31
  if (Array.isArray(node2))
32
32
  return React.createElement(React.Fragment, null, ...node2.map(render));
33
- if (node2 === null || typeof node2 !== "object" || !Tag.isTag(node2))
33
+ if (node2 === null || typeof node2 !== "object" || !Tag.isTag(node2)) {
34
34
  return node2;
35
+ }
35
36
  const {
36
37
  name,
37
38
  attributes: { class: className, ...attrs } = {},
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<any>;\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,IAAqB,MAArB,MAGE;AAAA,EAWA,YACE,OAAO,OACP,aAAa,CAAC,GACd,WAAiC,CAAC,GAClC;AAdF,SAAS,WAAW;AAelB,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,WAAW;AAAA,EAClB;AAAA,EAhBA;AAAA,SAAO,QAAQ,CAAC,QAAyB;AACvC,aAAO,CAAC,EAAE,KAAK,aAAa;AAAA,IAC9B;AAAA;AAeF;;;ACbA,SAAS,QACP,MACA,YACoB;AACpB,SAAO,OAAO,SAAS,WACnB,OACA,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,YAAY,IAChC,OACA,sBAAsB,WACtB,WAAW,IAAI,IACf,WAAW,IAAI;AACrB;AAMe,SAAR,QACL,MACA,OACA,EAAE,aAAa,CAAC,GAAG,iBAAiB,QAAQ,IAAgB,CAAC,GAC7D;AACA,WAAS,WAAW,OAAiB;AACnC,QAAI,SAAS,QAAQ,OAAO,UAAU,SAAU,QAAO;AAEvD,QAAI,MAAM,QAAQ,KAAK,EAAG,QAAO,MAAM,IAAI,CAAC,SAAS,WAAW,IAAI,CAAC;AAErE,QAAI,MAAM,aAAa,MAAO,QAAO,OAAO,KAAK;AAEjD,QAAI,OAAO,UAAU,SAAU,QAAO;AAEtC,UAAM,SAAiC,CAAC;AACxC,eAAW,CAAC,GAAG,CAAC,KAAK,OAAO,QAAQ,KAAK,EAAG,QAAO,CAAC,IAAI,WAAW,CAAC;AACpE,WAAO;AAAA,EACT;AAEA,WAAS,OAAOA,OAAsC;AACpD,QAAI,MAAM,QAAQA,KAAI;AACpB,aAAO,MAAM,cAAc,MAAM,UAAU,MAAM,GAAGA,MAAK,IAAI,MAAM,CAAC;AAEtE,QAAIA,UAAS,QAAQ,OAAOA,UAAS,YAAY,CAAC,IAAI,MAAMA,KAAI;AAC9D,aAAOA;AAET,UAAM;AAAA,MACJ;AAAA,MACA,YAAY,EAAE,OAAO,WAAW,GAAG,MAAM,IAAI,CAAC;AAAA,MAC9C,WAAW,CAAC;AAAA,IACd,IAAIA;AAEJ,QAAI,UAAW,OAAM,YAAY;AAEjC,WAAO,MAAM;AAAA,MACX,eAAe,MAAM,UAAU;AAAA,MAC/B,OAAO,KAAK,KAAK,EAAE,UAAU,IAAI,OAAO,WAAW,KAAK;AAAA,MACxD,GAAG,SAAS,IAAI,MAAM;AAAA,IACxB;AAAA,EACF;AAEA,SAAO,OAAO,IAAI;AACpB;",
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<any>;\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 // Preserve passthrough values from custom transforms, including React elements.\n return node as ReactNode;\n }\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,IAAqB,MAArB,MAGE;AAAA,EAWA,YACE,OAAO,OACP,aAAa,CAAC,GACd,WAAiC,CAAC,GAClC;AAdF,SAAS,WAAW;AAelB,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,WAAW;AAAA,EAClB;AAAA,EAhBA;AAAA,SAAO,QAAQ,CAAC,QAAyB;AACvC,aAAO,CAAC,EAAE,KAAK,aAAa;AAAA,IAC9B;AAAA;AAeF;;;ACbA,SAAS,QACP,MACA,YACoB;AACpB,SAAO,OAAO,SAAS,WACnB,OACA,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,YAAY,IAC9B,OACA,sBAAsB,WACpB,WAAW,IAAI,IACf,WAAW,IAAI;AACzB;AAMe,SAAR,QACL,MACA,OACA,EAAE,aAAa,CAAC,GAAG,iBAAiB,QAAQ,IAAgB,CAAC,GAC7D;AACA,WAAS,WAAW,OAAiB;AACnC,QAAI,SAAS,QAAQ,OAAO,UAAU,SAAU,QAAO;AAEvD,QAAI,MAAM,QAAQ,KAAK,EAAG,QAAO,MAAM,IAAI,CAAC,SAAS,WAAW,IAAI,CAAC;AAErE,QAAI,MAAM,aAAa,MAAO,QAAO,OAAO,KAAK;AAEjD,QAAI,OAAO,UAAU,SAAU,QAAO;AAEtC,UAAM,SAAiC,CAAC;AACxC,eAAW,CAAC,GAAG,CAAC,KAAK,OAAO,QAAQ,KAAK,EAAG,QAAO,CAAC,IAAI,WAAW,CAAC;AACpE,WAAO;AAAA,EACT;AAEA,WAAS,OAAOA,OAAsC;AACpD,QAAI,MAAM,QAAQA,KAAI;AACpB,aAAO,MAAM,cAAc,MAAM,UAAU,MAAM,GAAGA,MAAK,IAAI,MAAM,CAAC;AAEtE,QAAIA,UAAS,QAAQ,OAAOA,UAAS,YAAY,CAAC,IAAI,MAAMA,KAAI,GAAG;AAEjE,aAAOA;AAAA,IACT;AAEA,UAAM;AAAA,MACJ;AAAA,MACA,YAAY,EAAE,OAAO,WAAW,GAAG,MAAM,IAAI,CAAC;AAAA,MAC9C,WAAW,CAAC;AAAA,IACd,IAAIA;AAEJ,QAAI,UAAW,OAAM,YAAY;AAEjC,WAAO,MAAM;AAAA,MACX,eAAe,MAAM,UAAU;AAAA,MAC/B,OAAO,KAAK,KAAK,EAAE,UAAU,IAAI,OAAO,WAAW,KAAK;AAAA,MACxD,GAAG,SAAS,IAAI,MAAM;AAAA,IACxB;AAAA,EACF;AAEA,SAAO,OAAO,IAAI;AACpB;",
6
6
  "names": ["node"]
7
7
  }
@@ -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,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE/E,KAAK,UAAU,GAAG,QAAQ,CAAC;IACzB,aAAa,EAAE,OAAO,aAAa,CAAC;IACpC,QAAQ,EAAE,OAAO,QAAQ,CAAC;CAC3B,CAAC,CAAC;AAEH,KAAK,SAAS,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;AAEpC,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,MAAM,MAAM,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
+ {"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,KAAK,UAAU,GAAG,QAAQ,CAAC;IACzB,aAAa,EAAE,OAAO,aAAa,CAAC;IACpC,QAAQ,EAAE,OAAO,QAAQ,CAAC;CAC3B,CAAC,CAAC;AAEH,KAAK,SAAS,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;AAEpC,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,MAAM,MAAM,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,aAyC/D"}
@@ -1,16 +1,25 @@
1
- import MarkdownIt from 'markdown-it';
2
1
  import type { Token } from '../types';
3
2
  export type LinkPluginOptions = {
4
3
  validatedProtocols: string[];
5
4
  };
5
+ export type TokenizerOptions = {
6
+ html?: boolean;
7
+ xhtmlOut?: boolean;
8
+ breaks?: boolean;
9
+ langPrefix?: string;
10
+ linkify?: boolean;
11
+ typographer?: boolean;
12
+ quotes?: string | string[];
13
+ highlight?: ((content: string, language: string, attributes: string) => string) | null;
14
+ maxNesting?: number;
15
+ allowIndentation?: boolean;
16
+ allowComments?: boolean;
17
+ allowLinkValidation?: boolean;
18
+ linkValidationOptions?: LinkPluginOptions;
19
+ };
6
20
  export default class Tokenizer {
7
21
  private parser;
8
- constructor(config?: MarkdownIt.MarkdownItOptions & {
9
- allowIndentation?: boolean;
10
- allowComments?: boolean;
11
- allowLinkValidation?: boolean;
12
- linkValidationOptions?: LinkPluginOptions;
13
- });
22
+ constructor(config?: TokenizerOptions);
14
23
  tokenize(content: string): Token[];
15
24
  }
16
25
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AAKrC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtC,MAAM,MAAM,iBAAiB,GAAG;IAAE,kBAAkB,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAEjE,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B,OAAO,CAAC,MAAM,CAAwB;gBAGpC,MAAM,GAAE,UAAU,CAAC,iBAAiB,GAAG;QACrC,gBAAgB,CAAC,EAAE,OAAO,CAAC;QAC3B,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB,mBAAmB,CAAC,EAAE,OAAO,CAAC;QAC9B,qBAAqB,CAAC,EAAE,iBAAiB,CAAC;KACtC;IAwBR,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE;CAGnC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtC,MAAM,MAAM,iBAAiB,GAAG;IAAE,kBAAkB,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAIjE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC3B,SAAS,CAAC,EACR,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,IAAI,CAAC;IAC7E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,qBAAqB,CAAC,EAAE,iBAAiB,CAAC;CAC3C,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B,OAAO,CAAC,MAAM,CAAmB;gBAErB,MAAM,GAAE,gBAAqB;IAuBzC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE;CAGnC"}
@@ -1,3 +1,3 @@
1
- import type MarkdownIt from 'markdown-it';
2
- export default function plugin(md: MarkdownIt.MarkdownIt): void;
1
+ import type { MarkdownIt } from 'markdown-it';
2
+ export default function plugin(md: MarkdownIt): void;
3
3
  //# sourceMappingURL=annotations.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../../../src/tokenizer/plugins/annotations.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,UAAU,MAAM,aAAa,CAAC;AA+I1C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,EAAE,EAAE,UAAU,CAAC,UAAU,QAMvD"}
1
+ {"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../../../src/tokenizer/plugins/annotations.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAEV,UAAU,EAKX,MAAM,aAAa,CAAC;AA4IrB,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,EAAE,EAAE,UAAU,QAM5C"}
@@ -1,3 +1,3 @@
1
- import type MarkdownIt from 'markdown-it';
2
- export default function plugin(md: MarkdownIt.MarkdownIt): void;
1
+ import type { MarkdownIt } from 'markdown-it';
2
+ export default function plugin(md: MarkdownIt): void;
3
3
  //# sourceMappingURL=comments.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"comments.d.ts","sourceRoot":"","sources":["../../../../src/tokenizer/plugins/comments.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,aAAa,CAAC;AA6C1C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,EAAE,EAAE,UAAU,CAAC,UAAU,QAGvD"}
1
+ {"version":3,"file":"comments.d.ts","sourceRoot":"","sources":["../../../../src/tokenizer/plugins/comments.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA2B,MAAM,aAAa,CAAC;AA6CvE,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,EAAE,EAAE,UAAU,QAG5C"}
@@ -1,3 +1,3 @@
1
- import type MarkdownIt from 'markdown-it';
2
- export default function plugin(md: MarkdownIt.MarkdownIt): void;
1
+ import type { MarkdownIt } from 'markdown-it';
2
+ export default function plugin(md: MarkdownIt): void;
3
3
  //# sourceMappingURL=frontmatter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"frontmatter.d.ts","sourceRoot":"","sources":["../../../../src/tokenizer/plugins/frontmatter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,aAAa,CAAC;AAmC1C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,EAAE,EAAE,UAAU,CAAC,UAAU,QAEvD"}
1
+ {"version":3,"file":"frontmatter.d.ts","sourceRoot":"","sources":["../../../../src/tokenizer/plugins/frontmatter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAmC1D,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,EAAE,EAAE,UAAU,QAE5C"}
@@ -1,4 +1,4 @@
1
- import type MarkdownIt from 'markdown-it';
2
- import { LinkPluginOptions } from '..';
3
- export default function plugin(md: MarkdownIt.MarkdownIt, options: LinkPluginOptions): void;
1
+ import type { MarkdownIt } from 'markdown-it';
2
+ import type { LinkPluginOptions } from '..';
3
+ export default function plugin(md: MarkdownIt, options: LinkPluginOptions): void;
4
4
  //# sourceMappingURL=link.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../../../src/tokenizer/plugins/link.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,aAAa,CAAC;AAI1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AAyBvC,MAAM,CAAC,OAAO,UAAU,MAAM,CAC5B,EAAE,EAAE,UAAU,CAAC,UAAU,EACzB,OAAO,EAAE,iBAAiB,QAG3B"}
1
+ {"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../../../src/tokenizer/plugins/link.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,aAAa,CAAC;AAIzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AAyB5C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,iBAAiB,QAExE"}
package/index.ts CHANGED
@@ -23,6 +23,7 @@ import type {
23
23
  } from './src/types';
24
24
 
25
25
  export * from './src/types';
26
+ export type { TokenizerOptions } from './src/tokenizer';
26
27
 
27
28
  const tokenizer = new Tokenizer();
28
29
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@markdoc/markdoc",
3
3
  "author": "Ryan Paul",
4
- "version": "0.5.11",
4
+ "version": "0.5.12",
5
5
  "description": "A text markup language for documentation",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -14,21 +14,6 @@
14
14
  ],
15
15
  "sideEffects": false,
16
16
  "license": "MIT",
17
- "scripts": {
18
- "test": "node -r ts-eager/register ./node_modules/.bin/jasmine",
19
- "marktest": "node -r ts-eager/register ${INSPECT:+--inspect-brk} spec/marktest/index.ts spec/marktest/tests.yaml",
20
- "prebuild": "npx patch-package",
21
- "build": "npm run build:common && npm run build:types",
22
- "build:common": "node build.js",
23
- "build:types": "tsc --emitDeclarationOnly --outDir dist",
24
- "lint": "eslint .",
25
- "grammar": "pegjs -o src/grammar/tag.js src/grammar/tag.pegjs",
26
- "postgrammar": "prettier --write src/grammar/tag.js",
27
- "prettier": "prettier --write index.ts src spec",
28
- "prettier:check": "prettier --check index.ts src spec",
29
- "type:check": "tsc --noEmit",
30
- "typedoc": "typedoc index.ts --includeVersion --readme none --excludePrivate --excludeExternals --excludeInternal --sort source-order --out types"
31
- },
32
17
  "engines": {
33
18
  "node": ">=14.7.0"
34
19
  },
@@ -37,39 +22,30 @@
37
22
  "react": "*"
38
23
  },
39
24
  "peerDependenciesMeta": {
40
- "@types/react": {
41
- "optional": true
42
- },
43
25
  "react": {
44
26
  "optional": true
45
27
  }
46
28
  },
47
29
  "devDependencies": {
48
- "@eslint/js": "^9.0.0",
49
- "@types/jasmine": "^5.0.0",
50
- "@types/node": "^18.0.0",
51
- "@types/react": "^17.0.0",
30
+ "@eslint/js": "^10.0.1",
31
+ "@types/jasmine": "^7.0.0",
32
+ "@types/node": "^24.19.2",
33
+ "@types/react": "^19.3.0",
52
34
  "deep-assert": "0.3.0",
53
- "diff": "^4.0.4",
54
- "esbuild": "0.25.0",
55
- "eslint": "10.1.0",
56
- "globals": "^16.0.0",
57
- "jasmine": "5.13.0",
58
- "jest-diff": "^28.1.3",
35
+ "diff": "^9.0.0",
36
+ "esbuild": "0.28.2",
37
+ "eslint": "10.14.0",
38
+ "globals": "^17.14.0",
39
+ "jasmine": "7.0.0",
40
+ "jest-diff": "^30.5.2",
59
41
  "markdown-it": "15.0.1",
60
- "patch-package": "^8.0.0",
61
42
  "pegjs": "0.11.0-master.b7b87ea",
62
- "prettier": "^2.5.1",
63
- "ts-eager": "2.0.2",
64
- "typedoc": "0.28.18",
65
- "typescript": "^5.0.0",
66
- "typescript-eslint": "^8.0.0",
67
- "yaml-js": "^0.2.3"
68
- },
69
- "overrides": {
70
- "ts-eager": {
71
- "esbuild": "0.25.0"
72
- }
43
+ "prettier": "^3.9.10",
44
+ "tsx": "4.23.15",
45
+ "typedoc": "0.28.20",
46
+ "typescript": "^6.0.3",
47
+ "typescript-eslint": "^8.72.1",
48
+ "yaml-js": "^0.3.1"
73
49
  },
74
50
  "repository": {
75
51
  "type": "git",
@@ -78,5 +54,19 @@
78
54
  "bugs": {
79
55
  "url": "https://github.com/markdoc/markdoc/issues"
80
56
  },
81
- "homepage": "https://markdoc.dev"
82
- }
57
+ "homepage": "https://markdoc.dev",
58
+ "scripts": {
59
+ "test": "node --import tsx ./node_modules/jasmine/bin/jasmine.js",
60
+ "test:types": "node spec/types/check.mjs",
61
+ "marktest": "node --import tsx ${INSPECT:+--inspect-brk} spec/marktest/index.ts spec/marktest/tests.yaml",
62
+ "build": "pnpm run build:common && pnpm run build:types",
63
+ "build:common": "node build.js",
64
+ "build:types": "tsc --emitDeclarationOnly --outDir dist",
65
+ "lint": "eslint .",
66
+ "grammar": "pegjs -o src/grammar/tag.js src/grammar/tag.pegjs && prettier --write src/grammar/tag.js",
67
+ "prettier": "prettier --write index.ts src spec",
68
+ "prettier:check": "prettier --check index.ts src spec",
69
+ "type:check": "tsc --noEmit",
70
+ "typedoc": "typedoc index.ts --includeVersion --readme none --excludePrivate --excludeExternals --excludeInternal --sort source-order --out types"
71
+ }
72
+ }
@@ -1,9 +1,7 @@
1
- import type MarkdownIt from 'markdown-it';
1
+ import type { Token } from 'markdown-it';
2
2
  import type AstVariable from '../ast/variable';
3
3
  import type AstFunction from '../ast/function';
4
4
 
5
- type Token = MarkdownIt.Token;
6
-
7
5
  type astTypes = {
8
6
  Variable?: typeof AstVariable;
9
7
  Function?: typeof AstFunction;
@@ -17,10 +17,10 @@ function tagName(
17
17
  return typeof name !== 'string'
18
18
  ? name // This can be an object, e.g. when React.forwardRef is used
19
19
  : name[0] !== name[0].toUpperCase()
20
- ? name
21
- : components instanceof Function
22
- ? components(name)
23
- : components[name];
20
+ ? name
21
+ : components instanceof Function
22
+ ? components(name)
23
+ : components[name];
24
24
  }
25
25
 
26
26
  export type RenderOpts = {
@@ -50,8 +50,10 @@ export default function dynamic(
50
50
  if (Array.isArray(node))
51
51
  return React.createElement(React.Fragment, null, ...node.map(render));
52
52
 
53
- if (node === null || typeof node !== 'object' || !Tag.isTag(node))
54
- return node;
53
+ if (node === null || typeof node !== 'object' || !Tag.isTag(node)) {
54
+ // Preserve passthrough values from custom transforms, including React elements.
55
+ return node as ReactNode;
56
+ }
55
57
 
56
58
  const {
57
59
  name,
@@ -12,10 +12,10 @@ function tagName(
12
12
  return typeof name !== 'string'
13
13
  ? 'Fragment'
14
14
  : name[0] !== name[0].toUpperCase()
15
- ? name
16
- : components instanceof Function
17
- ? components(name)
18
- : components[name];
15
+ ? name
16
+ : components instanceof Function
17
+ ? components(name)
18
+ : components[name];
19
19
  }
20
20
 
21
21
  function renderArray(children: RenderableTreeNode[]): string {
package/src/tag.ts CHANGED
@@ -2,7 +2,7 @@ import type { RenderableTreeNode } from './types';
2
2
 
3
3
  export default class Tag<
4
4
  N extends string = string,
5
- A extends Record<string, any> = Record<string, any>
5
+ A extends Record<string, any> = Record<string, any>,
6
6
  > {
7
7
  readonly $$mdtype = 'Tag' as const;
8
8
 
@@ -1,4 +1,5 @@
1
1
  import MarkdownIt from 'markdown-it';
2
+ import type { MarkdownIt as MarkdownItParser } from 'markdown-it';
2
3
  import annotations from './plugins/annotations';
3
4
  import frontmatter from './plugins/frontmatter';
4
5
  import comments from './plugins/comments';
@@ -7,17 +8,29 @@ import type { Token } from '../types';
7
8
 
8
9
  export type LinkPluginOptions = { validatedProtocols: string[] };
9
10
 
11
+ // Keep public options independent of the bundled parser's type dependencies.
12
+ // spec/types/tokenizer-options.ts checks compatibility with markdown-it.
13
+ export type TokenizerOptions = {
14
+ html?: boolean;
15
+ xhtmlOut?: boolean;
16
+ breaks?: boolean;
17
+ langPrefix?: string;
18
+ linkify?: boolean;
19
+ typographer?: boolean;
20
+ quotes?: string | string[];
21
+ highlight?:
22
+ ((content: string, language: string, attributes: string) => string) | null;
23
+ maxNesting?: number;
24
+ allowIndentation?: boolean;
25
+ allowComments?: boolean;
26
+ allowLinkValidation?: boolean;
27
+ linkValidationOptions?: LinkPluginOptions;
28
+ };
29
+
10
30
  export default class Tokenizer {
11
- private parser: MarkdownIt.MarkdownIt;
31
+ private parser: MarkdownItParser;
12
32
 
13
- constructor(
14
- config: MarkdownIt.MarkdownItOptions & {
15
- allowIndentation?: boolean;
16
- allowComments?: boolean;
17
- allowLinkValidation?: boolean;
18
- linkValidationOptions?: LinkPluginOptions;
19
- } = {}
20
- ) {
33
+ constructor(config: TokenizerOptions = {}) {
21
34
  this.parser = new MarkdownIt(config);
22
35
  this.parser.use(annotations);
23
36
  this.parser.use(frontmatter);
@@ -4,13 +4,17 @@ import Variable from '../../ast/variable';
4
4
  import Function from '../../ast/function';
5
5
 
6
6
  import type { AttributeValue, Token } from '../../types';
7
- import type MarkdownIt from 'markdown-it';
7
+ import type {
8
+ Delimiter,
9
+ MarkdownIt,
10
+ StateBlock,
11
+ StateInline,
12
+ StateCore,
13
+ Token as MarkdownItToken,
14
+ } from 'markdown-it';
8
15
 
9
- type StateBlock = MarkdownIt.StateBlock;
10
- type StateInline = MarkdownIt.StateInline;
11
- type StateCore = MarkdownIt.StateCore;
12
16
  type StateWithDelimiters = (StateBlock | StateInline) & {
13
- delimiters?: MarkdownIt.Delimiter[];
17
+ delimiters?: Delimiter[];
14
18
  };
15
19
  // FenceToken combines markdown-it and Markdoc token types, using the more
16
20
  // specific markdown-it type for fields it defines (e.g. `info`, `content`,
@@ -18,7 +22,7 @@ type StateWithDelimiters = (StateBlock | StateInline) & {
18
22
  // (`errors`, `children`, `meta`). Previously we used module augmentation
19
23
  // (global.d.ts) to extend markdown-it's Token directly, but markdown-it 15
20
24
  // no longer exposes an augmentable module path for it.
21
- type FenceToken = Omit<MarkdownIt.Token, 'children' | 'meta'> &
25
+ type FenceToken = Omit<MarkdownItToken, 'children' | 'meta'> &
22
26
  Pick<Token, 'errors' | 'children' | 'meta'>;
23
27
 
24
28
  function createToken(
@@ -147,7 +151,7 @@ function core(state: StateCore) {
147
151
  }
148
152
  }
149
153
 
150
- export default function plugin(md: MarkdownIt.MarkdownIt /* options */) {
154
+ export default function plugin(md: MarkdownIt /* options */) {
151
155
  md.block.ruler.before('paragraph', 'annotations', block, {
152
156
  alt: ['paragraph', 'blockquote'],
153
157
  });
@@ -1,10 +1,10 @@
1
- import type MarkdownIt from 'markdown-it';
1
+ import type { MarkdownIt, StateBlock, StateInline } from 'markdown-it';
2
2
 
3
3
  const OPEN = '<!--';
4
4
  const CLOSE = '-->';
5
5
 
6
6
  function block(
7
- state: MarkdownIt.StateBlock,
7
+ state: StateBlock,
8
8
  startLine: number,
9
9
  endLine: number,
10
10
  silent: boolean
@@ -27,7 +27,7 @@ function block(
27
27
  return true;
28
28
  }
29
29
 
30
- function inline(state: MarkdownIt.StateInline, silent: boolean): boolean {
30
+ function inline(state: StateInline, silent: boolean): boolean {
31
31
  if (!state.src.startsWith(OPEN, state.pos)) return false;
32
32
 
33
33
  const close = state.src.indexOf(CLOSE, state.pos);
@@ -43,7 +43,7 @@ function inline(state: MarkdownIt.StateInline, silent: boolean): boolean {
43
43
  return true;
44
44
  }
45
45
 
46
- export default function plugin(md: MarkdownIt.MarkdownIt) {
46
+ export default function plugin(md: MarkdownIt) {
47
47
  md.block.ruler.before('table', 'comment', block, { alt: ['paragraph'] });
48
48
  md.inline.ruler.push('comment', inline);
49
49
  }
@@ -1,18 +1,18 @@
1
- import type MarkdownIt from 'markdown-it';
1
+ import type { MarkdownIt, StateBlock } from 'markdown-it';
2
2
 
3
3
  const fence = '---';
4
4
 
5
- function getLine(state: MarkdownIt.StateBlock, n: number) {
5
+ function getLine(state: StateBlock, n: number) {
6
6
  return state.src.slice(state.bMarks[n], state.eMarks[n]).trim();
7
7
  }
8
8
 
9
- function findClose(state: MarkdownIt.StateBlock, endLine: number) {
9
+ function findClose(state: StateBlock, endLine: number) {
10
10
  for (let line = 1; line < endLine; line++)
11
11
  if (getLine(state, line) === fence) return line;
12
12
  }
13
13
 
14
14
  function block(
15
- state: MarkdownIt.StateBlock,
15
+ state: StateBlock,
16
16
  startLine: number,
17
17
  endLine: number,
18
18
  silent: boolean
@@ -33,6 +33,6 @@ function block(
33
33
  return true;
34
34
  }
35
35
 
36
- export default function plugin(md: MarkdownIt.MarkdownIt /* options */) {
36
+ export default function plugin(md: MarkdownIt /* options */) {
37
37
  md.block.ruler.before('hr', 'frontmatter', block);
38
38
  }
@@ -1,8 +1,8 @@
1
- import type MarkdownIt from 'markdown-it';
1
+ import type { MarkdownIt, StateCore } from 'markdown-it';
2
2
  import type { Token } from '../../types';
3
3
 
4
4
  import { containsMarkdocTagInUrl } from '../../utils';
5
- import { LinkPluginOptions } from '..';
5
+ import type { LinkPluginOptions } from '..';
6
6
 
7
7
  const INVALID_HREF_MESSAGE =
8
8
  "The 'href' format cannot contain Markdoc tag or variable. URLs must be static strings.";
@@ -16,7 +16,7 @@ function pushHrefError(token: Token) {
16
16
  });
17
17
  }
18
18
 
19
- function core(state: MarkdownIt.StateCore, options: LinkPluginOptions) {
19
+ function core(state: StateCore, options: LinkPluginOptions) {
20
20
  let token: Token;
21
21
  for (token of state.tokens) {
22
22
  if (token.type !== 'inline' || typeof token.content !== 'string') continue;
@@ -27,9 +27,6 @@ function core(state: MarkdownIt.StateCore, options: LinkPluginOptions) {
27
27
  }
28
28
  }
29
29
 
30
- export default function plugin(
31
- md: MarkdownIt.MarkdownIt,
32
- options: LinkPluginOptions
33
- ) {
30
+ export default function plugin(md: MarkdownIt, options: LinkPluginOptions) {
34
31
  md.core.ruler.push('link_url_validation', (state) => core(state, options));
35
32
  }
package/src/validator.ts CHANGED
@@ -36,8 +36,8 @@ export function validateType(
36
36
  return !schema?.returns
37
37
  ? true
38
38
  : Array.isArray(schema.returns)
39
- ? schema.returns.find((t) => t === type) !== undefined
40
- : schema.returns === type;
39
+ ? schema.returns.find((t) => t === type) !== undefined
40
+ : schema.returns === type;
41
41
  }
42
42
 
43
43
  if (Ast.isAst(value)) return true;
@@ -1,136 +0,0 @@
1
- import { promises as fs } from 'fs';
2
- import { resolve } from 'path';
3
- import { diffJson, diffChars } from 'diff';
4
- import yaml from 'yaml-js';
5
-
6
- import markdoc from '../../index';
7
- import React from './react-shim';
8
-
9
- class Loader extends yaml.loader.Loader {
10
- construct_mapping(node) {
11
- return {
12
- ...super.construct_mapping(node),
13
- $$lines: {
14
- start: node.start_mark.line,
15
- end: node.end_mark.line,
16
- },
17
- };
18
- }
19
- }
20
-
21
- const tokenizer = new markdoc.Tokenizer({
22
- allowIndentation: true,
23
- allowComments: true,
24
- });
25
-
26
- function parse(content: string, slots?: boolean, file?: string) {
27
- const tokens = tokenizer.tokenize(content);
28
- return markdoc.parse(tokens, { file, slots });
29
- }
30
-
31
- function stripLines(object) {
32
- const removeLines = (key, value) => (key === '$$lines' ? undefined : value);
33
- return JSON.parse(JSON.stringify(object, removeLines));
34
- }
35
-
36
- function render(code, config, dynamic) {
37
- const partials = {};
38
- for (const [file, content] of Object.entries(config.partials ?? {}))
39
- partials[file] = parse(content as string, false, file);
40
-
41
- const { react, reactStatic } = markdoc.renderers;
42
- const transformed = markdoc.transform(code, { ...config, partials });
43
- return dynamic ? react(transformed, React) : eval(reactStatic(transformed));
44
- }
45
-
46
- function checkMatch(diffs) {
47
- return diffs.find((diff) => diff.added || diff.removed);
48
- }
49
-
50
- function run(
51
- { code = null, renderer = 'react', config = {}, expected = undefined } = {},
52
- dynamic
53
- ) {
54
- if (renderer === 'html') {
55
- const transformed = markdoc.transform(code, config);
56
- const output = markdoc.renderers.html(transformed);
57
- const diff = diffChars((expected || '').trim(), (output || '').trim());
58
- return checkMatch(diff) ? diff : false;
59
- }
60
-
61
- const output = render(code, config, dynamic) || {};
62
- const diff = diffJson(expected || {}, output.children || []);
63
- return checkMatch(diff) ? diff : false;
64
- }
65
-
66
- function formatter(filename, { $$lines: lines, name, code }, diff) {
67
- const prettyDiff = diff
68
- .flatMap((part) => [
69
- part.added ? '\x1b[32m' : part.removed ? '\x1b[31m' : '\x1b[0m',
70
- part.added || part.removed ? part.value.replace(/ /g, '⎵') : part.value,
71
- ])
72
- .join('');
73
-
74
- return [
75
- `\x1b[31mFAILED:\x1b[0m ${filename}:${lines.start}`,
76
- name,
77
- code,
78
- prettyDiff,
79
- ].join('\n\n');
80
- }
81
-
82
- function formatValidation(filename, test, validation) {
83
- const { $$lines: lines, name, code } = test;
84
-
85
- let output = '';
86
- for (const {
87
- lines,
88
- error: { message },
89
- } of validation)
90
- output += `${lines ? lines[0] : '?'}:${message}\n`;
91
-
92
- return [
93
- `\x1b[31mINVALID:\x1b[0m ${filename}:${lines.start}`,
94
- name,
95
- code,
96
- output,
97
- ].join('\n\n');
98
- }
99
-
100
- (async () => {
101
- const [filename, line] = process.argv.slice(2).join('').split(':');
102
- const path = resolve(filename);
103
- const file = await fs.readFile(path);
104
- const tests = yaml.load(file, Loader);
105
-
106
- let exitCode = 0;
107
- for (const test of tests) {
108
- const code = parse(test.code || '', test.slots);
109
-
110
- const { start, end } = test.$$lines;
111
- if (line && (Number(line) - 1 < start || Number(line) - 1 > end)) continue;
112
-
113
- const validation = markdoc.validate(code, test.config);
114
-
115
- let result;
116
- if (test.expectedError) {
117
- const output = validation.map((v) => v.error.message).join('\n');
118
- const diff = diffChars(
119
- (test.expectedError || '').trim(),
120
- (output || '').trim()
121
- );
122
-
123
- result = checkMatch(diff) ? diff : false;
124
- } else {
125
- if (validation.length && test.validation != false)
126
- console.log(formatValidation(path, test, validation));
127
-
128
- result = run({ ...stripLines(test), code }, true);
129
- }
130
-
131
- if (!result) continue;
132
- console.log(formatter(path, test, result));
133
- exitCode = 1;
134
- }
135
- process.exit(exitCode);
136
- })();