Adds the path information of an uploaded file.
File type ('image' | 'video' | 'file')
The uploaded path
editor.setEventListener('beforeUploadImage', (event) => {
const fileType = event.fileType;
const uploadCount = event.uploadCount;
const imageCount = editor
.getUploadedFiles(fileType)
.filter((info) => !info.isDeleted).length;
if (imageCount + uploadCount >= 5) {
event.returnValue = false;
}
});
Updates the stringified value of the original SEModel used to determine whether the editor body has changed, to match the current editing content.
Calling isDirty() immediately after this function will return false.
Destroys the editor.
Downloads all images in the editor body that match the specified URL pattern, then uploads them.
Calls callbackFunc when all uploads are complete.
Calling getPublishingHtml() inside callbackFunc returns HTML containing the updated image URLs.
If no pattern is specified, only callbackFunc is called and the method returns immediately.
OptionalcallbackFunc: (uploadResultMap: SynapEditorDownloadUploadResultMap) => voidCallback function invoked after upload is complete
OptionalurlPattern: string | RegExpURL pattern of images to download. If not specified, the pattern configured in the config file is used.
A Promise indicating upload completion
Executes an action.
Name of the action to execute
Arguments to pass to the action
The result object of the execution
Exports the editing content as a document file (docx, hwpx) and downloads it.
Notes:
Optionalname: stringFile name to save (default: 'untitled')
OptionalpageOrientation: "portrait" | "landscape"Page orientation ('portrait' | 'landscape', default: 'portrait')
OptionalexportFileFormat: stringFile format ('hwpx' | 'docx' | 'hwp', etc., default: 'hwpx')
A Promise indicating whether the file export operation completed
Returns an editable API model by ID.
For repeated edits, you can improve performance by using skipRendering: true and then calling render().
The element ID
Optionaloptions: SynapEditorAPIModelOptionsAPI model options
The API model
Returns editable API models based on the current selection.
Optionaloptions: SynapEditorAPIModelOptionsAPI model options
An array of API models
Returns editable API models matching the given CSS selector.
CSS selector
Optionaloptions: SynapEditorAPIModelOptionsAPI model options
An array of API models
Returns the body model JSON or a JSON string.
OptionaltoString: falseIf true, returns as a JSON string.
The body model JSON object or JSON string
Returns the HTMLElement at the given position.
Optionalposition: unknownPosition object. If omitted, uses the current selection's focus position.
The HTML element at the position, or null
Returns an array of HTMLElements based on the selection.
OptionalselectionObject: SynapEditorSelectionRangeLikeA selection object in the form { anchor, focus }. If omitted, uses the current selection.
An array of HTMLElements
Compares two body model JSONs or JSON strings and returns the changed parts as HTML.
The previous model (JSON object or JSON string)
The current model (JSON object or JSON string)
Optionaloptions: SynapEditorModelDiffOptionsComparison options (style settings, HTML options, etc.)
An HTML string showing the changed parts
const beforeBodyModel = editor.getBodyModelJSON();
const currentBodyModel = editor.getBodyModelJSON();
const result = editor.getModelDiffHTML(beforeBodyModel, currentBodyModel);
const beforeBodyModel = editor.getBodyModelJSON();
const currentBodyModel = editor.getBodyModelJSON();
const options = {
style: {
edit: {
color: 'rgba(144, 213, 235, 0.7)',
borderColor: 'rgb(93, 181, 209)'
}
}
};
const result = editor.getModelDiffHTML(beforeBodyModel, currentBodyModel, options);
Returns the publishing HTML.
Optionaloptions: SynapEditorGetPublishingHtmlOptionsPublishing options object
The publishing HTML string
Returns the API Selection.
The API Selection object
Returns the ID and text of the TableCell corresponding to the given field name.
The field name to search for
An array of { id, text } objects
Returns the TD or TH HTMLElement based on the current selection.
The focused table cell element, or null
Returns the table of contents model JSON.
OptionalshouldAssignId: booleanWhether to assign new IDs
A JSON array representing the hierarchical structure of the table of contents
Returns the table of contents model as an <ol> HTML list string.
OptionalshouldAssignId: booleanWhether to assign new IDs
The table of contents HTML string
Extracts text from the element matching the given CSS selector.
CSS selector
The text of the matching element, or null
// Collect text from multiple fields at once
const formData = {
name: editor.getText('#name'),
birth: editor.getText('#birth'),
address: editor.getText('#address'),
phone: editor.getText('#phone')
};
console.log('Collected form data:', formData);
// Check if a specific field is empty
const nameText = editor.getText('#name');
if (!nameText) {
alert('Please enter your name.');
}
Returns text information matching the given regular expression.
Regular expression object to search for
An array of matched text info { id, text, startIndex }
Returns an array of texts corresponding to the given CSS selectors.
An array of CSS selectors
An array of texts corresponding to each selector (null if the element does not exist)
const selectors = ['#name', '#email', '#phone'];
const texts = editor.getTextBySelectors(selectors);
const formData = { name: texts[0], email: texts[1], phone: texts[2] };
fetch('/api/save', {
method: 'POST',
body: JSON.stringify(formData)
});
Returns the content written in the editor as plain text.
Optionaloptions: SynapEditorGetTextContentOptionsText extraction options
The full text of the editor
// Extract text with emojis converted to HTML codes
const htmlCodeText = editor.getTextContent({ emoji: 'htmlcode' });
console.log('HTML code conversion:', htmlCodeText);
// Extract text with emojis preserved as Unicode
const unicodeText = editor.getTextContent({ emoji: 'unicode' });
console.log('Unicode conversion:', unicodeText);
// Extract plain text with emojis removed
const plainText = editor.getTextContent({ emoji: 'remove' });
console.log('Plain text:', plainText);
// Check the character count of the extracted text
const text = editor.getTextContent();
console.log('Total character count:', text.length);
Returns the list of uploaded files. If a file type is provided, returns the list for that type only. If no file type is provided, returns the list for all file types.
const filesData = editor.getUploadedFiles();
const imageFiles = editor.getUploadedFiles('image');
editor.setEventListener('beforeUploadImage', (event) => {
const fileType = event.fileType;
const uploadCount = event.uploadCount;
const imageCount = editor
.getUploadedFiles(fileType)
.filter((info) => !info.isDeleted).length;
if (imageCount + uploadCount >= 5) {
event.returnValue = false;
}
});
Returns the list of uploaded files. If a file type is provided, returns the list for that type only. If no file type is provided, returns the list for all file types.
const filesData = editor.getUploadedFiles();
const imageFiles = editor.getUploadedFiles('image');
editor.setEventListener('beforeUploadImage', (event) => {
const fileType = event.fileType;
const uploadCount = event.uploadCount;
const imageCount = editor
.getUploadedFiles(fileType)
.filter((info) => !info.isDeleted).length;
if (imageCount + uploadCount >= 5) {
event.returnValue = false;
}
});
Inserts HTML. If an ID is provided, inserts at the position corresponding to the ID and offset. If no ID is provided, inserts after the current selection's paragraph.
HTML string to insert
Optionalid: stringTarget element ID
Optionaloffset: numberPosition within the paragraph
OptionalforceRender: booleanWhether to render immediately (default: true)
Optionaloptions: SynapEditorInsertHTMLOptionsInsert options
The end position of the inserted element
Returns whether the editor is in source view mode.
Whether the editor is in source view mode
Returns true if there are changes in the editor body.
Whether the content has been changed
Checks whether the editor has been edited. Returns true if the undo stack is not empty. Resets when creating a new document or opening/importing (new insert).
Whether the editor has been edited
Returns whether the editor is in edit mode.
Whether the editor is in edit mode
Returns whether the editor has content.
Whether the content area is empty
Returns whether the editor is in preview mode.
Whether the editor is in preview mode
Opens directly with converted document data.
Document data object (docType, serializedData, importPath, etc.)
const DOC_TYPE = editor.constructor.CONST.DOC_TYPE
const data = {};
data.docType = DOC_TYPE.WORD;
data.serializedData = [10, 213, 156, ...];
data.importPath = "works/36a43f36f442b5824c6b061eb734553d";
data.name = "Editor Introduction.docx";
data.size = 71914;
window.editor.openDocumentByData(data);
Downloads and opens the document at the given URL. Due to CORS restrictions, only documents on the same server can be opened.
Document URL
Converts and opens a document via a server API.
Server API URL
Request parameters
Whether to overwrite existing content
Optionalheaders: Record<string, string>Request headers
Opens an HTML string.
HTML string to open
Optionaloptions: SynapEditorOpenHTMLOptionsOpen options
Opens an SEModel object or JSON.
Document or Body model / JSON object or JSON string
Optionaloptions: SynapEditorOpenSEModelOptionsOpen options
A Promise indicating open completion
Sets the HTML contents to be pasted.
Used to adjust clipboard data in the beforePaste event.
HTML string to paste
Sets a custom import function. When this function is set, it is called instead of the internal file import logic.
Custom import function
Sets a custom upload function.
When this function is set, it is called instead of the internal file upload logic.
The parameters passed from the editor to the custom function are file and fileType (image, video, file).
Custom upload function
Locks the element matching the given CSS selector.
CSS selector
Changes the editor mode.
Mode to switch to ('edit', 'preview', 'code', 'readonly')
Optionalcallback: () => voidCallback function invoked after the mode change is complete
Optionaloptions: SynapEditorSetModeOptionsMode change options
Sets text on multiple elements matching the given selectors in bulk.
An array of { selector, text } objects
Unlocks the element matching the given CSS selector.
CSS selector
Sets user information.
User information object
Updates the entire editing model based on the current body DOM.
Optionaloptions: SynapEditorAPIModelOptionsAPI model options
Updates the editing model of a specific element based on the changed DOM.
The element ID before the change
OptionalafterId: stringThe element ID after the change (if the ID was changed)
Optionaloptions: SynapEditorAPIModelOptionsAPI model options
Uploads all images included as base64 strings in the body.
When upload is complete, replaces the src in the HTML tag with the uploaded URL and calls callbackFunc.
Calling getPublishingHtml() inside callbackFunc returns the updated HTML tag.
OptionalcallbackFunc: () => voidCallback function invoked after upload is complete
A Promise indicating upload completion
Returns the body with an e-government document filter applied as a string.
Optionaloptions: SynapEditorXhtml4PubdocOptionsE-government document filter options
An HTML string with the filter applied
StaticaddStaticaddAdds messages. If a message with the same key already exists, it will be overwritten.
Language code (e.g., 'ko', 'en')
Message object to add
StaticgetReturns the icon resources.
The registered icon resource object
StaticgetReturns the messages for the specified language.
Language code (e.g., 'ko', 'en')
An object in the format { messageKey: message }
// Get Korean messages
const koMessages = SynapEditor.getMessages('ko');
console.log(koMessages);
// Get English messages
const enMessages = SynapEditor.getMessages('en');
console.log(enMessages);
// Set UI text with messages matching the current editor language
const lang = navigator.language.startsWith('ko') ? 'ko' : 'en';
const messages = SynapEditor.getMessages(lang);
document.getElementById('saveBtn').textContent = messages['save'] || 'Save';
SynapEditor Class.