-
Notifications
You must be signed in to change notification settings - Fork 316
Documentation: Use Remark as linter in text editors #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
caseywatts
wants to merge
7
commits into
decaporg:main
Choose a base branch
from
caseywatts:cw/document-linters
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c3fe90c
rename custom-formatters to editor tooling, and add in the new lintin…
caseywatts aab1382
Update content/docs/editor-tooling.md
caseywatts 4c609a5
Update content/docs/editor-tooling.md
caseywatts ba2b49c
add installation settings for remark-cli and remark-frontmatter
caseywatts c8da45b
Update content/docs/editor-tooling.md
caseywatts 74961de
Update content/docs/editor-tooling.md
caseywatts 0f3c5f2
Merge branch 'main' into cw/document-linters
yanthomasdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| --- | ||
| title: Editor Tooling | ||
| weight: 60 | ||
| group: Customization | ||
| aliases: | ||
| - custom-formatters | ||
| --- | ||
|
|
||
| ## Linting | ||
|
|
||
| If you want to lint your Markdown files as part of your development workflow through your code editor, pre-commit hooks, and/or CI, we recommend using the Remark ecosystem. | ||
|
|
||
| Since Decap CMS uses `remark` internally for Markdown processing, using it in your development workflow will help avoid formatting/style differences between files edited through Decap and files edited locally. | ||
|
|
||
| To start using it in your project, install both [`remark-cli`](https://github.com/remarkjs/remark/tree/main/packages/remark-cli) and [`remark-frontmatter`](https://github.com/remarkjs/remark-frontmatter): | ||
|
|
||
| ```sh | ||
| npm install --save-dev remark-cli remark-frontmatter | ||
| ``` | ||
|
|
||
| Then, add the following lines to your `package.json`: | ||
|
|
||
| ```json | ||
| { | ||
| "scripts": { | ||
| "remark:check": "remark .", | ||
| "remark:write": "remark . --output" | ||
| }, | ||
| "remarkConfig": { | ||
| "plugins": ["remark-frontmatter"] | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Now, you can use `npm run remark:check` to lint your Markdown files and `npm run remark:write` to format them. | ||
|
|
||
| ## 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.decapcms.org/docs/configuration-options/#collections) for more details. | ||
|
|
||
| You can also override the built-in 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), | ||
| }); | ||
| ``` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.