3.0.3 • Published 4 years ago
@namskiiiii/react-markdown-preview-naked v3.0.3
React Markdown Preview
React component preview markdown text in web browser. The minimal amount of CSS to replicate the GitHub Markdown style. The current document website is converted using this react component.
Quick Start
$ npm install @uiw/react-markdown-preview --save
Usage Example
import MarkdownPreview from '@uiw/react-markdown-preview';
const source = `
## MarkdownPreview
> todo: React component preview markdown text.
`;
function Demo() {
return (
<MarkdownPreview source={source} />
)
}
Options Props
import { ReactMarkdownProps } from 'react-markdown';
type MarkdownPreviewProps = {
className?: string;
source?: string;
style?: React.CSSProperties;
warpperElement?: HTMLDivElement;
onScroll?: (e: React.UIEvent<HTMLDivElement>) => void;
onMouseOver?: (e: React.MouseEvent<HTMLDivElement>) => void;
} & ReactMarkdownProps;
source
(string
, default:''
)\ Markdown to parseclassName
(string?
)\ Wrap the markdown in adiv
with this class name
This ReactMarkdownProps
details. Upgrade react-markdown
v6
children
(string
, default:''
)\ Markdown to parseclassName
(string?
)\ Wrap the markdown in adiv
with this class nameskipHtml
(boolean
, default:false
)\ Ignore HTML in Markdown completelysourcePos
(boolean
, default:false
)\ Pass a prop to all components with a serialized position (data-sourcepos="3:1-3:13"
)rawSourcePos
(boolean
, default:false
)\ Pass a prop to all components with their position (sourcePosition: {start: {line: 3, column: 1}, end:…}
)includeElementIndex
(boolean
, default:false
)\ Pass theindex
(number of elements before it) andsiblingCount
(number of elements in parent) as props to all componentsallowedElements
(Array.<string>
, default:undefined
)\ Tag names to allow (can’t combine w/disallowedElements
). By default all elements are alloweddisallowedElements
(Array.<string>
, default:undefined
)\ Tag names to disallow (can’t combine w/allowedElements
). By default no elements are disallowedallowElement
((element, index, parent) => boolean?
, optional)\ Function called to check if an element is allowed (when truthy) or not.allowedElements
/disallowedElements
is used first!unwrapDisallowed
(boolean
, default:false
)\ Extract (unwrap) the children of not allowed elements. By default, whenstrong
is not allowed, it and it’s children is dropped, but withunwrapDisallowed
the element itself is dropped but the children usedlinkTarget
(string
or(href, children, title) => string
, optional)\ Target to use on links (such as_blank
for<a target="_blank"…
)transformLinkUri
((href, children, title) => string
, default: uri-transformer.js, optional)\ URL to use for links. The default allows onlyhttp
,https
,mailto
, andtel
, and is available atReactMarkdown.uriTransformer
. Passnull
to allow all URLs. See securitytransformImageUri
((src, alt, title) => string
, default: uri-transformer.js, optional)\ Same astransformLinkUri
but for imagescomponents
(Object.<string, Component>
, default:{}
)\ Object mapping tag names to React componentsremarkPlugins
(Array.<Plugin>
, default:[]
)\ List of remark plugins to use. See the next section for examples on how to pass optionsrehypePlugins
(Array.<Plugin>
, default:[]
)\ List of rehype plugins to use. See the next section for examples on how to pass options
Development
Runs the project in development mode.
# Step 1, run first,
# listen to the component compile and output the .js file
# listen for compilation output type .d.ts file
npm run watch
# listen to the component compile and output the .css file
npm run css:watch
# Step 2, development mode, listen to compile preview website instance
npm start
Builds the app for production to the build folder.
npm run build
The build is minified and the filenames include the hashes. Your app is ready to be deployed!
Related
If you need more features-rich Markdown Editor, you can use @uiwjs/react-markdown-editor
- @uiw/react-codemirror: CodeMirror component for React. @codemirror
- @uiw/react-monacoeditor: Monaco Editor component for React.
- @uiw/react-markdown-editor: A markdown editor with preview, implemented with React.js and TypeScript.
- @uiw/react-markdown-preview: React component preview markdown text in web browser.
License
Licensed under the MIT License.
3.0.3
4 years ago