Problem with iframe in DIV macro

jonb November 12, 2020

I am creating a DIV macro that will allow users to place custom <div> tags and place content within the div.

I tested with an iframe and i noticed that there are extraneous tags being displayed as plain text after the iframe.

I'm just basing this test on the "collapse" macro from this page: https://confluence.atlassian.com/conf73/writing-user-macros-991928530.html

screenshot_2020-11-12_08.33.13_img.png

I'm putting the HTML macro with my iframe within my DIV macro.

screenshot_2020-11-12_08.32.09_img.pngThis is what the rendered page looks like.  The iframe is correctly inside my div container, but there is an extra "</div>" printed after the iframe

screenshot_2020-11-12_08.32.27_img.png

 

Looking at the page source, the </div> is both in the html as expected but also in some text after the iframe.

screenshot_2020-11-12_08.37.02_img.png

This becomes even more of a problem if you have nested div macros or tables, it seems to print out any closing tags after the iframe.

 

I've tested with a few other websites in the iframe with similar results.

1 answer

1 accepted

0 votes
Answer accepted
Bill Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 12, 2020

Why are you nesting a HTML macro inside the body of the macro? I would just structure the macro so that all the HTML is inside the user macro, and then you can either have body hold the src link, or even make it a parameter with no macro body. Then use the parameters in your code.

I would also make the width and height parameters to make it more configurable.

 

If you need the HTML macro, then move that instance to inside the user macro. Take a look at this article I wrote awhile back on wrapping a macro: Getting Started with User Macros - Writing a Wrapper Macro 

jonb November 17, 2020

Thanks for the info Bill, I'll take a look at your article.

The original intent was to have a generic div macro that could include any content like text or other macros.  This would help tie in with custom stylesheets and being able to style elements with a surrounding div id/class.

Are there known issues with nested macros?

Bill Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 17, 2020

I think the issue with nested macros is unpredictability with the rendered output. I have always gone the route or wrapping a macro if needed.

jonb November 17, 2020

I see.  Yeah I've been trying to generalize macros as best i can and then nest any existing macros inside, but like you said I've also ran into some strange cases of the output not behaving as expected.

I'll try making a simple iframe specific macro and see if that has any similar issues.

For the most part, I haven't had issues with the nested div macros in my post.  But seems to be something with how the iframe is processed in conjunction with the macro.

jonb November 17, 2020

Putting the iframe directly in the macro (not using the nested html macro):

<div><iframe>...</iframe></div>  still has the issue

 

Putting just the iframe in the macro seems to work fine.

I will just create an iframe macro and expose some paramters.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events