Editing Source Code in Confluence

We recently had to upgrade Confluence to 5.9.1 because of a bug in indexing that is supposed to be fixed in this version.  But then we discovered that  the source code editor we were using no longer works with that version. I used that editor to format our templates and create elements for CSS to format. We MUST have access to the html. Although we are allergic to plugins with a price, we may have to pay to find one that works. It's that important.  Does anyone have any suggestions....please....

2 answers

Comments Closed
This widget could not be displayed.

Well, if you are willing to pay for it, I wouldn't turn it down, but there is an option for changing the source code without the Source Editor plugin.  It takes a few manual steps, but it's not so hard.

  1. On the page you want to change, go to the ••• menu and choose "View Storage Format"
  2. Copy and paste it into your favorite editor (I like Notepad++)
  3. Make the changes you want
  4. (NO LONGER NECESSARY) Remove all line breaks (i.e. make it so the whole thing is on one line).  In Notepad++, you can do a search and replace for \r\n (don't forget to choose "Extended") and make sure that the replace box is empty and choose "replace all"
  5. (NO LONGER NECESSARY) Do another search and replace and replace all " characters with \"
  6. Copy that and paste it over the <PASTE CODE HERE> part of this script (but leave the backticks `` intact):

    var newBodyText = `<PASTE CODE HERE>`;
    jQuery.ajax({
        url: contextPath + "/rest/api/content/" + AJS.params.pageId + "?expand=body.storage,version,ancestors",
        success: function(response) {
            response.body.storage.value = newBodyText;
            response.version.number += 1;
            jQuery.ajax({
                contentType: 'application/json',
                type: 'PUT',
                url: contextPath + "/rest/api/content/" + AJS.params.pageId,
                data: JSON.stringify(response),
                success: function(response) {
                    console.log(response);
                    console.log("Success!");
                },
                error: function(response) {
                    console.log(response);
                    console.log("Error!");
                }
            });
        }
    });
  7. While you are on the page you want to change the code for, open up the browser console (Often by pressing F12 or Shift+Ctrl+I).
  8. Paste that new script into the browser console, and press enter.
  9. If everything went well, you should see Success!, and if you refresh the page, you should see your changes.

This would actually work in Confluence Cloud as well.

EDIT: Modern browsers let you make multiline strings using backticks (`) which makes steps 4 and 5 unnecessary.

Nice, simple en to the point

Can't give this enough up-votes

This widget could not be displayed.

Our organization offers a paid plugin, Source Editor for Confluence to edit the source of Confluence pages. We support both server and cloud. 

Let me know if you have any questions or feedback about the plugin.

Mohammed

Community showcase
Posted Sep 17, 2018 in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

599 views 8 6
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you