Skip to content

Commit

Permalink
Merge pull request #49 from plone/export-richtext-raw
Browse files Browse the repository at this point in the history
Export the raw value of rich text fields
  • Loading branch information
mauritsvanrees authored Jan 31, 2025
2 parents a3b1e0f + 12f3434 commit ba480e3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions news/48.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Export the raw value of rich text fields, instead of the transformed output.
This fixes internal links in Classic UI based distributions.
@mauritsvanrees
1 change: 1 addition & 0 deletions src/plone/exportimport/serializers/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
<adapter factory=".blocks.ExportImportBlocksSerializer" />
<adapter factory=".fields.CollectionFieldSerializer" />
<adapter factory=".fields.ChoiceFieldSerializer" />
<adapter factory=".fields.ExportImportRichTextSerializer" />
</configure>
15 changes: 15 additions & 0 deletions src/plone/exportimport/serializers/fields.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from plone.app.textfield.interfaces import IRichText
from plone.app.textfield.interfaces import IRichTextValue
from plone.dexterity.interfaces import IDexterityContent
from plone.exportimport.interfaces import IExportImportRequestMarker
from plone.restapi.interfaces import IFieldSerializer
Expand Down Expand Up @@ -76,3 +78,16 @@ def __call__(self):
self.context,
)
return json_compatible(value)


@adapter(IRichText, IDexterityContent, IExportImportRequestMarker)
class ExportImportRichTextSerializer(DefaultFieldSerializer):
def __call__(self):
value = self.get_value()
if value is None or not IRichTextValue.providedBy(value):
return json_compatible(value, self.context)
return {
"data": json_compatible(value.raw),
"content-type": json_compatible(value.mimeType),
"encoding": json_compatible(value.encoding),
}

0 comments on commit ba480e3

Please sign in to comment.