Ignore HTML formatting when publishing articles with Confluence Cloud API
Asked Answered
A

0

6

I am trying to publish article on Confluence using REST API.

When I am preparing the article in storage format, I indent the content as if I would HTML code, with newlines and spaces. The problem is that when article gets published all these newlines and spaces are preserved, as if I used <br/> and non-breaking space symbols.

For example, if I send content like this:

<p>First part of paragraph 
    <ac:link ac:anchor="4b14531b1624f2b">
        <ri:page ri:content-title="Test Article"></ri:page>
        <ac:plain-text-link-body><![CDATA[link caption]]></ac:plain-text-link-body>
    </ac:link>
 last part of paragraph.</p>

It is rendered like this on the page:

First part of paragraph
    link caption
last part of paragraph.

But I expect this:

First part of paragraph link caption last part of paragraph.

Is it possible to tell confluence to ignore whitespaces as in normal HTML? Maybe there's some setting admins can change?

If I create the page normally through web editor and then get its content by API call, all returned content is on one line. This is stupid.

I never had this problem with previous Confluence servers I worked on.

I am using Confluence Cloud version.

Apoplexy answered 8/12, 2021 at 14:4 Comment(2)
I don't know the answer or reason for this (I have experience with on-prem Confluence Server only where this is not a problem). But what if you simply remove all the new lines and indentation and pass data as one-line (if you ignore it's stupid as you mentioned:-)? I.e. let all line formatting on <p> and <br/> elements.Memphian
@Memphian that's what I do, but the problem is that sometimes newlines and spaces are required. For example, in code macro, user formatting has to be preserved. I handle that too with some ugly piece of code, but I can't ignore that it is stupid :-D Also there may appear other situations where formatting needs to be preserved and I will have to add yet more ugly code to handle that.Apoplexy

© 2022 - 2024 — McMap. All rights reserved.