Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

218
Vistas
How add audio(custom) tag in ckeditor5

Plugin:

export default class AudioUploader extends Plugin {

  static get pluginName() {
    return 'AudioUploader';
  }

  static get requires() {
    return [];
  }

  init() {
    const editor = this.editor;
    const schema = editor.model.schema;

    schema.register('audio', {
      allowIn: ['$root', '$block', 'blockQuote', 'paragraph'],
      isBlock: true,
      allowAttributes: ['controls', 'src'],
    });

    editor.conversion.elementToElement({
      model: 'audio',
      view: {
        name: 'audio',
      },
    });

    editor.conversion.for( 'dataDowncast' ).elementToElement({
      model: 'audio',
      view: {
        name: 'audio',
      },
    });

    editor.conversion.for( 'upcast' ).elementToElement({
      model: 'audio',
      view: {
        name: 'audio',
      },
    });

    editor.ui.componentFactory.add('AudioUploader', () => {
      const view = new FileDialogButtonView();

      view.buttonView.set({
        tooltip: 'Добавить аудио',
        icon: MusicIcon,
      });

      view.on('done', (evt, files) => {
        getBase64(Array.from(files)[0], (audio) => {
          editor.model.change(writer => {
            const elem = writer.createElement('audio', {
              src: audio,
              controls: true,
            });

            editor.model.insertContent(elem, editor.model.document.selection.getFirstPosition());
          });
        });
      });

      return view;
    });
  }
}

enter image description here

enter image description here

If you insert just text(writer.insertText('some text', editor.model.document.selection.getFirstPosition());), then everything will be inserted correctly.

Everything is correct in the ckeditor5 inspector. I don’t understand the philosophy of adding arbitrary tags to the editor.

Why isn't it showing up in the editor? Why is the content not correct in console?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda