-
Notifications
You must be signed in to change notification settings - Fork 60.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add experimental react support within markdown
Also added fronmatter for interactive: true to turn on React on a file by file basis and prevent slowing down the builds for non-react files
- Loading branch information
Showing
16 changed files
with
31,834 additions
and
581 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,23 @@ | ||
const { renderToString } = require('react-dom/server') | ||
const transform = require('./transform') | ||
|
||
// These all need to be here even though eslint doesn't think so | ||
/* eslint-disable */ | ||
const React = require('react') | ||
const CodeBlock = require('../../dist/react/CodeBlock') | ||
const RedContent = require('../../dist/react/RedContent') | ||
const Timer = require('../../dist/react/Timer') | ||
/* eslint-enable */ | ||
|
||
const renderReact = async componentStr => { | ||
const componentName = componentStr.match(/[^<]([a-zA-Z])*/gm)[0] | ||
const jsx = `<div className="react-component-${componentName}">\n${componentStr}\n</div>` | ||
const component = transform(jsx) | ||
|
||
// eslint-disable-next-line | ||
return renderToString(eval(component)) | ||
} | ||
|
||
module.exports = { | ||
renderReact | ||
} |
This file contains 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,13 @@ | ||
const babel = require('@babel/core') | ||
const transform = code => | ||
babel.transform(code, { | ||
presets: ['@babel/preset-env'], | ||
plugins: [ | ||
'@babel/plugin-transform-react-jsx', | ||
'@babel/plugin-proposal-object-rest-spread', | ||
'@babel/plugin-transform-modules-commonjs', | ||
'@babel/plugin-proposal-class-properties' | ||
] | ||
}).code | ||
|
||
module.exports = transform |
Oops, something went wrong.