🚀 Getting Started

The Project Setup

TOAST UI Editor can be used by using the package manager or downloading the source directly. However, we highly recommend using the package manager.

Via Package Manager (npm)

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.

  1. $ npm install --save @toast-ui/editor # Latest Version
  2. $ 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:

  1. - node_modules/
  2. ├─ @toast-ui/editor/
  3. ├─ dist/
  4. ├─ toastui-editor.js
  5. ├─ toastui-editor-viewer.js
  6. ├─ toastui-editor.css
  7. ├─ toastui-editor-viewer.css
  8. └─ toastui-editor-only.css

Via Contents Delivery Network (CDN)

TOAST UI Editor is available over the CDN powered by NHN Cloud. You can use the CDN as below.

  1. ...
  2. <body>
  3. ...
  4. <script src="https://uicdn.toast.com/editor/latest/toastui-editor-all.min.js"></script>
  5. </body>
  6. ...

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:

  1. - uicdn.toast.com/
  2. ├─ editor/
  3. ├─ latest/
  4. ├─ toastui-editor-all.js
  5. ├─ toastui-editor-all.min.js
  6. ├─ toastui-editor-viewer.js
  7. ├─ toastui-editor-viewer.min.js
  8. ├─ toastui-editor-editor.js
  9. ├─ toastui-editor-editor.min.js
  10. ├─ toastui-editor-editor.css
  11. ├─ toastui-editor-editor.min.css
  12. ├─ toastui-editor-viewer.css
  13. └─ toastui-editor-viewer.min.css
  14. ├─ 2.0.0/
  15. └─ ...

Create Your First Editor

Adding the Wrapper Element

You need to add the container element where TOAST UI Editor (henceforth referred to as ‘Editor’) will be created.

  1. ...
  2. <body>
  3. <div id="editor"></div>
  4. </body>
  5. ...

Importing the Editor’s Constructor Function

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.

Using Module Format in Node Environment

  • ES6 Modules
  1. import Editor from '@toast-ui/editor';
  • CommonJS
  1. const Editor = require('@toast-ui/editor');

Using Namespace in Browser Environment

  1. const Editor = toastui.Editor;

Adding CSS Files

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.

Using in Node Environment

  • ES6 Modules
  1. import '@toast-ui/editor/dist/toastui-editor.css'; // Editor's Style
  • CommonJS
  1. require('@toast-ui/editor/dist/toastui-editor.css');

Using in Browser Environment by CDN

  1. ...
  2. <head>
  3. ...
  4. <!-- Editor's Style -->
  5. <link rel="stylesheet" href="https://uicdn.toast.com/editor/latest/toastui-editor.min.css" />
  6. </head>
  7. ...

Creating Instance

You can create an instance with options and call various API after creating an instance.

  1. const editor = new Editor({
  2. el: document.querySelector('#editor')
  3. });

getting-started-01

  1. const editor = new Editor({
  2. el: document.querySelector('#editor'),
  3. height: '600px',
  4. initialEditType: 'markdown',
  5. previewStyle: 'vertical'
  6. });

getting-started-02

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 string
  • previewStyle: 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.

Example

You can see the example here.