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

149
Vistas
CKEditor 5 keep custom html elements (upcast/downcast)

I followed ckeditor 5 tutorial on creating block widget

Everything works fine and i am able to create a widget with parent container, containing an h1 and div elements with custom text etc.

My current model in the editor console:

enter image description here

With view:

enter image description here

This works great (using the exact implementation described in the link). However, what i am trying to achieve is that when fetching html from ckeditor instead of the parent div.doppio-block i get a custom element <doppio-block>. So something like this:

    <doppio-block>
<h1 class='doppio-block-class'></h1>
<div class='doppio-block-body'></div>
</doppio-block>

I tried changing the parent container conversion in editing.js (by making sure doppio-block element is created instead of a div)

conversion.for('upcast').elementToElement({
    model: 'doppio-block',
    view: {
        name: 'doppio-block',
        classes: 'doppio-block'
    }
});

// DATA downcast: HTML5 to MODEL
conversion.for('dataDowncast').elementToElement({
    view: {
        name: 'doppio-block',
        classes: 'doppio-block'
    },
    model: 'doppio-block',
});

conversion.for('editingDowncast').elementToElement({
    model: 'doppio-block',
    view: (modelElement, { writer: viewWriter }) => {

        const section = viewWriter.createContainerElement('doppio-block', { class: 'doppio-block' });
        return toWidget(section, viewWriter, { label: 'doppio block' });
    }
});

This works when initially creating the widget, but the rendering is messed up when pre-loading the ckeditor, which renders model:

enter image description here

And view:

enter image description here

I think my issue is somewhere with upcasting or downcasting, but cannot figure it out.

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