Deliver stored exercise HTML on the catalog API.
Deploy Development / deploy (push) Successful in 52s
Test Suite / pytest-backend (push) Successful in 52s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 16s
Test Suite / k6 /health Baseline (push) Successful in 35s
Test Suite / playwright-tests (push) Failing after 7m43s

The receiving application needs paragraphs, line breaks, lists and emphasis as stored in Shinkan. The catalog now returns that HTML and marks the text format, while titles and short variant descriptions stay plain text.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-11-23 22:12:14 +01:00
1 parent 68ae82a5e5
commit 5ff0cd43ee
3 files changed
+54 -10

No files matched your search

+23 -8
View File
@@ -15,6 +15,8 @@ from datetime import datetime, timezone
from html import unescape
from typing import Any, Iterable, Optional
from exercise_rich_text import normalize_inline_exercise_media_markup
PART_ROLES = (
"goal",
"prerequisites",
@@ -235,8 +237,20 @@ def catalog_available(offered: bool, in_scope: bool) -> bool:
return bool(offered) and bool(in_scope)
def catalog_html(value: Optional[str]) -> str:
"""Gespeichertes Übungs-HTML. Absätze, Umbrüche, Listen und Hervorhebungen bleiben erhalten."""
if value is None:
return ""
normalized = normalize_inline_exercise_media_markup(str(value))
return normalized or ""
def catalog_document(exercise: dict, variants: list[dict], media: list[dict]) -> dict:
"""Aktueller Übungsstand. Die Reihenfolge der Varianten und Medien gehört zum Inhalt."""
"""Aktueller Übungsstand. Die Reihenfolge der Varianten und Medien gehört zum Inhalt.
text_format html gilt für summary, goal, execution, preparation, trainer_notes
und variants.execution_changes. Titel, Variantenbeschreibung und Material bleiben Text.
"""
ordered_variants = sorted(
variants,
key=lambda item: (item.get("sequence_order") is None, item.get("sequence_order") or 0, int(item.get("id") or 0)),
@@ -247,12 +261,13 @@ def catalog_document(exercise: dict, variants: list[dict], media: list[dict]) ->
)
return {
"source_id": str(exercise.get("public_id")),
"text_format": "html",
"title": exercise.get("title") or "",
"summary": plaintext(exercise.get("summary")),
"goal": plaintext(exercise.get("goal")),
"execution": plaintext(exercise.get("execution")),
"preparation": plaintext(exercise.get("preparation")),
"trainer_notes": plaintext(exercise.get("trainer_notes")),
"summary": catalog_html(exercise.get("summary")),
"goal": catalog_html(exercise.get("goal")),
"execution": catalog_html(exercise.get("execution")),
"preparation": catalog_html(exercise.get("preparation")),
"trainer_notes": catalog_html(exercise.get("trainer_notes")),
"equipment": _equipment_text(exercise) or "",
"duration_min": exercise.get("duration_min"),
"duration_max": exercise.get("duration_max"),
@@ -260,8 +275,8 @@ def catalog_document(exercise: dict, variants: list[dict], media: list[dict]) ->
{
"id": str(item.get("public_id")),
"name": item.get("variant_name") or "",
"description": plaintext(item.get("description")),
"execution_changes": plaintext(item.get("execution_changes")),
"description": (item.get("description") or "").strip(),
"execution_changes": catalog_html(item.get("execution_changes")),
"sequence_order": item.get("sequence_order"),
}
for item in ordered_variants