WIP: Feature: Markdown preview for markdown-supported fields #1

Closed
Francesco Bellini wants to merge 2 commits from markdown-preview into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
2 changed files with 10 additions and 0 deletions
Showing only changes of commit 8691ee5e7b - Show all commits

View File

@ -21,6 +21,7 @@ urlpatterns = [
name='api-internal', name='api-internal',
), ),
# Public API # Public API
path('markdown/', api.MarkdownRenderApi.as_view(), name='markdown-rendering'),
path('api/v1/extensions/', api.ExtensionsAPIView.as_view(), name='api'), path('api/v1/extensions/', api.ExtensionsAPIView.as_view(), name='api'),
path( path(
'api/v1/extensions/<str:extension_id>/versions/upload/', 'api/v1/extensions/<str:extension_id>/versions/upload/',

View File

@ -4,6 +4,7 @@ from django.core.exceptions import ValidationError
from django.db import transaction from django.db import transaction
from django.http import JsonResponse from django.http import JsonResponse
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.views import View
from django.views.decorators.cache import cache_page from django.views.decorators.cache import cache_page
from drf_spectacular.utils import OpenApiParameter, extend_schema from drf_spectacular.utils import OpenApiParameter, extend_schema
from rest_framework.permissions import AllowAny from rest_framework.permissions import AllowAny
@ -13,6 +14,7 @@ from rest_framework.views import APIView
from rest_framework.permissions import IsAuthenticated from rest_framework.permissions import IsAuthenticated
from common.compare import is_in_version_range, version from common.compare import is_in_version_range, version
from common.markdown import render as render_markdown
from extensions.models import Extension, Platform from extensions.models import Extension, Platform
from extensions.utils import clean_json_dictionary_from_optional_fields from extensions.utils import clean_json_dictionary_from_optional_fields
from files.forms import FileFormSkipAgreed from files.forms import FileFormSkipAgreed
@ -273,3 +275,10 @@ def extensions_awaiting_review(request):
} }
) )
return JsonResponse(response, safe=False) return JsonResponse(response, safe=False)
class MarkdownRenderApi(View):
def post(self, request, *args, **kwargs):
text = request.POST.get('text')
rendered_markdown = render_markdown(text)
return JsonResponse({'markdown': rendered_markdown})