How to remove anchor tags in Confluence cloud?

I've got a wiki in confluence cloud in which someone apparently added anchor tags to several paragraphs. 

The page now renders that anchor'd text in a different color, and gives it an underline on hover. 

Is there a way to remove the anchor tags without copy/pasting the text out and back in to the document? Some of the text has other formatting that would be tedious to recreate.

This is the HTML of a portion of the page in question, with the anchor tags across multiple elements:

<li><em>CSS</em>:&nbsp;<a href="http://sass-lang.com/">scss</a></li>
<li><em>JavaScript</em>:&nbsp;<a href="http://coffeescript.org/">CoffeeScript</a></li></ul>
<h2><a name="rails_structure">Rails structure</a></h2>
<p><a name="rails_structure">The standard Rails directory structure is used, but you'll find certain files in places you might not expect. The most important directory is&nbsp;<code>app</code>, that is where you'll find the majority of the website&rsquo;s application code. Here&rsquo;s a truncated directory hierarchy:</a></p>
<pre><a name="rails_structure"><code>scribd
├── app
│&nbsp;&nbsp; ├── controllers
│&nbsp;&nbsp; ├── helpers
│&nbsp;&nbsp; ├── models
│&nbsp;&nbsp; └── views
├── config
├── doc
├── lib
├── public
└── vendor
</code></a></pre>
<p><a name="rails_structure">In the&nbsp;<code>views</code>&nbsp;directory you'll find the views (the files responsible for rendering HTML) a

There's an add-on for editing source, but it costs $82 per month for the cloud version, which is way more than I'm willing to pay to solve this.

 

 

 

 

1 answer

This might work for you:

jQuery.ajax({
    url: contextPath + "/rest/api/content/" + AJS.params.pageId + "?expand=body.storage,version,ancestors",
    success: function(response) {
        console.log(response);
        bodyText = "<xml>" + response.body.storage.value + "</xml>";
        xmlBodyText = bodyText
            .split("ac:").join("ac--")
            .split("ri:").join("ri--")
            .split("&nbsp;").join("nnbbsspp")
            .split("&quot;").join("qquuoott");
        xmlDoc = jQuery.parseXML(xmlBodyText);
        xml = jQuery(xmlDoc);
        anchor = xml.find('a[name="rails_structure"]');
        jQuery(anchor).each(function() {
            jQuery(this).replaceWith(this.innerHTML);
        });
        ser = new XMLSerializer();
        newBodyText = ser.serializeToString(xml[0]);
        newBodyText = newBodyText
            .split("ac--").join("ac:")
            .split("ri--").join("ri:")
            .split("nnbbsspp").join("&nbsp;")
            .split("<xml>").join("")
            .split("</xml>").join("")
            .split("/>").join(" />")
            .split("qquuoott").join("&quot;");
        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) {
                location.reload();
            },
            error: function(response) {
                console.log(response);
            }
        });
    }
});

You need to go to the page that you want to change and then copy and paste the code in the browser console (usually opened by pressing F12 on Windows, or Alt+Option+I on Mac).

If everything goes well, it should reload with with the changes visible. In case it messed something up, you should be able to restore your page from the history, but it should work (I tested it on a sample page).

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Dec 18, 2018 in Confluence Cloud

Happy holidays from our team to yours!

Hi Community!  2018 was filled with changes for our team, both big and small, and we've taken a lot of time to both celebrate our wins and recognize areas of improvement. One thing that we're a...

458 views 3 18
Read article

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