Warm tip: This article is reproduced from stackoverflow.com, please click
ckeditor5 javascript vue.js

How to insert custom HTML tag into ckeditor5

发布于 2020-06-28 13:15:53

I have ckeditor and few images (emoji), and I want to insert html tag of clicked image in ckeditor. I have tried solutions of this problem, but didn't get any result. I know that it is not allowed directly from ckeditor and it is not secure.

Vue.js component

<div class="emoji">
    <img @click="sendEmoji($event)" src="/assets/images/facebook/expressionless-face_1f611.png" alt="emoji">
</div>
<textarea id="comment_editor"></textarea>

    <script>
     export default {
      mounted() {
        ClassicEditor
            .create( document.querySelector( '#comment_editor' ), {
              toolbar: {
                items: [
                  'bold',
                  'italic',
                  'underline',
                  'link',
                  'fontColor',
                  'fontSize',
                  'fontFamily',
                  'codeBlock',
                  'specialCharacters',
                  'superscript',
                  'subscript',
                ]
              },
              language: 'ru',
              licenseKey: '',

            } )
            .then( comment_editor => {
              window.comment_editor = comment_editor;
            } )
            .catch( error => {
              console.error( 'Oops, something gone wrong!' );
              console.error( 'Please, report the following error in the https://github.com/ckeditor/ckeditor5 with the build id and the error stack trace:' );
              console.warn( 'Build id: 1elt9gdr81je-u3jmkfuwv026' );
              console.error( error );
            } );
        },
        methods: {
          sendEmoji: function(event){
            let img = event.target.outerHTML;
            console.log(img);
            window.comment_editor.setData(img)
            console.log(window.comment_editor.getData());
          },
        }
    }
Questioner
Narek
Viewed
23
Narek 2020-04-13 23:05

Solved. Just need to add Image plugin. It looks ugly, but I think it's fixable.