Forum Discussion

pizzaTime's avatar
Occasional Contributor
5 years ago

Push a to confluence using confluence APIs



So I'm trying to push readme to confluence, except that Confluence APIs accepts the body as json, but my readme is a multiline text.. In confluence I have a waiting plugin to convert the text into a well-formed readme :) 
So I'm trying to convert a multiline text into a single line so that I can automate pushing all readme to confluence.


One of my problem now is to locate the carriage return , and convert it into "\\n" but I'm new to groovy and I don't know how to do that.
One of the future struggle is going to be : how to parse through directories to locate readme.

many thanks


15 Replies

  • nmrao's avatar
    Champion Level 3

    Groovy supports multi line text


    def multiLine = '''line1 text
    next line
    and one more line'''
    //Show as is multiLine
    //Remove new lines / carriage returns
    def newString = multiLine.replaceAll('\n', '').replaceAll('\r', '')
    //See the diff with multiLine newString
    • pizzaTime's avatar
      Occasional Contributor

      Yes, but as I am using confluence API to send back : so I have this body to fill
      Especially the value in which I am replacing ${Properties#body} by the text

         "id" : "${Properties#pageId}",
         "type" : "page",
         "status" : "current",
         "title" : "Markdown test",
         "body" : {
           "storage" : {
               "value" : "<ac:structured-macro ac:name=\"markdown\" ac:schema-version=\"1\" ac:macro-id=\"1234\"><ac:plain-text-body><![CDATA[${Properties#body}]]></ac:plain-text-body></ac:structured-macro>",
               "representation" : "storage",
               "_expandable" : {
                  "content" : "/rest/api/content/${Properties#pageId}"

      To be more precise I have this readme: 

      ##  Title
      ## Another Title
      another text

      That I want to convert into :

      ## Title \n text \n ## Another Title \n another text

      So that it can be supplied in the body in my request.


      Best regards,