ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Wygwam + Matrix + ImgSizer + NSM Transplant + Low Replace - need regular expressions help

October 19, 2010 9:24am

Subscribe [5]
  • #1 / Oct 19, 2010 9:24am

    Joobs

    362 posts

    I’m using the method shown here for allowing clients to display images:
    http://ellislab.com/forums/viewthread/120427/

    However, since i am using a wygwam field, i’m getting unwanted paragraph tags added around the images.

    I saw Leevi Graham posting some regex code to try and solve this but i’m still having a few issues.

    Basically wygwam outputs code like:

    
          {image_1}

    I’m looking for an expression that ignores any whitespace or new lines, and then if it finds a {image_x} between two paragraph tags it removes them.  Ideally it only removes the tags if there no other content (so if someone inserts the image into the middle of the text it doesn’t remove all the text).

    Here is the code I am using as a base

    exp:low_replace find="<p.*?>\\n.*?({(video|image|quote)+_[0-9]+}).*?<\\/p>" replace="$1" regex="yes"}
          {body}
    {/exp:low_replace}

    Currently this only works if the paragraphs are formatted the wygwam way, with a line break after the first tag.  It also removes everything between the paragraph tags apart from the {image_x}

    Anyone fancy a go at improving this?

  • #2 / Nov 03, 2010 8:48am

    AJP

    311 posts

    As the original author, my way around the paragraphs in the wysiwyg field, was to either insert images inline, or to use CSS to minimalize any damage done by paragraphs.

    The only way I know currently would be not use a wysiwyg where p tags get auto inserted. I’ll ask Leevi or Brandon if they know of a way around it, but I wouldn’t count on it, as that is usually the desired behavior of the wysiwyg.

  • #3 / Nov 03, 2010 9:16am

    Joobs

    362 posts

    Adding low replace allows you to remove those P tags.  The expression above is based off something i saw Leevi post and basically works. But there are issues if the image is inline or they mess with the wygwam source.

    I’m hoping developing a way where the injected content isn’t inline it is a bit more flexible, then you can use it for block elements or anything else you want: blockquotes, video, audio, images, flash, and other specially formatted content.

    But that does leave the problem of what to do if someone wants to have the image inline with paragraph text…

  • #4 / Sep 29, 2011 7:03am

    sambo

    80 posts

    Did you ever find a solid way around this?

    I am implementing this method and Wygwam is of course creating a p tag around the {image_1} marker.

    Best,
    Sammi

  • #5 / Dec 04, 2011 6:31pm

    hothousegraphix

    851 posts

    I too am trying to use this replacement method for adding images to entries.

    <!-- Post -->
    {exp:low_replace find="<p.*?>\\\\n.*?({(image)+_[0-9]+}).*?<\\\\/p>" replace="$1" regex="yes"}
    {news_body}
    {/exp:low_replace}
    <!-- /Post -->

    (for some reason the “escapes” above are being repeated; however, this is not present in my expression)

    The replacement works if I only have one image to replace and the tag is placed at the top of the entry; but if more are included (up to 3 are possible) only the first gets replaced.

    
          {image_1}  
    
    //
    // resulting in
    //
    
    {image_1}
    
     Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur auctor dictum egestas. Morbi lorem magna, pellentesque non tempor et, porttitor sit amet odio. Ut pulvinar dolor id est sagittis rutrum. Vivamus dolor leo, aliquet vitae vehicula non, lobortis et magna. Morbi id massa id quam.
    
          {image_2)
    
     Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac lacus ipsum. Proin luctus ultrices accumsan. Donec at risus ligula, sed feugiat libero. Morbi vel elit tortor. Maecenas diam velit, tincidunt at suscipit eu, lacinia luctus metus. Etiam dapibus urna nec ante porta convallis. Etiam turpis est, aliquam id dapibus ut, dignissim et odio. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Praesent iaculis consequat lacinia. Vestibulum congue dignissim quam sed faucibus. Suspendisse potenti. Ut.
    
          {image_3)
    
     Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur auctor dictum egestas. Morbi lorem magna, pellentesque non tempor et, porttitor sit amet odio. Ut pulvinar dolor id est sagittis rutrum. Vivamus dolor leo, aliquet vitae vehicula non, lobortis et magna. Morbi id massa id quam.
    
    //
    // The replacement does not work at all if the below example is how the image tag is applied
    //
    
    
     Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac lacus ipsum. Proin luctus ultrices accumsan.
    
          {image_1)
    
     Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur auctor dictum egestas. Morbi lorem magna, pellentesque non tempor et, porttitor sit amet odio. Ut pulvinar dolor id est sagittis rutrum. Vivamus dolor leo, aliquet vitae vehicula non, lobortis et magna. Morbi id massa id quam.

    When I eliminate NSM Transplant this replacement issue persists. I assuming this is related to how the regular expression is functioning.

    Wondering if anyone might have a clue what I need to adjust within the find and replace tag parameters to accommodate my needs.

     

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases