NHN Cloud UI Editor can be used by using the package manager or downloading the source directly. However, we highly recommend using the package manager.
You can conveniently install it using the commands provided by each package manager. When using npm, be sure to use it in the environment Node.js is installed.
$ npm install --save @toast-ui/editor # Latest Version
$ npm install --save @toast-ui/editor@<version> # Specific Version
When installed and used with npm, the list of files that can be imported is as follows:
- node_modules/
├─ @toast-ui/editor/
│ ├─ dist/
│ │ ├─ toastui-editor.js
│ │ ├─ toastui-editor-viewer.js
│ │ ├─ toastui-editor.css
│ │ ├─ toastui-editor-viewer.css
│ │ └─ toastui-editor-only.css
NHN Cloud UI Editor is available over the CDN powered by NHN Cloud Cloud. You can use the CDN as below.
...
<body>
...
<script src="https://uicdn.toast.com/editor/latest/toastui-editor-all.min.js"></script>
</body>
...
If you want to use a specific version, use the tag name instead of latest
in the url's path.
The CDN directory has the following structure:
- uicdn.toast.com/
├─ editor/
│ ├─ latest/
│ │ ├─ toastui-editor-all.js
│ │ ├─ toastui-editor-all.min.js
│ │ ├─ toastui-editor-viewer.js
│ │ ├─ toastui-editor-viewer.min.js
│ │ ├─ toastui-editor-editor.css
│ │ ├─ toastui-editor-editor.min.css
│ │ ├─ toastui-editor-viewer.css
│ │ └─ toastui-editor-viewer.min.css
│ ├─ 2.0.0/
│ │ └─ ...
You need to add the container element where NHN Cloud UI Editor (henceforth referred to as 'Editor') will be created.
...
<body>
<div id="editor"></div>
</body>
...
The editor can be used by creating an instance with the constructor function. To get the constructor function, you should import the module using one of the following ways depending on your environment.
import Editor from "@toast-ui/editor";
const Editor = require("@toast-ui/editor");
const Editor = toastui.Editor;
You need to add the CSS files needed for the Editor. Import CSS files in node environment, and add it to html file when using CDN. When using the markdown editor, you need to add a style for the CodeMirror.
import "codemirror/lib/codemirror.css"; // Editor's Dependency Style
import "@toast-ui/editor/dist/toastui-editor.css"; // Editor's Style
require("codemirror/lib/codemirror.css");
require("@toast-ui/editor/dist/toastui-editor.css");
...
<head>
...
<!-- Editor's Dependecy Style -->
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/codemirror.min.css"
/>
<!-- Editor's Style -->
<link
rel="stylesheet"
href="https://uicdn.toast.com/editor/latest/toastui-editor.min.css"
/>
</head>
...
You can create an instance with options and call various API after creating an instance.
const editor = new Editor({
el: document.querySelector("#editor"),
});
const editor = new Editor({
el: document.querySelector("#editor"),
height: "600px",
initialEditType: "markdown",
previewStyle: "vertical",
});
editor.getHtml();
The basic options available are:
height
: Height in string or auto ex) 300px
| auto
initialEditType
: Initial type to show markdown
| wysiwyg
initialValue
: Initial value. Set Markdown stringpreviewType
: Preview style of Markdown mode tab
| vertical
usageStatistics
: Let us know the hostname. We want to learn from you how you are using the editor. You are free to disable it. true
| false
Find out more options here.
You can see the example here.