Rails application encounters issue where CKEditor is removing style elements from span classes

In my current setup using Rails 4.1.4, Ruby 2.1.2, and CKEditor 4.1.1 integrated with Rails Admin, I am facing an issue. Whenever I enter text in the CKEditor text area and apply a font or font size, it saves successfully. However, upon viewing the content, instead of seeing

<span style="font-size 36pt">text</span>
, I only see <span>text</span>.

I have experimented with both config.allowedContent = true; and

config.extraAllowedContent = 'style;*[id,rel](*){*}';
, as well as using both configurations simultaneously. Yet, the problem persists.

I initially suspected that the issue might be related to the rails_html_sanitizer. At present, my configuration for rails_html_sanitizer includes:


HTML::WhiteListSanitizer.allowed_tags.merge(%w(iframe table tbody tr td tfoot thead colgroup col style))
HTML::WhiteListSanitizer.allowed_attributes.merge(%w(target))

My desired outcome is to utilize CKEditor's font and font size options without losing the style attributes from the span classes. Most solutions I have come across suggest modifying the config.js file, but my attempts have been unsuccessful thus far. Any guidance or alternative approaches would be greatly appreciated. Thank you.

Answer №1

In a previous instance, I had the following code snippet:


    <% @docs.each do |doc| %> 
      <%= doc.title.html_safe %>
      <%= doc.discription.html_safe %>
      <%= doc.text.html_safe %>
    <% end %>

To correct this issue, I decided to incorporate the 'sanitize' method (considering I am utilizing rails_html_sanitizer, which has 'style' whitelisted as indicated in the original question):


    <% @docs.each do |doc| %> 
      <%= sanitize doc.title.html_safe %>
      <%= sanitize doc.discription.html_safe %>
      <%= sanitize doc.text.html_safe %>
    <% end %>

Alternatively, you could also address this problem by using the 'raw' method:


    <% @docs.each do |doc| %> 
      <%= sanitize doc.title.html_safe %>
      <%= sanitize doc.discription.html_safe %>
      <%= sanitize doc.text.html_safe %>
    <% end %>

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

"Modify the CSS color of h1 based on the presence of a specific class containing spaces in a div

I am currently attempting to modify the color of a heading by referencing a specific div's class. My attempts so far include: .pagetitle-title.heading { color: purple; } <div class="container"> <h1 class="pagetitle-title heading">I ...

Utilize jQuery or Javascript in WinRT to transfer names between pages seamlessly

Is there a way to pass four names entered by the user on the first page to another page while navigating in a winRT app using winJS or jQuery? For example, if the four names are: 1. Akshay 2. Ashish 3. Pavitra 4. Adarsh How can this be achieved? ...

Tips for using Python to capture specific HTML snippets

Here is a Python code snippet that I am working on: def parseAddressInfo(text): text = re.sub('\t', '', text) text = re.sub('\n', '', text) blocks = re.findall('<div class="result-box" ...

"Enhance your gaming experience with Three JS special effects

I'm in the process of creating a multiplayer web game using Three JS. So far, I have successfully implemented the game logic on both client and server sides, mesh imports, animations, skill bars, health bars, and the ability for players to engage in c ...

leveraging the power of JQuery and Ajax for submitting a form

I am looking to implement ajax functionality for form submission I want to achieve this using radio buttons instead of a submit button Essentially, when a radio button is clicked, the form should be submitted or posted My PHP page needs to determine whi ...

My Tailwind CSS toggle button disappears in dark mode, why is that happening?

<button aria-label="Toggle Dark Mode" type="button" className="lg:inline-flex lg:w-40 md:w-screen p-3 h-12 w-12 order-2 md:order-3" onClick={() => setTheme(theme === 'dark' ? &ap ...

How can I make my webpage fill the entire width of an iPhone screen when in landscape mode using Angular or React?

While testing my website on my iPhone, I noticed a significant gap appearing on either side of the app in landscape view in Safari. Is there a solution to fix this issue? The problem occurs in both Angular and React applications, examples of which are disp ...

What is the process for submitting a form on consecutive URLs?

I have a form that requires input for settings and includes two buttons: one to save the form and another to both save and execute the settings. <form method="post" action="/settings/{{id}}/save"> <!-- input fields --> ...

Animation in CSS Appears Jumpy in Chrome

For some reason, the text inside a moving div (which is transitioning using CSS) seems to jitter and shake in Chrome. However, this issue does not occur in Firefox, where the movement is very smooth and achieves the desired effect. #hidexpert { display: b ...

Vue Component, switching state

Feeling like I'm losing it, this should be really simple but it's not working... The idea is that when the link is clicked, the display property toggles between true and false. However, it's not working as expected. Vue.component('d ...

Breaking down JavaScript arrays into smaller parts can be referred to

Our dataset consists of around 40,000 entries that failed to synchronize with an external system. The external system requires the data to be in the form of subarrays sorted by ID and created date ascending, taken from the main array itself. Each ID can ha ...

I am searching for answers to solve issues related to a JSON file

I am currently working on a tool that searches for matches in an input field by comparing the keywords entered by the user with a JSON. During my testing phase, I focused on using a single API that provides information about different countries and fortun ...

Is it possible to embed HTML within standard PHP without using alternative methods?

Is it possible to embed HTML inside a PHP "if" statement? The top-rated answer in this thread on Stack Overflow discusses using alternative if style. While other answers suggest that it also works with normal if statements, the question remains: is this a ...

Setting the position of the center to be relative inside a table cell

I need help with centering a +/- animation within my table rows to create an accordion toggle effect for revealing more information. Despite finding a nice looking animation, I'm struggling to position it correctly within the td element in my code. He ...

"Learn how to use socket.io in conjunction with the express generator to create individual sockets for each unique link

I'm working on a typical express-generator app where I have some code in my controllers folder: router.get('/:id([A-Za-z0-9_]{5,25})', function(req, res, next) { res.render('my-page.html', { title: 'Messag ...

Having trouble with protractor's sendKeys function when trying to interact with md-contact-chips

Does anyone know how to set a value using sendKeys in Protractor for md-contact-chips? I attempted to use element(by.model('skills')).sendKeys('Java'); but it doesn't seem to be working. Any suggestions on how to approach this in ...

stay at the top of the screen with anchor #link

Is there a way to link to a page with a specific bootstrap nav-tabs open without the page automatically scrolling down to that tab? I've tried using #link with the tab id, like www.mysite.com/apagewithtabs#tab2, but I want the user to be at the top of ...

Issue with Vue multiselect preventing creation of new tags

Having a functional Vue multiselect feature that utilizes an autocomplete function via an axios call to a database. The process of retrieving DB results, adding them as options, and turning them into tags works seamlessly. The main issue arises when tryin ...

Array's Javascript length of 0

I have encountered some strange behavior with the following code. It's displaying an array length of 0 even though I can see a length greater than 0 when printing it right before that: var getTopSelection = function(callback) { var topSelection = ...

The data in AngularJS is not being successfully incorporated into the service

Utilizing angularjs and ajax, I am attempting to retrieve data from a webservice and pass it to the controller. To accomplish this, I am using a holder (a factory method or service). The setup works fine without the webservice, but when trying to fetch dat ...