Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!