Skip to content

Add image processing support from hexo-renderer-markdown-it#39

Open
PekingSpades wants to merge 1 commit intoCHENXCHEN:masterfrom
PekingSpades:master
Open

Add image processing support from hexo-renderer-markdown-it#39
PekingSpades wants to merge 1 commit intoCHENXCHEN:masterfrom
PekingSpades:master

Conversation

@PekingSpades
Copy link
Copy Markdown

feat: Add image processing support from hexo-renderer-markdown-it

Description

This PR introduces enhanced image processing capabilities by porting the image handling logic from the official hexo-renderer-markdown-it plugin. This enhancement allows for better integration with Hexo's native image handling features while maintaining backward compatibility.

Changes

1. New Image Processing Module (lib/image.js)

  • Added a dedicated image processing module that handles:
    • Lazy loading support: Automatically adds loading="lazy" attribute when enabled
    • Path resolution: Properly resolves relative image paths in posts
    • Post asset handling: Correctly processes images stored in post asset folders
    • URL generation: Utilizes Hexo's url_for helper for proper URL generation

2. Renderer Architecture Refactoring

  • Converted the renderer from a function export to a class-based architecture
  • This change enables:
    • Better access to Hexo instance throughout the rendering process
    • Support for local plugins that require Hexo context
    • More flexible plugin initialization

3. Enhanced Plugin System

  • Introduced support for local plugins (stored in lib/ directory)
  • Plugins now receive the Hexo instance through options, enabling:
    • Access to Hexo configuration
    • Use of Hexo models and helpers
    • Better integration with the Hexo ecosystem

Benefits

  1. Improved Image Handling: Users can now benefit from the same robust image processing available in the official hexo-renderer-markdown-it
  2. Better Asset Management: Proper support for post asset folders, making it easier to organize images alongside posts
  3. Performance Optimization: Optional lazy loading for images improves page load performance
  4. Enhanced Compatibility: Maintains full backward compatibility while adding new features

Configuration

The image processing feature works with existing configuration options and requires no additional setup. Users can optionally configure:

markdown_it_plus:
  plugins:
    - plugin:
        name: image
        enable: true
        options:
          lazyload: true        # Enable lazy loading
          prependRoot: true     # Prepend root path to image URLs
          postAsset: true       # Enable post asset folder support

Testing

  • Tested with various image path formats (relative, absolute, external URLs)
  • Verified compatibility with existing plugins
  • Confirmed that backward compatibility is maintained for current users

Related Issues

This enhancement addresses common user requests for better image handling in Hexo posts, particularly for users migrating from or familiar with the official hexo-renderer-markdown-it plugin.

Breaking Changes

None. This PR maintains full backward compatibility with existing configurations and usage patterns.

Checklist

  • Code follows the project's coding style
  • Changes have been tested locally
  • No breaking changes introduced
  • Dependencies updated in package.json and lock files

Additional Notes

This feature brings hexo-renderer-markdown-it-plus closer to feature parity with the official renderer while maintaining the additional plugins and flexibility that make this fork valuable to the community.

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.

1 participant