Skip to content

Conversation

@Bryan0324
Copy link

@Bryan0324 Bryan0324 commented Jan 6, 2026

What does it do?

This pull request adds support for MDX (.mdx files) rendering to Hexo, enabling users to write blog posts and pages using MDX - a powerful combination of Markdown and JSX.

Features:

  • Markdown Support: Full CommonMark markdown syntax support for content creation
  • JSX Components: Embed and use React/Preact components directly in markdown
  • JavaScript Expressions: Evaluate JavaScript expressions dynamically within content
  • Custom Components: Define and use custom reusable components
  • Inline Styles: Support for inline CSS styling with JavaScript objects
  • Error Handling: Comprehensive error messages with file path information for debugging

Implementation:

  • Uses @mdx-js/mdx v3.1.1 for MDX compilation
  • Preact for lightweight JSX rendering
  • Async rendering for non-blocking operations
  • Nunjucks disabled for MDX files to prevent conflicts
  • Registered as .mdx file extension handler

Example Usage:

Users can now create source/_posts/my-post.mdx with content like:

# Welcome to MDX

This is **markdown** with <span style={{color: 'red'}}>JSX</span>!

export const Button = ({text}) => (
  <button className="btn">{text}</button>
);

The answer is: {2 + 2 * 10}

<Button text="Click me!" />

Screenshots

N/A - Code feature (no UI changes)

Pull request tasks

  • Add test cases for the changes.
  • Passed the CI test.

@github-actions
Copy link

github-actions bot commented Jan 6, 2026

How to test

git clone -b new_feature https://github.com/Bryan0324/hexo.git
cd hexo
npm install
npm test

@Bryan0324 Bryan0324 changed the title New feature chore: Add MDX renderer for Markdown with JSX support Jan 6, 2026
Copy link
Member

@D-Sketon D-Sketon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be independently implemented as a separate npm package, similar to hexo-renderer-marked.

@Bryan0324
Copy link
Author

Is it okay if I submit a similar PR to hexo-renderer-marked, or should I create a new package?

@D-Sketon
Copy link
Member

D-Sketon commented Jan 6, 2026

Each renderer should focus on rendering just one type of file and not take on too many responsibilities. To make this work better, it's a good idea to create a separate package. For example, you could build your own dedicated renderer called hexo-renderer-mdx.

@Bryan0324
Copy link
Author

Thanks for the clarification! That makes sense — I’ll create a separate package for this.

@Bryan0324 Bryan0324 closed this Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants