Uploaded image for project: 'Confluence Data Center'
  1. Confluence Data Center
  2. CONFSERVER-25366

Confluence should respect relative links when copying and pasting the content of a page

      If you insert a relative link, then it should remain relative. This means that, if you copy the source of the page from one space to another, then the relative links should point to pages in the new space, not to pages in the original space.

      I have just tested the scenario described by a customer in a support case:

      • In the DOC space on CAC, I created a page called "Sarah test 1". I added three links that should be relative. All of them point to a page called "Supported Platforms". To create the links, I added one via the links autocomplete, one via the Search tab in the links browser, and one via the Advanced tab in the links browser.
      • Both the DOC space and the JIRA space already have a page with the same name, "Supported Platforms".
      • In the JIRA space on CAC, I created another page called "Sarah test 1", and copied the content from the above page. To copy it, I opened the above page in the editor, selected all the content, pressed Ctrl+C, then pasted the content into my new page.
      • Problem: The links are not relative in the new page. They still point to the DOC space, whereas they should point to the identically-named page in the JIRA space.

      See screenshots attached.

        1. screenshot-1.jpg
          screenshot-1.jpg
          225 kB
        2. screenshot-2.jpg
          screenshot-2.jpg
          244 kB

            [CONFSERVER-25366] Confluence should respect relative links when copying and pasting the content of a page

            Thanks very much smaddox for the excellent write-up above!

            Just to add, if you have the Confluence source editor plugin (which is essentially an editor for Confluence's underlying storage format) installed in your Confluence site, you should be able to convert 'absolute' links (i.e. which target pages in the original space you copied the 'source' content from) into 'relative' ones by:

            1. Editing the page in question and then clicking the < > button at the top-right to enter 'storage format editor mode'.

            2. Removing the ri:space-key="ORIGINALSPACE" attributes from the
              <ri:page ri:content-title="Name of page being linked to" ri:space-key="ORIGINALSPACE"/> elements which define your links, so that these elements become just
              <ri:page ri:content-title="Name of page being linked to"/>.
              For example:
              Remove the ri:space-key="DOC" attribute from the
              <ri:page ri:content-title="Supported Platforms" ri:space-key="DOC"/> so that it becomes just
              <ri:page ri:content-title="Supported Platforms"/>

            Giles Gaskell [Atlassian] added a comment - - edited Thanks very much smaddox for the excellent write-up above! Just to add, if you have the Confluence source editor plugin (which is essentially an editor for Confluence's underlying storage format) installed in your Confluence site, you should be able to convert 'absolute' links (i.e. which target pages in the original space you copied the 'source' content from) into 'relative' ones by: Editing the page in question and then clicking the < > button at the top-right to enter 'storage format editor mode'. Removing the ri:space-key="ORIGINALSPACE" attributes from the <ri:page ri:content-title="Name of page being linked to" ri:space-key="ORIGINALSPACE"/> elements which define your links, so that these elements become just <ri:page ri:content-title="Name of page being linked to"/> . For example: Remove the ri:space-key="DOC" attribute from the <ri:page ri:content-title="Supported Platforms" ri:space-key="DOC"/> so that it becomes just <ri:page ri:content-title="Supported Platforms"/>

            SarahA added a comment -

            There is a workaround, although it's messy. Thank you to @ggaskell for showing it to me!

            The workaround hinges on 2 facts: (1) The page copy function ("Tools" > "Copy") does respect relative links. (2) When you copy the content of a page within a space, using Ctrl+C and Ctrl+V, Confluence does leave the links as relative.

            So, the workaround is:

            • Use the Confluence "Tools" > "Copy" to copy the page to the new space. Let's assume your page is called "X". When you copy it, it will be named "Copy of X".
            • If the page did not yet exist in the 2nd space before you copied it, just rename the page from "Copy of X" to "X".
            • If the page "X" already exists in the 2nd space, edit "Copy of X", select all the content, Ctrl+C to copy it. Then edit "X" and paste the content into it. Confluence will respect the relative links in this case.

            How to see if links are relative? If you have access to viewing the Confluence storage format, you may see something like this:

            <p>I'm now creating a page in the JIRA space. I'm going to copy the content of the page from the DOC space, by opening the editor and copying all the content from the edit panel,</p>
            <h2>Copied content follows this heading</h2>
            <p>This is a link to the <ac:link>
                <ri:page ri:content-title="Supported Platforms" ri:space-key="DOC"/>
              </ac:link> page in the DOC space, created via autocomplete.</p>
            <p>This is a link to the <ac:link>
                <ri:page ri:content-title="Supported Platforms" ri:space-key="DOC"/>
              </ac:link> page in the DOC space, created via the Search tab in the links browser.</p>
            <p>This is a link to the <ac:link>
                <ri:page ri:content-title="Supported Platforms" ri:space-key="DOC"/>
              </ac:link> page in the DOC space, created via the Advanced tab in the links browser.</p>
            <p>I'm working on CAC, running Confluence 4.2.1.</p>
            <p>&nbsp;</p>
            <h2>Copied from page in the same space</h2>
            <p>This is a link to the <ac:link>
                <ri:page ri:content-title="Supported Platforms"/>
              </ac:link> page.</p>
            <p>This is a link to the <ac:link>
                <ri:page ri:content-title="Supported Platforms"/>
              </ac:link> page.</p>
            <p>This is a link to the <ac:link>
                <ri:page ri:content-title="Supported Platforms"/>
              </ac:link> page.</p>
            

            The elements that have an attribute like ri:space-key="DOC" are not relative links. The elements without that attribute are relative links.

            SarahA added a comment - There is a workaround, although it's messy. Thank you to @ggaskell for showing it to me! The workaround hinges on 2 facts: (1) The page copy function ("Tools" > "Copy") does respect relative links. (2) When you copy the content of a page within a space, using Ctrl+C and Ctrl+V, Confluence does leave the links as relative. So, the workaround is: Use the Confluence "Tools" > "Copy" to copy the page to the new space. Let's assume your page is called "X". When you copy it, it will be named "Copy of X". If the page did not yet exist in the 2nd space before you copied it, just rename the page from "Copy of X" to "X". If the page "X" already exists in the 2nd space, edit "Copy of X", select all the content, Ctrl+C to copy it. Then edit "X" and paste the content into it. Confluence will respect the relative links in this case. How to see if links are relative? If you have access to viewing the Confluence storage format, you may see something like this: <p>I'm now creating a page in the JIRA space. I'm going to copy the content of the page from the DOC space, by opening the editor and copying all the content from the edit panel,</p> <h2>Copied content follows this heading</h2> <p>This is a link to the <ac:link> <ri:page ri:content-title="Supported Platforms" ri:space-key="DOC"/> </ac:link> page in the DOC space, created via autocomplete.</p> <p>This is a link to the <ac:link> <ri:page ri:content-title="Supported Platforms" ri:space-key="DOC"/> </ac:link> page in the DOC space, created via the Search tab in the links browser.</p> <p>This is a link to the <ac:link> <ri:page ri:content-title="Supported Platforms" ri:space-key="DOC"/> </ac:link> page in the DOC space, created via the Advanced tab in the links browser.</p> <p>I'm working on CAC, running Confluence 4.2.1.</p> <p>&nbsp;</p> <h2>Copied from page in the same space</h2> <p>This is a link to the <ac:link> <ri:page ri:content-title="Supported Platforms"/> </ac:link> page.</p> <p>This is a link to the <ac:link> <ri:page ri:content-title="Supported Platforms"/> </ac:link> page.</p> <p>This is a link to the <ac:link> <ri:page ri:content-title="Supported Platforms"/> </ac:link> page.</p> The elements that have an attribute like ri:space-key="DOC" are not relative links. The elements without that attribute are relative links.

              jmasson@atlassian.com John Masson
              smaddox SarahA
              Affected customers:
              1 This affects my team
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: