Prevent CKEditor image-importer from automatically including dimensions

Is there a way to stop CKEditor from automatically adding sizes when importing an image? I would prefer to have control over the sizing. For instance, instead of this: Example 1

I'd like it to be like this:

Example 2

Any suggestions on how to prevent the image importer from automatically setting sizes?

Answer №1

Check out this code snippet that removes the width and height attributes from image tags and style tags to ensure responsiveness by adding a specific class to the image.

CKEDITOR.config.disallowedContent = 'img{width,height}';

CKEDITOR.on('instanceReady', function (ev) {
    ev.editor.dataProcessor.htmlFilter.addRules({
        elements: {
            $: function(element) {
                if (element.name == 'img') {
                    if (element.attributes.style) {
                        element.attributes.style = element.attributes.style.replace(/(height|width)[^;]*;/gi, '');
                    }
                }
                if (!element.attributes.style) {
                    delete element.attributes.style;
                }

                return element;
            }
        }
    });
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Troubleshooting the malfunction of the CSS display property

I've created a div with a number displayed initially. When I hover over the div, the number disappears and a paragraph is revealed. Upon hovering out, the paragraph hides and the number reappears. My attempts to achieve this using CSS (display: none ...

Angular controller makes several $http requests to a cross-origin REST API

I'm currently attempting to make multiple GET requests to my own REST API built in Java using Spring. Out of every 10 times, both requests are handled successfully 3 times and 7 times one of the HTTP requests fails with a 'No Access-Control-Allow ...

Material UI Grid's layout does not support placing a select element within a row

As a newcomer in the world of full stack development, I am delving into coding projects to enhance my understanding of frontend technologies like React JS and Material UI. My latest endeavor involves creating a page that displays posts from the backend in ...

Utilizing Firebase Cloud Messaging for push notifications in Twilio Conversations

I am currently facing a challenge in setting up push notifications using Twilio Conversations and Firebase Cloud Messaging on a Next.js 12 app. The documentation assumes the use of Firebase 8 syntax, but I am working with Firebase 9 in this case. I have be ...

Customize the select option in HTML to hide the default arrow and provide additional spacing for the options

I am dealing with a select option markup that looks like this <div class="styleselect"> <select onchange="setLocation(this.value)" class="selections"> <option selected="selected" value="position">Position</option> <opt ...

The animation is not updating quickly enough

I'm working on a navigation bar that sticks to the top of the page. As the user scrolls down, I want the bar to shrink, and when they scroll back up, it should return to its original size. Issue: The problem I'm facing is that when the user quic ...

Leverage the Power of Mongoose Schema Across Various Files (mongoose)

I recently encountered an issue while trying to utilize my Permissions schema in two different files. The error message "Cannot overwrite 'example' model once compiled" keeps popping up. Query: How can I effectively employ my Permissions schema ...

Unable to locate module using absolute import in a Next.js + TypeScript + Jest setup

Currently in my NextJS project, I am utilizing absolute imports and testing a component with Context Provider. The setup follows the instructions provided in this jest setup guide TEST: import { render, screen } from 'test-util'; import { Sideb ...

Issues encountered with loading rewarded video ad due to varying errors specific to each device

I've been encountering issues while trying to display rewarded video ads in my app. Every time I attempt to load the ad, it immediately goes to the "failed to load ad" method. On my phone, the error message reads: W/Ads: Fail to instantiate adapter ...

The data retrieved using Ionic 3 Angular Fire's payload.val() seems to be returning

Is it possible to determine whether a profile is filled in or empty when using Firebase Database for storing profile information? Currently, I am utilizing profile.payload.val(), but it seems to return null in both cases instead of true when the profile is ...

Leveraging useContext to alter the state of a React component

import { createContext, useState } from "react"; import React from "react"; import axios from "axios"; import { useContext } from "react"; import { useState } from "react"; import PermIdentityOutlinedIcon f ...

Eliminating replicated vertices in a Three.js geometry model

I'm struggling with removing duplicate vertices from a SphereGeomerty. I need to eliminate the seam on one side of the geometry as it doesn't align properly when updating the vertex positions. The issue arises when attempting to create a new geo ...

Error in template loading

Currently, I am going through the Angular.js tutorial to learn how to incorporate some of its advanced features into my existing applications. Everything has been smooth sailing until I reached the (angular route) section. Unfortunately, I've hit a ro ...

Looking to conduct date comparisons within angular-ui-grid?

I'm currently working on an application that utilizes angular-ui-grid to display form data. One issue I'm facing is how to compare the submission date obtained from an API call with the current date within ui-grid, in order to calculate the numbe ...

Utilizing Vue to link data to an input field

I am struggling with a loop of input elements <li v-for="role in ..."> {{-some html-}} </li> Each input is nested inside the loop as shown below <input type="text" :data-some="role.name" :value="role.name" name="name" ....> While ...

Eliminate forward slashes from the telephone number

I am trying to figure out how to format a USA phone number by removing slashes and brackets. I have searched on Google, but I cannot find the answer. I would like to use regex to achieve this, while keeping the plus sign at the start intact. For example, ...

"Exploring the Intersection of Meteor, NPM Packages, and Fiber Callbacks

I am currently utilizing request and cheerio to extract specific content, particularly a quote, from a website. Here is the code snippet ( server.js ) : q = new Mongo.Collection('quotelist'); postList = new Mongo.Collection('quotes&apos ...

Move router parameters to separate files to streamline and organize code

I have encountered a bit of an issue. I currently have the following code in my routing.js file where I define both my parameter and route. I have moved the routes to a separate router instance in my routing.js file, but I am struggling to separate the par ...

a guide on dynamically determining the value within a text input field

Does anyone know how to use jQuery to calculate values in a textbox for an invoice? I am not very familiar with jQuery and would appreciate any help in solving this issue. Within my invoice, there is a quantity textbox. If a user enters a quantity, th ...

Pulling and showcasing an object in Angular using a remote AJAX call

I am attempting to display an object retrieved remotely through AJAX. The current error I am facing is: ReferenceError: $stateParams is not defined Below is the snippet from services.js: .factory('Games', function() { var games = $.ajax({ ...