Skip to content

Commit d0d1381

Browse files
authored
Merge pull request #830 from sphinx-contrib/support-sphinx-data-viewer-extension
support sphinx-data-viewer extension
2 parents 36723f3 + 0d32510 commit d0d1381

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

sphinxcontrib/confluencebuilder/storage/translator.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from sphinxcontrib.confluencebuilder.util import convert_length
2828
from sphinxcontrib.confluencebuilder.util import extract_length
2929
from sphinxcontrib.confluencebuilder.util import first
30+
import json
3031
import posixpath
3132
import re
3233
import sys
@@ -2832,6 +2833,42 @@ def visit_FancyOutputNode(self, node):
28322833
def depart_FancyOutputNode(self, node):
28332834
pass
28342835

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+
28352872
# ---------------------------------------------------
28362873
# sphinx -- extension (third party) -- sphinx-toolbox
28372874
# ---------------------------------------------------

0 commit comments

Comments
 (0)