
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react-easy-md
Advanced tools
React marked-markdown improved without null title and with shortcuts for links.
Write Markdown with React easily with some JavaScript modules for it.
This is forked version of react-marked-markdown. But the differences are
null title.set prop is included for MarkdownPreview to help you write shortcuts for <a> inside markdown.The original Github repository is archived so this package was made to share the code from the former repository with some improvements.
Steadylearner uses markdown intensively and it may have more features later.
To explain more about 1., You can define title for links with the syntax below
[Website](https://www.steadylearner.com/ "Website")
But having default value solves the problem of showing null title when users forget to define it or when third party data doesn't send it.
Type $npm install --save react-easy-md or $yarn add react-easy-md in your CLI
Then,import component(s) you want
import {
MarkdownInput,
MarkdownPreview,
//
html,
markdown,
copy,
readLocalFileWithHow,
saveTextFromWeb,
//
substitute,
// reverseSet,
// unsubstitute,
} from 'react-easy-md';
// index.js
import React from "react";
import ReactDOM from "react-dom";
import { MarkdownPreview, copy, } from "react-easy-md";
const example = "## React Easy Markdown"
const set = [
["s-", "https://www.steadylearner.com"],
["l-", "https://www.linkedin.com/in"],
["y-", "https://www.youtube.com/channel/"],
["t-", "https://twitter.com/"],
["g-", "https://www.github.com"],
];
function App() {
return (
<section className="App">
<MarkdownPreview
value={markdown(html(example))}
markedOptions={{
langPrefix: "hljs ", // 1.
sanitize: false, // // 2.
breaks: true, // 3.
}}
set={set} // 4.
/>
<button onClick={() => copy(example)} >Copy</button>
</section>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
You can Refer to www.steadylearner.com/markdown page for live example.
The important points here are
hljs prefix to style code blocks.
false to allow html
You can use [enter] instead of \n
You can define shortcut for links with set prop
For code syntax highlight process in 1., you may read How to enable code syntax highlight in React App.
Then, Include link below in your index.html.
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/styles/foundation.min.css" />
Define set of shortcuts and links for your .md files.
const set={[
["s-", "https://www.steadlyearner.com"],
["l-", "https://www.linkedin.com/in"],
["y-", "https://www.youtube.com/channel/"],
["t-", "https://twitter.com/"],
["g-", "https://www.github.com"]
]}
Then, pass it to MarkdownPreview for set prop and it will convert
[Blog](s-/blog)
[LinkedIn](l-/steady-learner-3151b7164)
[YouTube](y-/UCt_jsJOe91EVjd58kHpgTfw)
[Twittter](t-/steadylearner_p)
[Github](g-/steadylearner)
equal to
[Blog](https://www.steadylearner.com/blog)
[LinkedIn](https://www.linkedin.com/in/steady-learner-3151b7164/)
[YouTube](https://www.youtube.com/channel/UCt_jsJOe91EVjd58kHpgTfw)
[Twittter](https://twitter.com/steadylearner_p)
[Github](https://github.com/steadylearner)
With set from this package, you don't have to type the entire paths anymore.
It helps you not to repeat what you know they will do. You can use it wherever you use link. For example,
[code]: s-/code "Steadylearner Code"
You can use shortcuts you define in set and use substitute before you use .md file where don't have code to convert them.
import { substitute, unsubstitute } from "react-easy-md";
const set={[
["s-", "https://www.steadlyearner.com"],
["l-", "https://www.linkedin.com/in"],
["y-", "https://www.youtube.com/channel/"],
["t-", "https://twitter.com/"],
["g-", "https://www.github.com"]
]};
const short = ": s-, (s-)";
const long = ": www.steadylearner.com, (https://www.steadylearner.com)";
substitute(set)(short); // equals to long
unsubstitue(set)(long); // eqauls to short
What you need is just to wrap .md file value with substitute(set)(value).
unsubstitue is just reverse API of substitute. You can make it with substitute and reverseSet. But it is included for your convenience.
You can refer to example code to understand it better or tests for it.
They use regex so you have to use it with caution and test for your .md file before you use them.
If you want to use it for all .md files in directory, please refer to convertdir.js.
import { html, markdown } from "react-easy-md";
const package = "# react easy md";
const HTML = html(package); // <h1 id="react-easy-md" >react easy md</h1>
const react-easy-md = markdown(HTML) // "# react easy md"
You can use them for .md files or other usages.
import React, { Component } from "react";
import { readLocalFileWithHow, saveTextFromWeb } from "react-easy-md";
class ReadSave extends Component {
constructor(props) {
super(props);
this.state = {
value: "# React Easy Markdown",
};
}
readLocalFile(e) {
readLocalFileWithHow(e, (value) => this.setState({
value,
}));
} // 1.
// 2.
render() {
const { value } = this.state;
return (<section>
<span>
<input
className="md-file-input"
type="file"
id="md-file-input"
name="md-file-input"
accept=".md"
onClick={(e) => this.readLocalFile(e)}
/>
<label
htmlFor="md-file-input"
>
</label>
</span>
<span
onClick={() => saveTextFromWeb(value)}
>
<i
className={`fas fa-file`}
/>
</span>
</section>);
}
}
You can refer to examples for them.
The important parts here are
readLocalFileWithHow.(Then, You can define function for how to use it)If you see some warnings and errors with this package while you use webpack, you may include
// Refer to webpack.config.js at
// https://github.com/steadylearner/react-easy-md/blob/master/examples/config/webpack.config.js
// Remove errors in developement
const FilterWarningsPlugin = require('webpack-filter-warnings-plugin');
// For production mode work, use it instead of uglifyjsplugin
const TerserPlugin = require('terser-webpack-plugin'); //
moudle.exports = () => {
return({
module: {
rules: [
{// to exclude source map error from third part libraires.
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ["source-map-loader"],
enforce: "pre",
},
],
node: {
fs: "empty",
tls: "empty",
net: "empty",
child_process: "empty",
},
optimization: {
minimizer: [new TerserPlugin()],
},
// To remove warning from 'jsdom' used inside react-easy-md
plugins: [
new FilterWarningsPlugin({
exclude: /Critical dependency: the request of a dependency is an expression/,
}),
],
}
})
}
It is mainly to remove warnigns from the package written in TypeScript.
You won't need them if you use CRA.
(This package upgraded dependencies from react-marked-markdown and one of new dependency use TypeScript and it makes dependency problems. So you have to enable it for your bundler. )
Refer to convertdir.js and $node convertdir.js <withshorcut> <withoutit>.
It will substitute shorcuts and use whole link for your .md files.
FAQs
React marked-markdown improved without null title and with shortcuts for links.
We found that react-easy-md demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.