Skip to content

Commit

Permalink
docs: explain usage and note manual initialization requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
mmkal committed Feb 12, 2022
1 parent 1dc43db commit 6d29b23
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions website/content/docs/beta-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 6d29b23

Please sign in to comment.