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

0 vote
Stephen Deutsch Community Champion Jul 03, 2017

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

2,348 views 25 10
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