Welcome to strapi-markdown-parser 👋
Strapi controller module to parse Markdown to HTML.
Install
yarn add strapi-markdown-parser
Use
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.
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')
const standardFields = ['body', 'summary']
const inlineFields = ['title', 'photo.caption']
const standardFields = fieldsByType(model, ['richtext'])
const inlineFields = fieldsByType(model, ['string', 'text'])
const standardFields = fieldsByType([model, componentA], ['richtext'])
const inlineFields = fieldsByType([model, componentA, componentB], ['string', 'text'])
const standardFields = ['caption', ...fieldsByType(model, ['richtext'])]
const inlineFields = fieldsByType(model, ['string'])
const options = {
smartypants: true,
headerIds: false,
breaks: true
}
const { md } = new StrapiMarkdown(standardFields, inlineFields, options)
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)
}
}
🤝 Contributing
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Show your support
Give a ⭐️ if this project helped you!
This README was generated with ❤️ by readme-md-generator