Skip to content

Commit 2218fc8

Browse files
committed
translator: introduce _warnref call
Adding a utility call to help print warning messages that automatically handle printing source location with line numbers (if available). This is to allow other calls to utilize this capability, instead of just the unknown_node hook. Signed-off-by: James Knight <[email protected]>
1 parent 073778b commit 2218fc8

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

sphinxcontrib/confluencebuilder/translator.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,7 @@ def unknown_visit(self, node):
165165
handler[node_name](self, node)
166166
raise nodes.SkipNode
167167

168-
if node.source:
169-
lpf = f'#{node.line}' if node.line else ''
170-
self.warn(f'unknown node {node_name}: {node.source}{lpf}')
171-
else:
172-
self.warn(f'unknown node {node_name}: {self.docname}')
168+
self._warnref(node, f'unknown node {node_name}')
173169

174170
raise nodes.SkipNode
175171

@@ -506,3 +502,22 @@ def _fetch_alignment(self, node):
506502
alignment = self.encode(alignment)
507503

508504
return alignment
505+
506+
def _warnref(self, node, msg):
507+
"""
508+
generate a warning with a reference to the source/line number (or doc)
509+
510+
A helper used to generate a warning that includes the source with line
511+
number or a document name. This is to make it easier for a user to know
512+
where the warning originated from.
513+
514+
Args:
515+
node: the node
516+
msg: the message
517+
"""
518+
519+
if node.source:
520+
lpf = f'#{node.line}' if node.line else ''
521+
self.warn(f'{msg}: {node.source}{lpf}')
522+
else:
523+
self.warn(f'{msg}: {self.docname}')

0 commit comments

Comments
 (0)