Enhancement: render document notes as markdown (#14626)

---------

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
Johannes Hagerandshamoon authored and GitHub committed 2026-11-13 09:08:20 -08:00
1 parent bfd5628dcc
commit b63ea77543
13 files changed
+270 -30

No files matched your search

+54
View File
@@ -3689,6 +3689,7 @@ class TestDocumentApi(DirectoriesMixin, ConsumeTaskMixin, APITestCase):
{
"id": note.id,
"note": note.note,
"format": Note.Format.PLAIN,
"user": {
"id": note.user.id,
"username": note.user.username,
@@ -3737,11 +3738,64 @@ class TestDocumentApi(DirectoriesMixin, ConsumeTaskMixin, APITestCase):
resp_data = resp_data[0]
self.assertEqual(resp_data["note"], "this is a posted note")
self.assertEqual(resp_data["format"], Note.Format.PLAIN)
doc = Document.objects.get(pk=doc.pk)
# modified was updated to today
self.assertEqual(doc.modified.day, timezone.now().day)
def test_create_markdown_note(self) -> None:
doc = DocumentFactory(
title="test",
content="this is a document which will have a markdown note",
)
response = self.client.post(
f"/api/documents/{doc.pk}/notes/",
data={"note": "**markdown**", "format": Note.Format.MARKDOWN},
format="json",
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
note = Note.objects.get(document=doc)
self.assertEqual(note.format, Note.Format.MARKDOWN)
response = self.client.get(f"/api/documents/{doc.pk}/notes/", format="json")
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.json()[0]["format"], Note.Format.MARKDOWN)
def test_create_note_rejects_unsupported_format(self) -> None:
doc = DocumentFactory(
title="test",
content="this is a document which will have a note",
)
response = self.client.post(
f"/api/documents/{doc.pk}/notes/",
data={"note": "unsupported", "format": "html"},
format="json",
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertIn("format", response.json())
self.assertFalse(Note.objects.filter(document=doc).exists())
def test_create_note_requires_note(self) -> None:
doc = DocumentFactory(
title="test",
content="this is a document which will have a note",
)
response = self.client.post(
f"/api/documents/{doc.pk}/notes/",
data={"format": Note.Format.MARKDOWN},
format="json",
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertIn("note", response.json())
self.assertFalse(Note.objects.filter(document=doc).exists())
def test_create_note_only_saves_document_modified_field(self) -> None:
"""
GIVEN: