diff --git a/lib/esbonio/changes/874.fix.md b/lib/esbonio/changes/874.fix.md new file mode 100644 index 000000000..473327195 --- /dev/null +++ b/lib/esbonio/changes/874.fix.md @@ -0,0 +1 @@ +Esbonio's preview generation should no longer conflict with extensions like `ablog` which call methods like `replac_self()` on custom doctree nodes. diff --git a/lib/esbonio/esbonio/sphinx_agent/handlers/webview.py b/lib/esbonio/esbonio/sphinx_agent/handlers/webview.py index 33aff9e0f..7bcf87ca3 100644 --- a/lib/esbonio/esbonio/sphinx_agent/handlers/webview.py +++ b/lib/esbonio/esbonio/sphinx_agent/handlers/webview.py @@ -15,6 +15,7 @@ STATIC_DIR = (pathlib.Path(__file__).parent.parent / "static").resolve() +ALLOWED_MODULES = {"docutils.nodes", "sphinx.addnodes"} def has_source(node): @@ -31,6 +32,16 @@ def has_source(node): if isinstance(node, addnodes.toctree) and version_info[0] < 7: return False + # It's not only limited to `toctreenodes`! + # + # The identical error is thrown when using esbonio with the `ablog` extension + # See: https://github.com/swyddfa/esbonio/issues/874 + # + # I think for now, the safest approach is to only handle nodes defined by Sphinx or + # docutils. + if node.__module__ not in ALLOWED_MODULES: + return False + return (node.line or 0) > 0 and node.source is not None