Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverRainZ committed Oct 3, 2024
1 parent d9826d5 commit 6aec4bd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
3 changes: 3 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ Directive:
.. ddd:: Hey!

I am here.

.. autoclass:: jinja.context.NodeAdapter
:members:
32 changes: 20 additions & 12 deletions src/sphinxnotes/jinja/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/sphinxnotes/jinja/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 6aec4bd

Please sign in to comment.