You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

26 lines
752 B

/**
* 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);
}
});
};