PhaultLines

Validating Markdoc attribute values with Zod

In a React application written in TypeScript, the language’s type system is the first line of defense against type errors in component props. In Markdoc, where content is decoupled from rendering logic and can’t take advantage of TypeScript types, the schema-based validation system plays an important role in bridging the gap between declarative tag definitions and typed React components. The Markdoc validator ensures that tag attribute values in a document match the types declared in the corresponding schema.

Continue Reading ›

Accessing parent nodes in a Markdoc validation function

A recent Markdoc release introduced a new feature that makes it possible for validation functions to access the parents of the current node. This feature is useful for writing custom validation logic that analyzes document structure or enforces rules based on a node’s position in the hierarchy. For example, you might want to impose restrictions on where an image can be nested in a document, prohibiting the use of images in specific tags like callouts and asides.

Continue Reading ›