Editing Source Code in Confluence
Asked by Susan Vineyard:

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....


Answers:
author: Stephen Deutsch
body: 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.

comments: author: Maarten Joosen
body: Nice, simple en to the point


author: Nicky van Steensel van der Aa
body: :thumbsup:


author: Philip Schlesinger
body: Can't give this enough up-votes


author: Mohammed Davoodi
body: Our organization offers a paid plugin, [Source Editor for Confluence](https://marketplace.atlassian.com/plugins/com.mohamicorp.html.source.editor.for.confluence/cloud/overview) 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


Tags: confluence-administration