Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["@salesforce/eslint-config-lwc/recommended"]
}
82 changes: 59 additions & 23 deletions example/src/example.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,67 @@
var Editor = require('react-md-editor');
var marked = require('marked');
var React = require('react');
var ReactDOM = require('react-dom');

var App = React.createClass({
getInitialState () {
return {
code: '# React Markdown Editor\n\n* A list\n\nSome **bold** and _italic_ text\n\n> A quote...\n\nBy [Jed Watson](https://github.com/JedWatson) and [Joss Mackison](https://github.com/jossmac)'
};
},
updateCode (newCode) {
this.setState({
code: newCode
});
},
render () {
var preview = marked(this.state.code);
// Import React and other dependencies
import React, { Component } from "react";
import PropTypes from "prop-types";
import Editor from "react-md-editor";
import marked from "marked";

// Define a new React component
class App extends Component {
// Define the PropTypes for the component
static propTypes = {
code: PropTypes.string.isRequired,
};

// Define the initial state of the component
state = {
code: this.props.code,
};

// Define a function to update the state when the editor content changes
updateCode = (newCode) => {
this.setState({ code: newCode });
};

// Render the component
render() {
// Extract the current state of the component
const { code } = this.state;

// Use marked to convert the markdown content to HTML
const preview = marked(code);

// Render the component
return (
<div className="example">
<div className="hint">The editor is below, with default options. This example also uses marked to generate the preview on the right as you type.</div>
<div className="hint">
The editor is below, with default options. This example also uses
marked to generate the preview on the right as you type.
</div>
// Render the Markdown editor component
<div className="editor">
<Editor value={this.state.code} onChange={this.updateCode} />
<Editor value={code} onChange={this.updateCode} />
</div>
<div className="preview" dangerouslySetInnerHTML={{__html: preview}} />
{/* Render the preview of the markdown content */}
<div
className="preview"
dangerouslySetInnerHTML={{ __html: preview }}
/>
</div>
);
}
});
}

// Render the App component and mount it to the DOM
ReactDOM.render(
<App
code="# React Markdown Editor

* A list

Some **bold** and _italic_ text

> A quote...

ReactDOM.render(<App />, document.getElementById('app'));
By [Jed Watson](https://github.com/JedWatson) and [Joss Mackison)"
/>,
document.getElementById("app")
);
Loading