SynapEditor API 3.3.0
    Preparing search index...

    Class SynapEditor

    SynapEditor Class.

    Index

    Constructors

    Methods

    • Adds the path information of an uploaded file.

      Parameters

      • fileType: SynapEditorFileType

        File type ('image' | 'video' | 'file')

      • uploadPath: string

        The uploaded path

      Returns void

      editor.addUploadPath('image', 'upload/path/filename.png');
      
      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.

      Returns void

      editor.clearDirty();
      console.log(editor.isDirty()); // false
      async function saveDocument() {
      const html = editor.getPublishingHtml();
      await fetch('/api/save', { method: 'POST', body: html });
      editor.clearDirty();
      console.log('Save complete, isDirty:', editor.isDirty()); // false
      }
    • Destroys the editor.

      Returns void

      // React example (call destroy on unmount)
      useEffect(() => {
      editorInstance = new SynapEditor();
      // Call the destroy function when leaving the page or when the component unmounts
      return () => {
      if (editorInstance) {
      editorInstance.destroy();
      editorInstance = null;
      }
      };
      }, []);
      // Clean up the editor on SPA page navigation
      function cleanupEditor() {
      if (editorInstance) {
      editorInstance.destroy();
      editorInstance = null;
      }
      }

      window.addEventListener('beforeunload', cleanupEditor);
    • 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.

      Parameters

      • OptionalcallbackFunc: (uploadResultMap: SynapEditorDownloadUploadResultMap) => void

        Callback function invoked after upload is complete

      • OptionalurlPattern: string | RegExp

        URL pattern of images to download. If not specified, the pattern configured in the config file is used.

      Returns Promise<void>

      A Promise indicating upload completion

      editor.downloadAndUploadImages(undefined, urlPattern).then(() => {
      const html = editor.getPublishingHtml();
      });
      const callback = () => {
      const html = editor.getPublishingHtml();
      };

      editor.downloadAndUploadImages(callback, urlPattern);
    • Executes an action.

      Parameters

      • actionName: string

        Name of the action to execute

      • ...args: unknown[]

        Arguments to pass to the action

      Returns unknown

      The result object of the execution

      var result = editor.execCommand('insertText', 'Hello SynapEditor');
      if (!result.isSuccess) {
      console.error(result.errorMessage);
      }
      const result = editor.execCommand('bold');
      if (result.isSuccess) {
      console.log('Bold applied successfully');
      } else {
      console.log('Failed to apply bold');
      }
    • Exports the editing content as a document file (docx, hwpx) and downloads it.

      Notes:

      • Identical representation and quality between the original imported document and the exported document is not guaranteed.
      • Due to the structural characteristics of the web editor environment, 1:1 matching with the original document format is difficult, which may cause some objects to be missing or displayed abnormally.

      Parameters

      • Optionalname: string

        File name to save (default: 'untitled')

      • OptionalpageOrientation: "portrait" | "landscape"

        Page orientation ('portrait' | 'landscape', default: 'portrait')

      • OptionalexportFileFormat: string

        File format ('hwpx' | 'docx' | 'hwp', etc., default: 'hwpx')

      Returns Promise<void>

      A Promise indicating whether the file export operation completed

      editor.exportFile('Editor Document', 'portrait', 'hwpx').then(() => {
      console.log('Export complete.');
      });
    • Returns an editable API model by ID. For repeated edits, you can improve performance by using skipRendering: true and then calling render().

      Parameters

      Returns unknown

      The API model

      const table = editor.getAPIModelById('ID');
      table.insertCol(1);
      table.insertRow(1);
      table.setWidth(400);
      const table = editor.getAPIModelById('ID', { skipUndoRedo: true });
      table.insertCol(1);
      table.insertRow(1);
      table.setWidth(400);
    • Returns editable API models based on the current selection.

      Parameters

      Returns unknown[]

      An array of API models

      const paragraph = editor.getAPIModels()[0];
      paragraph.append('<span>TEXT</span>');
      const paragraph = editor.getAPIModels({ skipUndoRedo: true })[0];
      paragraph.append('<span>APPEND TEXT</span>');
    • Returns editable API models matching the given CSS selector.

      Parameters

      Returns unknown[]

      An array of API models

      const body = editor.getAPIModelsBySelector('.se-contents')[0];
      body.append('<p><span>APPEND TEXT</span></p>');
      const body = editor.getAPIModelsBySelector('.se-contents', { skipUndoRedo: true })[0];
      body.append('<p><span>APPEND TEXT</span></p>');
    • Returns the body model JSON or a JSON string.

      Parameters

      • OptionaltoString: false

        If true, returns as a JSON string.

      Returns SynapEditorBodyModelJSON

      The body model JSON object or JSON string

      var model = editor.getBodyModelJSON();
      var model = editor.getBodyModelJSON(true); // Returns as a JSON string
      const modelStr = editor.getBodyModelJSON(true);
      fetch('/api/save-model', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ model: modelStr })
      });
    • Returns the body model JSON or a JSON string.

      Parameters

      • toString: true

        If true, returns as a JSON string.

      Returns string

      The body model JSON object or JSON string

      var model = editor.getBodyModelJSON();
      var model = editor.getBodyModelJSON(true); // Returns as a JSON string
      const modelStr = editor.getBodyModelJSON(true);
      fetch('/api/save-model', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ model: modelStr })
      });
    • Returns the Document of the editor content area.

      Returns Document

      The Document object of the editor content area

      var contentsDocument = editor.getContentsDocument();
      var element = contentsDocument.getElementById('id');
      const doc = editor.getContentsDocument();
      const style = doc.createElement('style');
      style.textContent = '.highlight { background-color: yellow; }';
      doc.head.appendChild(style);
    • Returns the HTMLElement at the given position.

      Parameters

      • Optionalposition: unknown

        Position object. If omitted, uses the current selection's focus position.

      Returns HTMLElement

      The HTML element at the position, or null

      const element = editor.getHTMLElement();
      console.log(element?.innerHTML);
      const selection = editor.getSelection();
      const startElement = editor.getHTMLElement(selection.start);
      const endElement = editor.getHTMLElement(selection.end);

      console.log(startElement?.innerHTML);
      console.log(endElement?.innerHTML);
    • Returns an array of HTMLElements based on the selection.

      Parameters

      Returns HTMLElement[]

      An array of HTMLElements

      const elements = editor.getHTMLElements();
      console.log(elements[0]?.innerHTML);
      const selection = editor.getSelection();
      const elements = editor.getHTMLElements(selection);

      console.log(elements[0]?.innerHTML);
    • Compares two body model JSONs or JSON strings and returns the changed parts as HTML.

      Parameters

      Returns string

      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.

      Parameters

      Returns string

      The publishing HTML string

      const html = editor.getPublishingHtml();
      
      const plainHtml = editor.getPublishingHtml({ wrap: false });
      const documentHtml = editor.getPublishingHtml({ contentPadding: 'document' });
      const scopedHtml = editor.getPublishingHtml({ selector: '#test' });
    • Returns the API Selection.

      Returns unknown

      The API Selection object

      const selection = editor.getSelection();
      const { start, end, anchor, focus } = selection;
      const selection = editor.getSelection();
      const anchorType = selection.anchor.getType();
      const focusType = selection.focus.getType();
    • Returns the ID and text of the TableCell corresponding to the given field name.

      Parameters

      • fieldName: string

        The field name to search for

      Returns SynapEditorTableCellData[]

      An array of { id, text } objects

      var tableCellData = editor.getTableCellDataByFieldName('test');
      // [{ id: "cell_2", text: "2" }, { id: "cell_4", text: "4" }]
      const nameData = editor.getTableCellDataByFieldName('name');
      const emailData = editor.getTableCellDataByFieldName('email');
      const formData = {
      name: nameData.map(d => d.text),
      email: emailData.map(d => d.text)
      };
    • Returns the TD or TH HTMLElement based on the current selection.

      Returns HTMLTableCellElement

      The focused table cell element, or null

      const td = editor.getTableCellHTMLElement();
      td.innerHTML = "This is a table cell.";
      const td = editor.getTableCellHTMLElement();
      if (td) {
      td.style.backgroundColor = '#f0f0f0';
      editor.render();
      }
    • Returns the table of contents model JSON.

      Parameters

      • OptionalshouldAssignId: boolean

        Whether to assign new IDs

      Returns SynapEditorTableOfContentsModel[]

      A JSON array representing the hierarchical structure of the table of contents

      const model = editor.getTableOfContentsModelJSON();
      const prefixedModel = editor.getTableOfContentsModelJSON(true);
      editor.getTableOfContentsModelJSON(true);
      editor.updateTableOfContentsIds();
    • Returns the table of contents model as an <ol> HTML list string.

      Parameters

      • OptionalshouldAssignId: boolean

        Whether to assign new IDs

      Returns string

      The table of contents HTML string

      // Get HTML list
      const html = editor.getTableOfContentsModelListHTML(true);
      console.log(html);
      // Synchronize IDs between TOC elements in content and the TOC model
      editor.getTableOfContentsModelListHTML();
      editor.updateTableOfContentsIds();
      const tocHtml = editor.getTableOfContentsModelListHTML(true);
      const sidebar = document.getElementById('sidebar-toc');
      sidebar.innerHTML = tocHtml;
    • Extracts text from the element matching the given CSS selector.

      Parameters

      • selector: string

        CSS selector

      Returns string

      The text of the matching element, or null

      const text = editor.getText('#field');
      
      // 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.

      Parameters

      • regExp: RegExp

        Regular expression object to search for

      Returns SynapEditorTextByRegexInfo[]

      An array of matched text info { id, text, startIndex }

      const textInfoList = editor.getTextByRegex(/\+제\d+\([가-힣\s\d\w]+\)/g);
      
      const textInfoList = editor.getTextByRegex(/\+제\d+\([가-힣\s\d\w]+\)/g);

      textInfoList.forEach((textInfo) => {
      editor.execCommand('setCaretById', textInfo.id);
      editor.execCommand('insertBookmark', textInfo.text);
      });
    • Returns an array of texts corresponding to the given CSS selectors.

      Parameters

      • selectors: string[]

        An array of CSS selectors

      Returns string[]

      An array of texts corresponding to each selector (null if the element does not exist)

      texts = editor.getTextBySelectors(selectors);
      
      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.

      Parameters

      Returns string

      The full text of the editor

      const text = editor.getTextContent();
      
      // 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.

      Returns SynapEditorUploadedFilesMap

      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.

      Parameters

      Returns SynapEditorUploadedFileInfo[]

      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.

      Parameters

      • html: string

        HTML string to insert

      • Optionalid: string

        Target element ID

      • Optionaloffset: number

        Position within the paragraph

      • OptionalforceRender: boolean

        Whether to render immediately (default: true)

      • Optionaloptions: SynapEditorInsertHTMLOptions

        Insert options

      Returns unknown

      The end position of the inserted element

      const html = '<svg ...></svg>';
      editor.insertHTML(html);
      const html = 'html Content';
      editor.insertHTML(html, id, offset);
    • Returns whether the editor is in source view mode.

      Returns boolean

      Whether the editor is in source view mode

      if (editor.isCodeViewMode()) {
      editor.setMode('edit');
      }
      function getCurrentMode() {
      if (editor.isCodeViewMode()) {
      return 'Source view mode';
      } else if (editor.isEditMode()) {
      return 'Edit mode';
      }
      return 'Preview mode';
      }
    • Returns true if there are changes in the editor body.

      Returns boolean

      Whether the content has been changed

      if (editor.isDirty()) {
      console.log('There are unsaved changes.');
      }
      editor.setEventListener('contentChanged', () => {
      const saveButton = document.getElementById('saveBtn');
      saveButton.disabled = !editor.isDirty();
      });
    • 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).

      Returns boolean

      Whether the editor has been edited

      var html;
      if(!editor.isEdited()) {
      html = editor.getPublishingHtml();
      }
      window.addEventListener('beforeunload', (event) => {
      if (editor.isEdited()) {
      event.preventDefault();
      event.returnValue = 'You have unsaved changes. Are you sure you want to leave?';
      }
      });
    • Returns whether the editor is in edit mode.

      Returns boolean

      Whether the editor is in edit mode

      if (editor.isEditMode()) {
      editor.insertHTML('Hello SynapEditor~');
      }
      function handleSave() {
      if (editor.isEditMode()) {
      const html = editor.getPublishingHtml();
      fetch('/api/save', { method: 'POST', body: html });
      } else {
      editor.setMode('edit');
      }
      }
    • Returns whether the editor has content.

      Returns boolean

      Whether the content area is empty

      var html;
      if(!editor.isEmpty()) {
      html = editor.getPublishingHtml();
      }
      function saveDocument() {
      if (editor.isEmpty()) {
      alert('Please enter some content.');
      return;
      }
      const html = editor.getPublishingHtml();
      fetch('/api/save', {
      method: 'POST',
      body: JSON.stringify({ content: html })
      });
      }
    • Returns whether the editor is in preview mode.

      Returns boolean

      Whether the editor is in preview mode

      if (editor.isPreviewMode()) {
      editor.setMode('edit');
      }
      function togglePreview() {
      if (editor.isPreviewMode()) {
      editor.setMode('edit');
      } else {
      editor.setMode('preview');
      }
      }
    • Opens directly with converted document data.

      Parameters

      Returns void

      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);
      fetch('/api/convert', { method: 'POST', body: formData })
      .then(response => response.json())
      .then(data => {
      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.

      Parameters

      • url: string

        Document URL

      Returns void

      const url = '/resource/test.docx';
      editor.openDocumentByURL(url);
      function loadTemplate(templateName: string) {
      const url = `/resource/template/${templateName}.docx`;
      editor.openDocumentByURL(url);
      }
    • Converts and opens a document via a server API.

      Parameters

      • api: string

        Server API URL

      • params: SynapEditorServerOpenParams

        Request parameters

      • bOverwrite: boolean

        Whether to overwrite existing content

      • Optionalheaders: Record<string, string>

        Request headers

      Returns void

      const api = './importOnServer';
      const params = { path: 'D:\\test.docx' };
      const overwrite = true;
      editor.openDocumentOnServer(api, params, overwrite);
      const api = './importOnServer';
      const params = new FormData();
      params.append('file', docFile);
      const headers = { 'Authorization': 'Bearer token123' };
      editor.openDocumentOnServer(api, params, false, headers);
    • Opens an HTML string.

      Parameters

      Returns void

      const html = "<H1>Synap Editor</H1><P>Holistic Rich Text Editor</P>";
      editor.openHTML(html);
      const html = '<h1>Title</h1><p>Body content.</p>';
      editor.openHTML(html, {
      callback: () => {
      console.log('HTML loaded successfully');
      },
      bFocus: true
      });
    • Opens an SEModel object or JSON.

      Parameters

      Returns Promise<void>

      A Promise indicating open completion

      const json = editor.getBodyModelJSON();
      editor.openSEModel(json);
      const jsonStr = editor.getBodyModelJSON(true);
      editor.openSEModel(jsonStr);
      fetch('/api/document/123')
      .then(response => response.json())
      .then(data => {
      editor.openSEModel(data.bodyModel);
      });
    • Performs rendering if there are changed models.

      Returns void

      var table = editor.getAPIModelById('ID', { skipRendering : true });
      table.insertCol(1);
      table.insertRow(1);
      table.setWidth(400);
      editor.render();
      const table = editor.getAPIModelById('tableId', { skipRendering: true });
      table.insertRow(2);
      table.insertCol(3);
      editor.render();
    • Sets the HTML contents to be pasted. Used to adjust clipboard data in the beforePaste event.

      Parameters

      • html: string

        HTML string to paste

      Returns void

      editor.setEventListener('beforePaste', function(data) {
      var html = data.clipboardData.html;
      var text = data.clipboardData.text;
      var data = html ? html : getHTMLString(text);
      editor.setContentsToPaste('<h1>SynapEditor</h1>' + data);
      });
      editor.setEventListener('beforePaste', (data) => {
      let html = data.html;
      // Remove external styles before pasting
      html = html.replace(/style="[^"]*"/g, '');
      editor.setContentsToPaste(html);
      });
    • Sets a custom import function. When this function is set, it is called instead of the internal file import logic.

      Parameters

      Returns void

      editor.setCustomImportFunction((docFile, bOverwrite) => {
      return {
      serializedData,
      importPath,
      importImageMap
      };
      });
      editor.setCustomImportFunction(async (docFile, bOverwrite) => {
      return Promise.resolve({ serializedData, importPath, importImageMap });
      });
    • 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).

      Parameters

      Returns void

      editor.setCustomUploadFunction((file, uploadFileType) => {
      const url = '/uploads/image.png';
      return url;
      });
      editor.setCustomUploadFunction(async (file, uploadFileType) => {
      const url = await Promise.resolve('/uploads/image.png');
      return url;
      });
    • Locks the element matching the given CSS selector.

      Parameters

      • selector: string

        CSS selector

      Returns void

      window.editor.setLock('#lock_element_Id');
      window.editor.setLock('.not_editable');
      // Lock the signature area and copyright area
      editor.setLock('#signature_area');
      editor.setLock('#copyright_notice');
    • Changes the editor mode.

      Parameters

      • mode: string

        Mode to switch to ('edit', 'preview', 'code', 'readonly')

      • Optionalcallback: () => void

        Callback function invoked after the mode change is complete

      • Optionaloptions: SynapEditorSetModeOptions

        Mode change options

      Returns void

      if (editor.isPreviewMode()) {
      editor.setMode('edit');
      } else {
      editor.setMode('preview');
      }
      const callback = () => {
      console.log('done');
      };

      editor.setMode('edit', callback);
    • Sets text on the element matching the given CSS selector.

      Parameters

      • selector: string

        CSS selector

      • text: string

        Text to set

      Returns void

      window.editor.setText('#field', 'Field Text');
      window.editor.setText('#name', 'Name Text');
      const fields = { '#name': 'Hong Gildong', '#email': 'hong@example.com', '#phone': '010-1234-5678' };
      Object.entries(fields).forEach(([selector, text]) => {
      editor.setText(selector, text);
      });
    • Sets text on multiple elements matching the given selectors in bulk.

      Parameters

      Returns void

      window.editor.setTextBySelectors([
      { selector: '#field', text: 'Field Text' },
      { selector: '#name', text: 'Name Text' }
      ]);
      fetch('/api/user/profile')
      .then(res => res.json())
      .then(data => {
      editor.setTextBySelectors([
      { selector: '#name', text: data.name },
      { selector: '#email', text: data.email },
      { selector: '#phone', text: data.phone }
      ]);
      });
    • Unlocks the element matching the given CSS selector.

      Parameters

      • selector: string

        CSS selector

      Returns void

      window.editor.setUnlock('#unlock_element_Id');
      window.editor.setUnlock('.editable');
      if (userRole === 'admin') {
      editor.setUnlock('#signature_area');
      editor.setUnlock('#copyright_notice');
      }
    • Sets user information.

      Parameters

      Returns void

      window.editor.setUserInfo({
      id: 'editor',
      name: 'editor',
      color:'#3C39B8',
      userData: {
      userId: 'userId',
      connected: Date.now(),
      profileImage:'/img/path.png'
      }
      });
      fetch('/api/user/me')
      .then(res => res.json())
      .then(user => {
      editor.setUserInfo({
      id: user.id,
      name: user.displayName,
      color: user.themeColor,
      userData: { department: user.department }
      });
      });
    • Updates the entire editing model based on the current body DOM.

      Parameters

      Returns void

      const paragraphs = document.querySelectorAll('.se-contents p');
      paragraphs.forEach(function(para, index){ para.innerText = index + 'test'; });
      editor.updateBodyModel();
      const doc = editor.getContentsDocument();
      const paragraphs = doc.querySelectorAll('.se-contents p');
      paragraphs.forEach(p => {
      p.style.lineHeight = '1.8';
      });
      editor.updateBodyModel();
    • Updates the editing model of a specific element based on the changed DOM.

      Parameters

      • beforeId: string

        The element ID before the change

      • OptionalafterId: string

        The element ID after the change (if the ID was changed)

      • Optionaloptions: SynapEditorAPIModelOptions

        API model options

      Returns void

      const paragraph = document.getElementById('p1');
      if (paragraph) {
      paragraph.innerText = 'Updating the text.';
      editor.updateModel('p1');
      }
      const paragraph = document.getElementById('p1');
      if (paragraph) {
      paragraph.id = 'p2';
      paragraph.innerText = 'Updating the text.';
      editor.updateModel('p1', 'p2');
      }
    • 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.

      Parameters

      • OptionalcallbackFunc: () => void

        Callback function invoked after upload is complete

      Returns Promise<void>

      A Promise indicating upload completion

      editor.uploadBase64Images().then(() => {
      editor.getPublishingHtml();
      });
      const callback = () => {
      editor.getPublishingHtml();
      };

      editor.uploadBase64Images(callback);
    • Returns the body with an e-government document filter applied as a string.

      Parameters

      Returns string

      An HTML string with the filter applied

      var pubdoc = editor.xhtml4pubdoc();
      var pubdocOption = editor.xhtml4pubdoc({applyFirstTextStyle: ['fontSize', 'color']});
      const pubdoc = editor.xhtml4pubdoc({ applyFirstTextStyle: ['fontSize', 'color'] });
      fetch('/api/pubdoc', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ content: pubdoc })
      });
    • Adds icon resources. If an icon with the same name already exists, it will be overwritten.

      Parameters

      • icons: Record<string, string>

        Icon resource object to add

      Returns void

      const iconResources = {
      image: '<img ...>',
      bold: '<svg ...>'
      };

      SynapEditor.addIcons(iconResources);
      const customIcons = {
      bold: '<img src="/assets/bold.png" />',
      italic: '<svg ...></svg>'
      };

      SynapEditor.addIcons(customIcons);
      const editor = new SynapEditor('synapEditor', synapEditorConfig);
    • Adds messages. If a message with the same key already exists, it will be overwritten.

      Parameters

      • language: string

        Language code (e.g., 'ko', 'en')

      • messages: Record<string, string>

        Message object to add

      Returns void

      const messages = {
      'myPlugin.message.synap': '사이냅',
      'myPlugin.message.editor': '에디터'
      };

      SynapEditor.addMessages('ko', messages);
      const changedMessages = {
      'message.label.bold': '★두껍게★',
      'message.label.italic': '♧이탤릭♧'
      };

      SynapEditor.addMessages('ko', changedMessages);
      const editor = new SynapEditor('synapEditor', synapEditorConfig);
    • Returns the icon resources.

      Returns Record<string, string>

      The registered icon resource object

      const icons = SynapEditor.getIcons();
      
      const icons = SynapEditor.getIcons();
      if (icons['bold']) {
      console.log('The bold icon is registered.');
      }
    • Returns the messages for the specified language.

      Parameters

      • language: string

        Language code (e.g., 'ko', 'en')

      Returns Record<string, string>

      An object in the format { messageKey: message }

      const language = 'ko';
      const messages = SynapEditor.getMessages(language);
      // 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';