Backend support for Markdown descriptions and migration from bleach to nh3#2140
Open
Frenzy-code wants to merge 8 commits intowger-project:masterfrom
Open
Backend support for Markdown descriptions and migration from bleach to nh3#2140Frenzy-code wants to merge 8 commits intowger-project:masterfrom
Frenzy-code wants to merge 8 commits intowger-project:masterfrom
Conversation
- Remove dependency (deprecated). - Add and dependencies. - Add field to ExerciseTranslation model. - Update API serializers to handle markdown input. - Create for rendering and sanitization.
- Added `migrate_descriptions_to_markdown` command to convert legacy `description` (HTML) content to `description_source` (Markdown) using `markdownify`. - Migrated to add the `description_source` field to `ExerciseTranslation` and `HistoricalTranslation`. - Updated `ExerciseTranslation.save()` logic to handle both Markdown source input AND legacy raw HTML input, ensuring the strict `nh3` sanitization is applied in both cases to maintain data integrity. - Adjusted test expectations (`test_command_migrate_descriptions`, `test_patch_clean_html`) to correctly reflect the strict CommonMark rendering (`<strong>`, `<em>`) and the secure content-stripping behavior of the `nh3` sanitizer. Now the backend completely replaced `bleach` and adopted Markdown descriptions.
Member
|
NB: I'm planning to finish implementing the UI for the trophies, doing a release, and then merging this for the next one |
# Conflicts: # pyproject.toml
This make the migration happen automatically, and makes sure the exercises don't end up in a half migrated step or so.
rolandgeider
approved these changes
Feb 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed Changes
description_sourcefield to theExerciseTranslationmodel to store raw Markdown input.ExerciseTranslation.save()to render Markdown todescription. So now New Markdown input is stored indescription_sourceand automatically rendered to HTML for the legacydescriptionfield. This way it preserves compatibility while also sanitizing all HTML inputs usingnh3library.migrate_descriptions_to_markdownmanagement command to convert existing HTML descriptions to Markdown usingmarkdownify.ExerciseTranslationSerializerto expose the newdescription_sourcefield for editing, while keepingdescriptionread-only for backward compatibility with existing clients.wger/wger/utils/markdown.pyto modularly handle rendering logic only for ('b' / 'strong', 'em' / 'i', 'ul', 'ol', 'li', 'p').Related Issue(s)
Closes #1240 (but not the Flutter and React sub-issues)
Please check that the PR fulfills these requirements
ruff format && isort .)Other questions
(e.g. database migration, deployment changes)?
Yes. After applying standard django migrations (
python manage.py migrate), administrators should run the following command to generate Markdown sources for existing exercises:This command has a
--dry-runflag, which is recommended for testing the conversion before making permanent changes: