I am using SQL Query to get a JSON string from Postgres which is then fed via a user macro to JavaScript to initialize Chart.js plugin for better charts
Seems like I can only place another macro inside my user macro if I select "Rendered" body. However, this causes Confluence to render the resulting JSON as Confluence markup, which breaks everything completely and horribly. How can I allow a macro as the body of my user macro but stop it from processing that data before handoff to my user macro? Is there an intermediary macro I can use to stop that processing? Is there a way to escape curly brackets without whatever escape character following through to the user macro? the user macro needs valid JSON as input.
Right now everything works if i change my user macro to "unrendered" and paste my JSON manually, but the JSON is dynamic hence the SQL query.
I didn't find a way around it, I ended up using javascript to remove the crap.
1) Load underscore.js in Custom HTML <head> or in place
2) Set the SQL Query output to "escape special wiki characters"
3) Use the following javascript on document load:
<script type="text/javascript">
var json =`$body`;
json = json.replace(/<\/?span[^>]*>/g,"");
json = json.replace(/(<|)br\s*\/*(>|)/g,' ');
json = _.unescape(json);
json = JSON.parse(json);
//var json should now be valid JSON, hopefully
</script>
Hi Austin,
Thank you for your post, I have tried nesting with chart macro and successful. But the charts are very basic and I dont have much control.
I was going through the chart.js documentation but could not figure out how to nest Chart.js inside a user macro,
Can you please share that part where you nested chart.js in your user macro?
Thank you
with warm regards
ramki
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.