Skip to content

Commit cd130fc

Browse files
committed
FEAT(sphinxext): +graphtik_save_dot_files config
1 parent 6645558 commit cd130fc

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

graphtik/sphinxext/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ def setup(app: Sphinx):
466466
app.add_config_value("graphtik_plot_keywords", {}, "html", [cabc.Mapping])
467467
app.add_config_value("graphtik_zoomable", True, "html", [bool])
468468
app.add_config_value("graphtik_warning_is_error", False, "html", [bool])
469+
app.add_config_value("graphtik_save_dot_files", False, "html", [bool])
469470
app.add_config_value(
470471
"graphtik_zoomable_options",
471472
"{controlIconsEnabled: true, fit: true}",

graphtik/sphinxext/_graphtikbuilder.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,26 @@ def _render_dot_image(
153153
fname = f"graphtik-{hasher.hexdigest()}.{img_format}"
154154
abs_fpath = Path(self.outdir, self.imagedir, fname)
155155

156-
## Don not re-write images, that have content-named path,
156+
## Do not re-write images, that have content-named path,
157157
# so they are never out-of-date.
158158
#
159159
self.env.graphtik_image_purgatory.register_doc_fpath(
160160
self.env.docname, abs_fpath
161161
)
162+
if self.config.graphtik_save_dot_files:
163+
self.env.graphtik_image_purgatory.register_doc_fpath(
164+
self.env.docname, abs_fpath.with_suffix(".txt")
165+
)
166+
162167
if not abs_fpath.is_file():
163168
abs_fpath.parent.mkdir(parents=True, exist_ok=True)
164169
dot.write(abs_fpath, format=img_format)
165170
if img_format == "png":
166171
cmap = dot.create(format="cmapx", encoding="utf-8").decode("utf-8")
167172
node.cmap = cmap
173+
if self.config.graphtik_save_dot_files:
174+
with open(abs_fpath.with_suffix(".txt"), "w") as f:
175+
f.write(str(dot))
168176

169177
## XXX: used to work till active-builder attributes were transfered to self.
170178
# rel_fpath = Path(self.imgpath, fname)

0 commit comments

Comments
 (0)