Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@sergey-vasiliev-dualboot
Copy link

@sergey-vasiliev-dualboot sergey-vasiliev-dualboot commented Nov 11, 2025

Summary

Adds a new MarkdownWidget for editing Markdown content in Django admin, using the EasyMDE editor with full integration into Unfold's design system.

Motivation

Provides an alternative to WysiwygWidget for users who work with the Markdown format. Useful for documentation, technical blogs, and any content requiring Markdown syntax.

Features

  • Plain text editor with monospace font (no markdown styling in editor)
  • Preview modes: side-by-side and fullscreen support
  • Theme integration: automatic dark/light theme switching using Unfold's color palette
  • Material Symbols icons: matching Unfold's design system
  • Toolbar buttons: bold, italic, strikethrough, headings (H1-H3), quote, code, lists, link, image, table, horizontal-rule, preview, side-by-side, fullscreen, guide
  • Storage: stores pure Markdown text in TextField (no HTML conversion)
  • Image insertion: via URL only (no upload)
  • Responsive: mobile-friendly with adaptive toolbar
  • No autosave: saves only on Django form submit
  • Max width: 4xl for normal view (matching other Unfold widgets)

Implementation

Core components

  • MarkdownWidget class in unfold/contrib/forms/widgets.py
  • HTML template with Material Symbols icons
  • JavaScript configuration (EasyMDE initialization)
  • Custom CSS with Unfold theme integration (no !important hacks)

Static assets

  • EasyMDE v2.18.0 (MIT License)
  • Custom styling matching Unfold design system
  • Material Symbols icon mappings

Testing

  • 4 new tests for MarkdownWidget (initialization, rendering, empty values, custom attrs)
  • 2 additional tests for WysiwygWidget and ArrayWidget
  • All 122 project tests passing ✅
  • Pre-commit hooks passing ✅

Documentation

  • Complete widget documentation in docs/widgets/markdown.md
  • Usage examples and comparison with WysiwygWidget
  • Markdown rendering guidelines

Test server

  • Example Article model with markdown fields
  • ArticleAdmin configuration
  • Migration file

Usage Example

settings.py

INSTALLED_APPS = [
    "unfold",
    "unfold.contrib.forms",
]

admin.py

from django.db import models
from unfold.admin import ModelAdmin
from unfold.contrib.forms.widgets import MarkdownWidget

@admin.register(Article)
class ArticleAdmin(ModelAdmin):
    formfield_overrides = {
        models.TextField: {"widget": MarkdownWidget}
    }

Breaking Changes

None. This is a new feature addition that does not modify existing functionality.

Checklist

  • Code follows project style guidelines (Ruff passing)
  • Pre-commit hooks passing
  • Tests added and passing (122/122)
  • Documentation added
  • Widget integrated into unfold.contrib.forms
  • Material Symbols icons used
  • Dark/light theme support
  • Responsive design implemented

Screenshots

Screenshot 2025-11-11 at 00 57 52 Screenshot 2025-11-11 at 00 57 42

Add full-featured Markdown editor widget using EasyMDE library.

Features:
- Plain text editor with monospace font (no markdown styling in editor)
- Side-by-side preview mode (manual toggle)
- Fullscreen support with side-by-side layout
- Full dark/light theme integration
- Material Symbols icons matching Unfold design
- Toolbar: bold, italic, strikethrough, headings (H1-H3), quote, code,
  lists, link, image, table, horizontal-rule, preview modes
- Max width 4xl for normal view
- No autosave (saves only on form submit)
- Image insertion via URL only
- Stores pure Markdown text in TextField

Usage:
    from unfold.contrib.forms.widgets import MarkdownWidget

    formfield_overrides = {
        models.TextField: {'widget': MarkdownWidget}
    }
@sergey-vasiliev-dualboot
Copy link
Author

Hi @lukasvinclav ! Could you please take a look at this pr?

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