Can I get a ScriptRunner custom macro body in storage format?
Asked by William Lupton:

I'm writing a ScriptRunner custom macro that will process its body, but I'd prefer to process storage format (which is valid XML) rather than view format (which isn't). Looking at [ConversionContext](https://docs.atlassian.com/atlassian-confluence/6.3.3/com/atlassian/confluence/content/render/xhtml/ConversionContext.html), there are methods to convert storage to view but (not surprisingly I guess) not the other way round.

As explained at <https://docs.adaptavist.com/sr4c/latest/features/macros/custom-macros>, the macro body is available in the body variable, but this appears to be view format and I don't see any way of requesting storage format. I checked whether there were any other hidden variables (such as bodyStorage) in the binding, but there don't appear to be.

Any ideas? Thanks.  

*** ** * ** ***

**UPDATE**: I created a simple example that uses the "status" macro. Here is the storage format (I've inserted some line breaks to make it more readable):

```
<p class="auto-cursor-target"><br /></p>
<ac:structured-macro ac:name="inspect-body" ac:schema-version="1"
        ac:macro-id="2c224875-7f90-41be-bf74-486fc930c58c">
  <ac:rich-text-body>
    <p>
      <ac:structured-macro ac:name="status" ac:schema-version="1"
              ac:macro-id="c6c51709-dfab-4cce-8a47-a8a878787f45">
        <ac:parameter ac:name="title">Status</ac:parameter>
      </ac:structured-macro>
    </p>
  </ac:rich-text-body>
</ac:structured-macro><p class="auto-cursor-target"><br /></p>
```

**inspect-body** is my custom macro and it just returns the body HTML as literal text. The weird thing is that I'm seeing different view formats when previewing the macro in the macro editor:

```
<p>
<img class="editor-inline-macro" height="18" width="88"
     src="/plugins/servlet/status-macro/placeholder?title=Status"
     data-macro-name="status"
     data-macro-id="c6c51709-dfab-4cce-8a47-a8a878787f45"
     data-macro-parameters="title=Status"
     data-macro-schema-version="1">
</p>
```

...and when saving the page (again I've added some newlines in both cases):

```
<p talk-marker="1" talk-page-id="116228112" talk-page-version="7">
<span class="status-macro aui-lozenge conf-macro output-inline"
      data-hasbody="false" data-macro-name="status">STATUS</span>
</p>
```

I guess I need to be able to process both of the above (because I want the macro logic to execute both in the editor and when saving the page) but of course the **\<img\>** tag isn't terminated, so I can't parse it as XML. I guess I'll either preprocess it to make it valid XML or else do a naive parse (I don't care about the full details of the XML; I just want some bits, e.g., the status macro text).

Does this additional information help to point to the source of the problem, if indeed it is a problem?

Also, I don't suppose it's relevant, but the SR version is 6.36.0.


Answers:
author: Fabian Lim
body: Hi [@William Lupton](/t5/user/viewprofilepage/user-id/968162)

I suggest you also contact [adaptivist support](https://scriptrunner.adaptavist.com/latest/jira/getting-help.html) directly for faster support.

Regards

comments: author: William Lupton
body: Thanks [@Fabian Lim](/t5/user/viewprofilepage/user-id/3131564) and sorry for the delay in replying. Yes I will create a support ticket but in the meantime I have avoided the problem in the way that I suggested.


Tags: confluence-server

scriptrunner

server