Export custom Portable Text from Google Docs and Notion to Sanity
Learn how you can export custom Portable Text from Google Docs and Notion to Sanity
Introduction
Sanity uses a proprietary JSON format called Portable Text. When you export content to Sanity, Cloudpress will automatically convert the content to the correct Portable Text format. It will convert your text with the formatting, headings, tables, code blocks, etc.
However, you may want to export custom content not supported by Cloudpress. For example, Sanity has Portable Text blocks such as the geopoint and file blocks, for which there is no corresponding representation in Google Docs and Notion.
You can edit the content in Sanity after you export it with Cloudpress to add these blocks, but that requires an extra step. Also, if you re-export the source content with Cloudpress, all your changes will be lost.
To work around this problem, Cloudpress introduced a feature called Raw Content Blocks that allows you to add the source code for Portable Text blocks like these to your source document. When Cloudpress exports your content and encounters a Raw Content Block, it will send the content of that block to Sanity as-is.
The rest of this document will walk you through this feature by demonstrating how to add a geopoint
and file
block your content and have Cloudpress export it correctly to Sanity.
Get the JSON representation of your Portable Text blocks
First, you must get the JSON representation of the Portable Text block(s) you want to export. Create an empty item in Sanity containing the Portable Text elements to export - in this example, a geopoint
and file
block.
Next, we need to get the underlying JSON code for these blocks. To do that, open the overflow menu and select the Inspect menu item.
Switch to the Raw JSON tab to see a text outline of the JSON for this document.
You can see the body
property is an array that contains two objects that represent the geopoint
and file
blocks. To copy the JSON for a block, highlight the JSON code for the block you want to include in your Raw Content Block and copy it to the clipboard.
For example, here is the JSON of the geopoint
:
If you want to export multiple blocks, place them inside an array. We suggest you copy the JSON for each block individually to a text editor and then edit them to wrap them inside an array before you copy and paste the JSON for that array to Google Docs or Notion. Below is an example of an array containing the JSON for both the geopoint
and the file
.
Once you have the JSON for the Portable Text blocks, you can add it to Google Docs or Notion. The process differs for each and is discussed in separate sections below.
Export your custom Portable Text
To export the Portable Text elements, you must define a raw content block using the @@begin_raw_content
and @@end_raw_content
processing directives.
- Denote the start of a raw content block by by adding the
@@begin_raw_content
directive to your document. - After that, add the JSON for the Portable Text element(s)
- Finally, close off a raw content block, use the
@@end_raw_content
directive.
The raw content block should appear in your editor as per the screenshots below.
Only plain text is allowed between the two directives. Any other content, such as tables, lists, images, etc., will be dropped during the export. In the case of Notion, as per the screenshot above, you may also use the Code block between the two directives.
When you export your document, Cloudpress will interpret the content between the @@begin_raw_content
and @@end_raw_content
directives as raw content and will export it to Sanity as-is. It is therefore important that the content you specify is valid JSON. If not, Sanity will prevent Cloudpress from exporting the content.
When the document in the screenshots above is exported to Sanity, it will result in the correct Portable Text content being created.
Sample documents
You can find the sample documents used in this documentation below: