Convert Markdown Content to Contentful Rich Text with AI Formatting
Last edited 39 days ago
Workflow: Publish to Contentful with Rich Text Formatting
⚡ About the Creators
This workflow was created by Varritech Technologies, an innovative agency that leverages AI to engineer, design, and deliver software development projects 500% faster than traditional agencies. Based in New York City, we specialize in custom software development, web applications, and digital transformation solutions. If you need assistance implementing this workflow or have questions about content management solutions, please reach out to our team.
🏗️ Architecture Overview
This workflow takes a JSON article payload, splits its markdown content into logical chunks, converts each chunk into Contentful Rich Text JSON via an AI agent, merges the resulting rich text nodes back into a single document, formats the entire entry according to Contentful's field schema, and finally publishes it to Contentful.
- Trigger → Executes when called by another workflow
- Split by Headings → Breaks markdown into
##
-delimited chunks - Markdown → Rich Text → AI agent converts each chunk to Contentful Rich Text JSON
- Combine Rich Text Objects → Aggregates all chunk outputs into one document
- Format Entry → Wraps metadata and rich-text content into Contentful schema
- Publish Entry → HTTP POST to Contentful API
📦 Node-by-Node Breakdown
flowchart LR
A[When Executed by Another Workflow] --> B[Split by Headings]
B --> C[Markdown to Contentful format]
C --> D[Combine Rich Text Objects]
D --> E[Merge1]
E --> F[Format1]
F --> G[Create newly formatted Contentful Entry]
1. When Executed by Another Workflow
Type: Execute Workflow Trigger
Input Example:
- title, slug, category.id, description, keywords, content, metaTitle, metaDescription, readingTime, difficulty
Purpose: Receives the JSON payload from the upstream workflow.
2. Split by Headings
Type: Code
Logic:
- Splits input.content into an array of markdown chunks at each second-level heading (##).
- Emits one item per chunk with index, slug, title, and contentChunk.
3. Markdown to Contentful format
Type: LangChain Agent (+ OpenAI Chat model)
System Prompt:
- Defines rules for generating valid Contentful Rich Text JSON (must include nodeType, data:{}, content:[], etc.).
- Provides examples for paragraphs, headings, lists, links, and images.
User Prompt:
Here is the markdown content to convert:
{{ $json.contentChunk }}
Purpose: Converts each markdown chunk into an array of rich-text nodes.
4. Combine Rich Text Objects
Type: Code
Logic:
- Parses and merges all content arrays returned by the AI agent into one combined content array under a document root.
5. Merge1
Type: Merge
Purpose: Joins the original item (with metadata) and the combined rich-text document into a single data stream.
6. Format1
Type: Code
Logic:
- Maps workflow data into the Contentful entry schema by setting each field (title, slug, category link, description, keywords, rich-text content, metaTitle, metaDescription, readingTime, difficulty) under the appropriate locale and structure required by Contentful.
7. Create newly formatted Contentful Entry
Type: HTTP Request
Method: POST
URL: https://api.contentful.com/spaces
Headers:
- Authorization: Bearer token for Contentful Management API
- Content-Type: application/vnd.contentful.management.v1+json
- X-Contentful-Version: entry version number
- X-Contentful-Content-Type: content type ID
Body: The formatted fields object produced by the previous node
Purpose: Publishes the new entry with rich-text content to Contentful.
🔍 Design Rationale & Best Practices
Chunked Conversion
Splitting by headings prevents AI context limits and keeps conversions modular.
Strict Rich Text Schema
Enforcing nodeType, data, and content structure avoids validation errors on Contentful.
Two-Phase Merge
Separating "combine AI outputs" and "format entry" keeps transformations clear and testable.
Idempotent Publish
Uses explicit versioning and content type headers to ensure correct entry creation.
You may also like
New to n8n?
Need help building new n8n workflows? Process automation for you or your company will save you time and money, and it's completely free!