-
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
c3fe90c
aab1382
4c609a5
ba2b49c
c8da45b
74961de
0f3c5f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| --- | ||
| title: Editor Tooling | ||
| weight: 60 | ||
| group: Customization | ||
| --- | ||
|
|
||
| ## Linting via remark | ||
|
caseywatts marked this conversation as resolved.
Outdated
|
||
|
|
||
| If you want to lint your markdown files as part of your development workflow (in editors, in a pre-commit hook, and/or via CI), then we suggest you use `remark`. Remark is the library used by the Decap markdown widget. | ||
|
|
||
| If you were to use a different linter than `remark` (such as `prettier`, etc), then you would end up with formatting conflicts between files. Files edited via the Decap web interface would be formatted differently than files edited via your development workflow. | ||
|
caseywatts marked this conversation as resolved.
Outdated
|
||
|
|
||
| To set this up, you will need to install and set up both of these npm packages in your project: | ||
|
|
||
| - remark: https://remark.js.org/ | ||
| - remark-frontmatter: https://github.com/remarkjs/remark-frontmatter | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess most of the time people will want to use remark-lint with remark-cli instead of the core I think remark-lint will not mess with frontmatter, so maybe
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you're right that people will likely use remark-cli instead of remark directly! That's what my team is doing, too. I can update that, no problem.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On my project we did initially try to do it without In our Decap situation it behaves differently, because the markdown widget (which runs remark) is only manipulating the markdown body section of the markdown file. The Decap markdown widget is not aware of the frontmatter.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One thing I noticed on the remark-lint page is that it suggests a bunch of plugins: Since we want to make sure people are getting set up with the same configuration as the Decap markdown widget, maybe we could align these. Either:
Which approach do you think would be better? (or do you have another idea?)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll say 2 should be easier, if you could bring a bit of what you did in your project as quite of a quick set up for remark linting would be great!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great -- I added the setup from my project as an example here 👏 |
||
|
|
||
| ## 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), | ||
| }); | ||
| ``` | ||
Uh oh!
There was an error while loading. Please reload this page.