How to copy a Macro filled with content, without going into the Edit Mode?

Andrzej Delgado June 25, 2021

Hey Guys,

I've been working on a solution to copy a macro filled with content, without going into the Edit mode. I did some research, I iterated on couple of drafts but to no avail.

Let me try to structure the problem, and path I went through.

1. Reasoning (the need)

The reason behind this kind of solution is to serve a user, that has read only permission, a possibilty to copy into his own Confluence page not only the outcome of the macro's work but also the whole macro filled with the content, so he/she can modify it, while keeping him/her from editing the page.

2. Example of use

There is a form (a ContiForm) pre-populated with content and variety of options already picked. Setting up such form takes a good while. Through such solution user could copy the form into his Confluence page, modify 1-2 fields and re-use the whole bunch of options. But he/she would not have a chance to change anything in the source page, since has read-only privileges.

3. Attempts

So I've tried adding js scripts through html macro, with and without using the jQuery.

The furthest I got was to copy specific part of the page with full formatting and function (the result of macro's work), but not the macro itself.

function copy(element_id){
var aux = document.createElement("div");
aux.setAttribute("contentEditable", true);
aux.innerHTML = document.getElementById(element_id).innerHTML;
aux.setAttribute("onfocus", "document.execCommand('selectAll',false,null)");
document.body.appendChild(aux);
aux.focus();
document.execCommand("copy");
document.body.removeChild(aux);
}

+

<p id="demo"><b>Bold text</b> and <u>underlined text</u>.</p>
<button onclick="copy('demo')">Copy Result</button>

I know it might seem this is a very hacky attempt, but that was my idea. I have no experience in velocity, nor I have administration privileges in the the said Confluence sever instance. Hence this is the way I tried to achieve the goal with such attempt.

4. Discussion starter

If you have any insight you might share, or idea of your own or some advice, I'd be more the happy to read your input.

Any constructive help would be most appreciated.

0 comments

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events