Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Petr Hruzek 28 posts 100 karma points
    May 06, 2014 @ 17:13
    Petr Hruzek
    0

    Styling img tag

    Hello!

    I am trying to style img tag exactly as here http://our.umbraco.org/wiki/recommendations/recommended-reading-for-content-editors/adding-styles-to-the-tinymce

    But no matter what I do, instead of adding a class to an IMG tag TinyMCE keeps surrounding my IMG tag with a new SPAN with that class. How can I style IMG tag directly as at the wiki page above. Am I missing something? I am using Umbraco 7.1.1.

    Thank you.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    May 06, 2014 @ 21:17
    Jan Skovgaard
    100

    Hi Petr

    This behavior has been like that for as long as I can remember between Umbraco versions. Not sure how to fix it.

    But I think the easy way around it would be to make sure that your CSS takes into account that the class is sometimes sourrounding the image and sometimes it is placed directly on the tag.

    So in your CSS do something like

    .yourclass > img, .yourclass

    If you think this is something that should be changed you could try adding a request for it on the issue tracker

    Hope this helps.

    /Jan

  • Petr Hruzek 28 posts 100 karma points
    May 07, 2014 @ 13:57
    Petr Hruzek
    0

    Hello Jan!

    I am not happy with code polluted with unnecessary tags, but your solution will do the job. Thank you for taking time to reply to my question.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    May 07, 2014 @ 13:59
    Jan Skovgaard
    0

    Hi Petr

    I understand that and I feel the same way. But sometimes it's just hard to be perfect when you're not in complete control of the code.

    Remember to mark the post as solved btw :)

    Cheers, Jan

  • Darren Clark 52 posts 249 karma points
    Nov 01, 2014 @ 02:20
    Darren Clark
    1

    Hi Guys,

    I hit this issue also and needed a quick solution, so ended up creating a new class to do the trick, not sure if this is the best solution though it works. You could certainly adapt it to suit your needs.

    using System;
    using Umbraco.Core;
    using Umbraco.Core.Logging;
    using Umbraco.Core.Models;
    
    namespace iconic.Overrides
    {
        public class PublishOverride : ApplicationEventHandler
        {
            protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
                Umbraco.Core.Services.ContentService.Published += ContentService_Published;
                base.ApplicationStarted(umbracoApplication, applicationContext);
            }
    
            private void ContentService_Published(Umbraco.Core.Publishing.IPublishingStrategy sender, Umbraco.Core.Events.PublishEventArgs<Umbraco.Core.Models.IContent> e)
            {
                foreach (var content in e.PublishedEntities)
                {
                    PublishDoc(content);
                }
            }
    
            private void PublishDoc(IContent sender)
            {
                try
                {
                    string propertyValue = sender.GetValue("bodyText").ToString();
                    if (!string.IsNullOrEmpty(propertyValue))
                    {
                        string changedPropertyValue = propertyValue.Replace("<img", "<img class=\"img-responsive\" ");
                        sender.SetValue("bodyText", changedPropertyValue);
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.Error<Exception>("Error publishing!", ex);
                }
            }
        }
    }
    
  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Nov 01, 2014 @ 08:29
    Jan Skovgaard
    0

    Hi Darren

    Thanks for sharing the above code - Someone will certainly be able to benefit from this :)

    H5YR!

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft