Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda