From 6aec4bd4dadd3ff90447da2945dd6887620f8b13 Mon Sep 17 00:00:00 2001 From: Shengyu Zhang Date: Thu, 3 Oct 2024 22:39:09 +0800 Subject: [PATCH] update --- docs/index.rst | 3 +++ src/sphinxnotes/jinja/context.py | 32 +++++++++++++++++++------------ src/sphinxnotes/jinja/template.py | 2 +- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index d4a0968..b5e7e5a 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -15,3 +15,6 @@ Directive: .. ddd:: Hey! I am here. + +.. autoclass:: jinja.context.NodeAdapter + :members: diff --git a/src/sphinxnotes/jinja/context.py b/src/sphinxnotes/jinja/context.py index 09f816e..54359a0 100644 --- a/src/sphinxnotes/jinja/context.py +++ b/src/sphinxnotes/jinja/context.py @@ -76,9 +76,11 @@ def text(self) -> str: @property def title(self) -> NodeAdapter | None: if not isinstance(self.node, (nodes.document, nodes.section)): + print('node:', type(self.node), 'not doc sect') return None title = self.node.first_child_matching_class(nodes.title) if not title: + print('no title') return None return NodeAdapter(self.node[title]) @@ -91,24 +93,20 @@ class TopLevelVarNames(object): super = 'super' git = 'git' -class DirectiveContextVariableNames(object): - arguments = 'args' - options = 'opts' - content = 'content' - +class _MarkupVars(object): name = 'name' rawtext = 'rawtext' source = 'source' lineno = 'lineno' +class _DirectiveVars(_MarkupVars): + arguments = 'args' + options = 'opts' + content = 'content' -class RoleContextVariableNames(object): - text = 'text' - name = 'name' - rawtext = 'rawtext' - source = 'source' - lineno = 'lineno' +class RoleVars(_MarkupVars): + content = 'content' class ContextDirective(SphinxDirective, ContextGenerator): @classmethod @@ -139,7 +137,12 @@ def derive(cls, ) def gen(self) -> dict[str, Any]: + source, lineno = self.get_source_info() ctx = { + 'name': self.name, + 'rawtext': self.block_text, + 'source': source, + 'lineno': lineno, } if self.required_arguments + self.optional_arguments != 0: ctx['args'] = self.arguments @@ -177,8 +180,13 @@ def derive(cls, role_name: str, text_variable_name: str = 'text') -> Type['Conte ) def gen(self) -> dict[str, Any]: + source, lineno = self.get_source_info() ctx = { - 'text': self.text, + 'content': self.text, + 'name': self.name, + 'rawtext': self.rawtext, + 'source': source, + 'lineno': lineno, } return ctx diff --git a/src/sphinxnotes/jinja/template.py b/src/sphinxnotes/jinja/template.py index fcfb234..f34cb95 100644 --- a/src/sphinxnotes/jinja/template.py +++ b/src/sphinxnotes/jinja/template.py @@ -29,7 +29,7 @@ def render(obj: SphinxDirective | SphinxRole, ctx: dict[str, Any]): {% endfor %} title:: - {{ doc.title.text }} + {{ doc.section.title.text }} """ if isinstance(obj, SphinxRole): print('>>>>>>>>>>>>>> is role')