mirror of
https://github.com/zeek/zeek.git
synced 2025-10-03 15:18:20 +00:00
Teach sphinx a new ".. rootedliteralinclude::" directive.
It's like ".. literalinclude::" except the argument is an absolute path which may contain environment variables to be be expanded when generating documents.
This commit is contained in:
parent
c453c228cb
commit
01090cf09f
2 changed files with 29 additions and 1 deletions
25
doc/ext/rootedliteralinclude.py
Normal file
25
doc/ext/rootedliteralinclude.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
import os
|
||||
from sphinx.directives.code import LiteralInclude
|
||||
|
||||
def setup(app):
|
||||
app.add_directive('rootedliteralinclude', RootedLiteralInclude)
|
||||
|
||||
class RootedLiteralInclude(LiteralInclude):
|
||||
"""
|
||||
Like ``.. literalinclude::``, but the argument is an absolute path
|
||||
which may contain environment variables which will be expanded when
|
||||
generating documents.
|
||||
"""
|
||||
|
||||
def run(self):
|
||||
document = self.state.document
|
||||
if not document.settings.file_insertion_enabled:
|
||||
return [document.reporter.warning('File insertion disabled',
|
||||
line=self.lineno)]
|
||||
env = document.settings.env
|
||||
|
||||
expanded_arg = os.path.expandvars(self.arguments[0])
|
||||
sphinx_src_relation = os.path.relpath(expanded_arg, env.srcdir)
|
||||
self.arguments[0] = os.path.join(os.sep, sphinx_src_relation)
|
||||
|
||||
return super(RootedLiteralInclude, self).run()
|
Loading…
Add table
Add a link
Reference in a new issue