Skip to content

Configuration

This table outlines the various options you can pass to Markdoc.transform. Each option adjusts how a document is transformed and rendered.

KeyTypeDescription
nodes{ [nodeType: NodeType]: Schema }Register custom nodes in your schema
tags{ [tagName: string]: Schema }Register custom tags in your schema
variables{ [variableName: string]: any }Register variables to use in your document
functions{ [functionName: string]: ConfigFunction }Register custom functions to use in your document
partials{ [partialPath: string]: Ast.Node }Register reusable pieces of content to used by the partial tag

Full example

Here's an example of what a Markdoc config would look like:

const config = {
  nodes: {
    heading: {
      render: 'Heading',
      attributes: {
        id: { type: String },
        level: { type: Number }
      }
    }
  },
  tags: {
    callout: {
      render: 'Callout',
      attributes: {
        title: {
          type: String
        }
      }
    }
  },
  variables: {
    name: 'Dr. Mark',
    frontmatter: {
      title: 'Configuration options'
    }
  },
  functions: {
    includes: {
      transform(parameters, config) {
        const [array, value] = Object.values(parameters);

        return Array.isArray(array) ? array.includes(value) : false;
      }
    }
  },
  partials: {
    'header.md': Markdoc.parse(`# My header`)
  }
};

const content = Markdoc.transform(ast, config);