Blocks
You can decorate markdown elements with a special syntax, Code Hike will transform them into objects and pass them as props to your components.
This lets you add structure to your markdown content that you can then use to render it in any way you want using React components.
The !mordor decoration at the start of the first heading tells Code Hike to group the content between this heading and the next one, the !isengard heading. That content group becomes a block object, that you can then use in your components.
Images, CodeBlocks, and Paragraphs
Besides headings, you can add the !
decoration to images, codeblocks, and paragraphs.
Lists
You can use !!
, instead of !
, to list all the blocks with the same decoration in an array.
The same applies to images, codeblocks, and paragraphs.
Nesting
You can use headigns with different levels to create nested blocks.
Schema
You can use zod schemas to validate the content coming from the MDX.
npm install zod
This has two benefits:
- Type-safe markdown: You'll see an error if the content doesn't match the schema
- Better tooling:You'll get autocompletion and type checking in your editor
Root level blocks
You can use decorated elements directly in the root of your Markdown/MDX file.
Component blocks
Coming soon
Examples
The code tooltip example shows how to use blocks at a component level.
The scrollycoding example shows how to use blocks for layout at a page level.