Proposal: Feature: Markdown preview for markdown-supported fields #260

Open
Francesco Bellini wants to merge 2 commits from Francesco-Bellini/extensions-website: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 8f163a1577 - Show all commits

View File

@ -21,6 +21,7 @@ urlpatterns = [
name='api-internal',
),
# 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/<str:extension_id>/versions/upload/',

View File

@ -4,6 +4,7 @@ from django.core.exceptions import ValidationError
from django.db import transaction
from django.http import JsonResponse
from django.utils.decorators import method_decorator
from django.views import View
from django.views.decorators.cache import cache_page
from drf_spectacular.utils import OpenApiParameter, extend_schema
from rest_framework.permissions import AllowAny
@ -13,6 +14,7 @@ from rest_framework.views import APIView
from rest_framework.permissions import IsAuthenticated
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.utils import clean_json_dictionary_from_optional_fields
from files.forms import FileFormSkipAgreed
@ -278,3 +280,10 @@ def extensions_awaiting_review(request):
}
)
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})