Skip to content

Commit bab3b55

Browse files
GatsbyJS Botfshowalter
GatsbyJS Bot
andauthored
fix(gatsby-transformer-remark): Activate footnotes by default & remove included options with remark v13 (#31019) (#31080)
* fix footnotes in gatsby-transformer-remark * fix tests * fix example * allow any value for deprecated parameters (cherry picked from commit a35d615) Co-authored-by: Frank Showalter <[email protected]>
1 parent 3dfa9af commit bab3b55

File tree

7 files changed

+39
-30
lines changed

7 files changed

+39
-30
lines changed

examples/using-remark/gatsby-config.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ module.exports = {
2727
resolve: `gatsby-transformer-remark`,
2828
options: {
2929
gfm: true,
30-
commonmark: true,
3130
footnotes: true,
32-
pedantic: true,
3331
// blocks: ["h2"], Blocks option value can be provided here as an array.
3432
excerpt_separator: `<!-- end -->`,
3533
plugins: [

packages/gatsby-transformer-remark/README.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,8 @@ plugins: [
1414
{
1515
resolve: `gatsby-transformer-remark`,
1616
options: {
17-
// CommonMark mode (default: true)
18-
commonmark: true,
1917
// Footnotes mode (default: true)
2018
footnotes: true,
21-
// Pedantic mode (default: true)
22-
pedantic: true,
2319
// GitHub Flavored Markdown mode (default: true)
2420
gfm: true,
2521
// Plugins configs
@@ -29,15 +25,12 @@ plugins: [
2925
],
3026
```
3127

32-
The following parts of `options` are passed down to Remark as options:
28+
The following parts of `options` enable the `remark-footnotes` and `remark-gfm`
29+
plugins:
3330

34-
- `options.commonmark`
3531
- `options.footnotes`
36-
- `options.pedantic`
3732
- `options.gfm`
3833

39-
The details of the Remark options above could be found in [`remark-parse`'s documentation](https://github.com/remarkjs/remark/tree/main/packages/remark-parse#processoruseparse-options)
40-
4134
A full explanation of how to use markdown in Gatsby can be found here:
4235
[Creating a Blog with Gatsby](https://www.gatsbyjs.org/blog/2017-07-19-creating-a-blog-with-gatsby/)
4336

packages/gatsby-transformer-remark/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"mdast-util-to-string": "^2.0.0",
1818
"mdast-util-toc": "^5.1.0",
1919
"remark": "^13.0.0",
20+
"remark-footnotes": "^3.0.0",
2021
"remark-gfm": "^1.0.0",
2122
"remark-parse": "^9.0.0",
2223
"remark-retext": "^4.0.0",

packages/gatsby-transformer-remark/src/__tests__/gatsby-node.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@ import { pluginOptionsSchema } from "../gatsby-node"
44
describe(`gatsby-node.js`, () => {
55
it(`should provide meaningful errors when fields are invalid`, async () => {
66
const expectedErrors = [
7-
`"commonmark" must be a boolean`,
87
`"footnotes" must be a boolean`,
9-
`"pedantic" must be a boolean`,
108
`"gfm" must be a boolean`,
119
`"plugins" must be an array`,
1210
]
1311

1412
const { errors } = await testPluginOptionsSchema(pluginOptionsSchema, {
15-
commonmark: `this should be a boolean`,
1613
footnotes: `this should be a boolean`,
17-
pedantic: `this should be a boolean`,
1814
gfm: `this should be a boolean`,
1915
plugins: `this should be an array`,
2016
})
@@ -24,9 +20,7 @@ describe(`gatsby-node.js`, () => {
2420

2521
it(`should validate the schema`, async () => {
2622
const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, {
27-
commonmark: false,
2823
footnotes: false,
29-
pedantic: false,
3024
gfm: false,
3125
plugins: [
3226
`gatsby-remark-copy-linked-files`,

packages/gatsby-transformer-remark/src/extend-node-type.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const mdastToString = require(`mdast-util-to-string`)
99
const unified = require(`unified`)
1010
const parse = require(`remark-parse`)
1111
const remarkGfm = require(`remark-gfm`)
12+
const remarkFootnotes = require(`remark-footnotes`)
1213
const stringify = require(`remark-stringify`)
1314
const english = require(`retext-english`)
1415
const remark2retext = require(`remark-retext`)
@@ -95,31 +96,32 @@ module.exports = function remarkExtendNodeType(
9596
// Setup Remark.
9697
const {
9798
blocks,
98-
commonmark = true,
9999
footnotes = true,
100100
gfm = true,
101-
pedantic = true,
102101
tableOfContents = {
103102
heading: null,
104103
maxDepth: 6,
105104
},
106105
} = pluginOptions
107106
const tocOptions = tableOfContents
108-
const remarkOptions = {
109-
commonmark,
110-
footnotes,
111-
pedantic,
112-
}
107+
const remarkOptions = {}
108+
113109
if (_.isArray(blocks)) {
114110
remarkOptions.blocks = blocks
115111
}
112+
116113
let remark = new Remark().data(`settings`, remarkOptions)
117114

118115
if (gfm) {
119116
// TODO: deprecate `gfm` option in favor of explicit remark-gfm as a plugin?
120117
remark = remark.use(remarkGfm)
121118
}
122119

120+
if (footnotes) {
121+
// TODO: deprecate `footnotes` option in favor of explicit remark-footnotes as a plugin?
122+
remark = remark.use(remarkFootnotes, { inlineNotes: true })
123+
}
124+
123125
for (const plugin of pluginOptions.plugins) {
124126
const requiredPlugin = require(plugin.resolve)
125127
if (_.isFunction(requiredPlugin.setParserPlugins)) {

packages/gatsby-transformer-remark/src/gatsby-node.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ exports.setFieldsOnGraphQLNodeType = require(`./extend-node-type`)
99

1010
exports.pluginOptionsSchema = function ({ Joi }) {
1111
return Joi.object({
12-
commonmark: Joi.boolean().description(
13-
`Activates CommonMark mode (default: true)`
14-
),
12+
// Options `commonmark` and `pedantic` have no effect since [email protected]
13+
// TODO: remove in v5
14+
commonmark: Joi.any(),
15+
pedantic: Joi.any(),
1516
footnotes: Joi.boolean().description(
1617
`Activates Footnotes mode (default: true)`
1718
),
18-
pedantic: Joi.boolean().description(
19-
`Activates pedantic mode (default: true)`
20-
),
2119
gfm: Joi.boolean().description(
2220
`Activates GitHub Flavored Markdown mode (default: true)`
2321
),

yarn.lock

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18088,6 +18088,14 @@ mdast-util-find-and-replace@^1.1.0:
1808818088
unist-util-is "^4.0.0"
1808918089
unist-util-visit-parents "^3.0.0"
1809018090

18091+
mdast-util-footnote@^0.1.0:
18092+
version "0.1.7"
18093+
resolved "https://registry.yarnpkg.com/mdast-util-footnote/-/mdast-util-footnote-0.1.7.tgz#4b226caeab4613a3362c144c94af0fdd6f7e0ef0"
18094+
integrity sha512-QxNdO8qSxqbO2e3m09KwDKfWiLgqyCurdWTQ198NpbZ2hxntdc+VKS4fDJCmNWbAroUdYnSthu+XbZ8ovh8C3w==
18095+
dependencies:
18096+
mdast-util-to-markdown "^0.6.0"
18097+
micromark "~2.11.0"
18098+
1809118099
mdast-util-from-markdown@^0.8.0:
1809218100
version "0.8.5"
1809318101
resolved "https://registry.yarnpkg.com/mdast-util-from-markdown/-/mdast-util-from-markdown-0.8.5.tgz#d1ef2ca42bc377ecb0463a987910dae89bd9a28c"
@@ -18515,6 +18523,13 @@ microevent.ts@~0.1.1:
1851518523
resolved "https://registry.yarnpkg.com/microevent.ts/-/microevent.ts-0.1.1.tgz#70b09b83f43df5172d0205a63025bce0f7357fa0"
1851618524
integrity sha512-jo1OfR4TaEwd5HOrt5+tAZ9mqT4jmpNAusXtyfNzqVm9uiSYFZlKM1wYL4oU7azZW/PxQW53wM0S6OR1JHNa2g==
1851718525

18526+
micromark-extension-footnote@^0.3.0:
18527+
version "0.3.2"
18528+
resolved "https://registry.yarnpkg.com/micromark-extension-footnote/-/micromark-extension-footnote-0.3.2.tgz#129b74ef4920ce96719b2c06102ee7abb2b88a20"
18529+
integrity sha512-gr/BeIxbIWQoUm02cIfK7mdMZ/fbroRpLsck4kvFtjbzP4yi+OPVbnukTc/zy0i7spC2xYE/dbX1Sur8BEDJsQ==
18530+
dependencies:
18531+
micromark "~2.11.0"
18532+
1851818533
micromark-extension-frontmatter@^0.2.0:
1851918534
version "0.2.2"
1852018535
resolved "https://registry.yarnpkg.com/micromark-extension-frontmatter/-/micromark-extension-frontmatter-0.2.2.tgz#61b8e92e9213e1d3c13f5a59e7862f5ca98dfa53"
@@ -22681,6 +22696,14 @@ [email protected]:
2268122696
resolved "https://registry.yarnpkg.com/remark-footnotes/-/remark-footnotes-1.0.0.tgz#9c7a97f9a89397858a50033373020b1ea2aad011"
2268222697
integrity sha512-X9Ncj4cj3/CIvLI2Z9IobHtVi8FVdUrdJkCNaL9kdX8ohfsi18DXHsCVd/A7ssARBdccdDb5ODnt62WuEWaM/g==
2268322698

22699+
remark-footnotes@^3.0.0:
22700+
version "3.0.0"
22701+
resolved "https://registry.yarnpkg.com/remark-footnotes/-/remark-footnotes-3.0.0.tgz#5756b56f8464fa7ed80dbba0c966136305d8cb8d"
22702+
integrity sha512-ZssAvH9FjGYlJ/PBVKdSmfyPc3Cz4rTWgZLI4iE/SX8Nt5l3o3oEjv3wwG5VD7xOjktzdwp5coac+kJV9l4jgg==
22703+
dependencies:
22704+
mdast-util-footnote "^0.1.0"
22705+
micromark-extension-footnote "^0.3.0"
22706+
2268422707
remark-frontmatter@^3.0.0:
2268522708
version "3.0.0"
2268622709
resolved "https://registry.yarnpkg.com/remark-frontmatter/-/remark-frontmatter-3.0.0.tgz#ca5d996361765c859bd944505f377d6b186a6ec6"

0 commit comments

Comments
 (0)