Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to remove anchor tags in Confluence cloud?

Alex Bernardin June 30, 2017

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 votes
Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 3, 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
TAGS
AUG Leaders

Atlassian Community Events