diff --git a/website/content/docs/beta-features.md b/website/content/docs/beta-features.md index d68d552d07f2..e1b5b7bfa342 100644 --- a/website/content/docs/beta-features.md +++ b/website/content/docs/beta-features.md @@ -664,3 +664,31 @@ CMS.registerRemarkPlugin({ settings: { bullet: '-' } }); ``` Note that `netlify-widget-markdown` currently uses `remark@10`, so you should check a plugin's compatibility first. + +## Custom formatters + +To manage content with other file formats than the built in ones, you can register a custom formatter: + +```js +const JSON5 = require('json5'); + +CMS.registerCustomFormat('json5', 'json5', { + fromFile: text => JSON5.parse(text), + toFile: value => JSON5.stringify(value, null, 2), +}); +``` + +Then include `format: json5` in your collection configuration. See the [Collection docs](https://www.netlifycms.org/docs/configuration-options/#collections) for more details. + +You can also override the in-built formatters. For example, to change the YAML serialization method from [`yaml`](https://npmjs.com/package/yaml) to [`js-yaml`](https://npmjs.com/package/js-yaml): + +```js +const jsYaml = require('js-yaml'); + +CMS.registerCustomFormat('yml', 'yml', { + fromFile: text => jsYaml.load(text), + toFile: value => jsYaml.dump(value), +}); +``` + +Note: custom formats must be registered before the CMS is initialized, so enable [manual initialization](#manual-initialization) when using it.