markdown2react
v0.0.1
Published
Transform markdown files to React component files
Downloads
3
Readme
markdown2react
Utility functions for transforming markdown files into React components
Getting Started
npm i -S markdown2react
Transforming markdown
The transform
function takes in a markdown string and returns a new string that is the contents of a component file.
Example:
const { transform } = require('markdown2react')
transform({
name: 'MyComponent', // optional
markdown: '## Hello', // required
}, (error, component) => {
console.log(component)
})
This should log the following to the console.
import React from 'react';
const MyComponent = () => (<h2 class="hello">Hello</h2>)
export default MyComponent;
Transforming markdown and persisting to disk
The write
function takes in a glob path, than using the transform
function, it will transform and write markdown files to disk. Finally the write function will create a set of index.js
files for easier accessibility.
Example:
Example markdown directory structure
docs/
tutorials/
how-to-get-started.md
Readme.md
Calling write function
const { write } = require('markdown2react')
write({
src: './docs/**/*.md',
dest: './dest',
}, console.log)
The following files will be created
dist/
tutorials/
HowToGetStarted.js
index.js
Readme.js
index.js
License
Copyright 2019 Paul Serraino
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.