Files
react.dev/plugins/gatsby-remark-use-jsx/index.js
Brian Vaughn 3e4f2687c6 Update copyright headers (#3086)
Added and updated copyright headers.

Added some missing Flow types.

Removed an invalid prop-types import.
2020-07-07 10:35:57 -04:00

27 lines
752 B
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*/
const visit = require('unist-util-visit');
// Always treat JS blocks as JSX.
// TODO: maybe we can just change it in Markdown in the future?
module.exports = ({markdownAST}) => {
visit(markdownAST, `code`, node => {
if (typeof node.lang !== 'string') {
return;
}
if (node.lang.indexOf('jsx') === 0) {
// Already JSX (with optional line range).
return;
}
// Turn JS into JSX, preserving the optional line range.
if (node.lang.indexOf('js') === 0) {
node.lang = 'jsx' + node.lang.substring('js'.length);
}
if (node.lang.indexOf('javascript') === 0) {
node.lang = 'jsx' + node.lang.substring('javascript'.length);
}
});
};