|
27 | 27 | from sphinxcontrib.confluencebuilder.util import convert_length |
28 | 28 | from sphinxcontrib.confluencebuilder.util import extract_length |
29 | 29 | from sphinxcontrib.confluencebuilder.util import first |
| 30 | +import json |
30 | 31 | import posixpath |
31 | 32 | import re |
32 | 33 | import sys |
@@ -2832,6 +2833,42 @@ def visit_FancyOutputNode(self, node): |
2832 | 2833 | def depart_FancyOutputNode(self, node): |
2833 | 2834 | pass |
2834 | 2835 |
|
| 2836 | + # ------------------------------------------------------- |
| 2837 | + # sphinx -- extension (third party) -- sphinx-data-viewer |
| 2838 | + # ------------------------------------------------------- |
| 2839 | + |
| 2840 | + def visit_DataViewerNode(self, node): |
| 2841 | + data = json.dumps(json.loads(node['data']), indent=4) |
| 2842 | + |
| 2843 | + title = node.get('title', None) |
| 2844 | + if title: |
| 2845 | + title = self.encode(title) |
| 2846 | + |
| 2847 | + # use the `none` language type by default; however, if it appears |
| 2848 | + # that this configuration supports json rendering, use that instead |
| 2849 | + target_lang = 'none' |
| 2850 | + if self.builder.lang_transform: |
| 2851 | + new_target_lang = self.builder.lang_transform('json') |
| 2852 | + if 'json' in new_target_lang: |
| 2853 | + target_lang = new_target_lang |
| 2854 | + |
| 2855 | + self.body.append(self._start_ac_macro(node, 'code')) |
| 2856 | + self.body.append(self._build_ac_param(node, 'language', target_lang)) |
| 2857 | + |
| 2858 | + if title: |
| 2859 | + self.body.append(self._build_ac_param(node, 'title', title)) |
| 2860 | + |
| 2861 | + expand = node.get('expand', None) |
| 2862 | + if not expand: |
| 2863 | + self.body.append(self._build_ac_param(node, 'collapse', 'true')) |
| 2864 | + |
| 2865 | + self.body.append(self._start_ac_plain_text_body_macro(node)) |
| 2866 | + self.body.append(self._escape_cdata(data)) |
| 2867 | + self.body.append(self._end_ac_plain_text_body_macro(node)) |
| 2868 | + self.body.append(self._end_ac_macro(node)) |
| 2869 | + |
| 2870 | + raise nodes.SkipNode |
| 2871 | + |
2835 | 2872 | # --------------------------------------------------- |
2836 | 2873 | # sphinx -- extension (third party) -- sphinx-toolbox |
2837 | 2874 | # --------------------------------------------------- |
|
0 commit comments