
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
strapi-markdown-parser
Advanced tools
Strapi controller module to parse Markdown to HTML.
yarn add strapi-markdown-parser
Open your collection or single type's controller file (eg., ./api/{COLLECTION}/controllers/${COLLECTION}.js
), and add the following, substituting your collection or single type's name in the place of {COLLECTION}
. You can specify field names directly, or use the fieldsByType
helper utility to get the fields from the provided model matching the specified datatypes. This module uses Marked as its parser, therefore options correspond to the Marked API.
// Import parser, helper utility, and collection/component models
const { StrapiMarkdown, fieldsByType } = require('strapi-markdown-parser')
const model = require('../models/{COLLECTION}.settings.json')
const componentA = require('../../../components/{CATEGORY}/{COMPONENT}.json')
const componentB = require('../../../components/{CATEGORY}/{COMPONENT}.json')
// Standard fields are wrapped in <p> tags
const standardFields = ['body', 'summary']
// Inline fields are not wrapped in <p> tags
const inlineFields = ['title', 'photo.caption']
// Get field names by type using helper utility
const standardFields = fieldsByType(model, ['richtext'])
const inlineFields = fieldsByType(model, ['string', 'text'])
// Get field names by type, including components
const standardFields = fieldsByType([model, componentA], ['richtext'])
const inlineFields = fieldsByType([model, componentA, componentB], ['string', 'text'])
// Special feature: Include captions from all Strapi file upload types
const standardFields = ['caption', ...fieldsByType(model, ['richtext'])]
const inlineFields = fieldsByType(model, ['string'])
// Options for Marked Markdown parser (defaults shown)
const options = {
smartypants: true,
headerIds: false,
breaks: true
}
// Instantiate class
const { md } = new StrapiMarkdown(standardFields, inlineFields, options)
// Modify response data
module.exports = {
async find(ctx) {
const data = await strapi.services.{COLLECTION}.find(ctx.query)
return md(data)
},
async findOne(ctx) {
const { id } = ctx.params
const data = await strapi.services.{COLLECTION}.findOne({ id })
return md(data)
}
}
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Give a ⭐️ if this project helped you!
This README was generated with ❤️ by readme-md-generator
FAQs
Strapi controller module to parse Markdown to HTML
The npm package strapi-markdown-parser receives a total of 4 weekly downloads. As such, strapi-markdown-parser popularity was classified as not popular.
We found that strapi-markdown-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.