- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
考虑具有此框架的 reStructuredText 文档:
Main Title
==========
text text text text text
Subsection
----------
text text text text text
.. my-import-from:: file1
.. my-import-from:: file2
my-import-from
指令由文档特定的 Sphinx 扩展提供,它应该读取作为其参数提供的文件,解析嵌入其中的 reST,并将结果注入(inject)为当前输入文件中的一个部分。 (类似于 autodoc,但文件格式不同。)我现在拥有的代码如下所示:
class MyImportFromDirective(Directive):
required_arguments = 1
def run(self):
src, srcline = self.state_machine.get_source_and_line()
doc_file = os.path.normpath(os.path.join(os.path.dirname(src),
self.arguments[0]))
self.state.document.settings.record_dependencies.add(doc_file)
doc_text = ViewList()
try:
doc_text = extract_doc_from_file(doc_file)
except EnvironmentError as e:
raise self.error(e.filename + ": " + e.strerror) from e
doc_section = nodes.section()
doc_section.document = self.state.document
# report line numbers within the nested parse correctly
old_reporter = self.state.memo.reporter
self.state.memo.reporter = AutodocReporter(doc_text,
self.state.memo.reporter)
nested_parse_with_titles(self.state, doc_text, doc_section)
self.state.memo.reporter = old_reporter
if len(doc_section) == 1 and isinstance(doc_section[0], nodes.section):
doc_section = doc_section[0]
# If there was no title, synthesize one from the name of the file.
if len(doc_section) == 0 or not isinstance(doc_section[0], nodes.title):
doc_title = nodes.title()
doc_title.append(make_title_text(doc_file))
doc_section.insert(0, doc_title)
return [doc_section]
这是可行的,除了新部分是作为当前部分的子注入(inject)的,而不是兄弟。换句话说,上面的示例文档生成了一个像这样的 TOC 树:
- Main Title
- Subsection
- File1
- File2
而不是想要的
- Main Title
- Subsection
- File1
- File2
我该如何解决这个问题? Docutils 文档……不充分,尤其是在控制部分深度方面。我尝试过的一件明显的事情是返回 doc_section.children
而不是 [doc_section]
;从 TOC 树中完全删除 File1
和 File2
(但确实使文档正文中的节标题出现是为了正确嵌套级别)。
最佳答案
我认为不可能通过从指令中返回该部分来做到这一点(不按照 Florian 建议的方式进行操作),因为它将附加到“当前”部分。但是,您可以通过 self.state.section
添加该部分,就像我在下面所做的那样(为简洁起见删除了选项的处理)
class FauxHeading(object):
"""
A heading level that is not defined by a string. We need this to work with
the mechanics of
:py:meth:`docutils.parsers.rst.states.RSTState.check_subsection`.
The important thing is that the length can vary, but it must be equal to
any other instance of FauxHeading.
"""
def __init__(self, length):
self.length = length
def __len__(self):
return self.length
def __eq__(self, other):
return isinstance(other, FauxHeading)
class ParmDirective(Directive):
required_arguments = 1
optional_arguments = 0
has_content = True
option_spec = {
'type': directives.unchanged,
'precision': directives.nonnegative_int,
'scale': directives.nonnegative_int,
'length': directives.nonnegative_int}
def run(self):
variableName = self.arguments[0]
lineno = self.state_machine.abs_line_number()
secBody = None
block_length = 0
# added for some space
lineBlock = nodes.line('', '', nodes.line_block())
# parse the body of the directive
if self.has_content and len(self.content):
secBody = nodes.container()
block_length += nested_parse_with_titles(
self.state, self.content, secBody)
# keeping track of the level seems to be required if we want to allow
# nested content. Not sure why, but fits with the pattern in
# :py:meth:`docutils.parsers.rst.states.RSTState.new_subsection`
myLevel = self.state.memo.section_level
self.state.section(
variableName,
'',
FauxHeading(2 + len(self.options) + block_length),
lineno,
[lineBlock] if secBody is None else [lineBlock, secBody])
self.state.memo.section_level = myLevel
return []
关于python - docutils/sphinx 自定义指令创建兄弟部分而不是子部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20912467/
我的目标是运行类似 bro --iface 的命令并只获取 conn.log,但我无法从 Bro 文档或联机帮助页中得知如何执行此操作。 谢谢。 最佳答案 这让你继续: bro -i -b b
我正在使用以下 jQuery 来更改无序列表中元素的类。这似乎不是实现该效果的最有效方法。有更好的写法吗? $(function() { $('nav li a').click( functi
我有一个看起来像这样的导航栏 Services Work Contact 当我 :hover 一项时,我想更改其他两项的样式。我可以使用什么 CSS 选择器? 最佳答案 您
我正在寻找一种方法来选择包含特定图像的列的行内具有特定名称属性的所有输入。 下面的代码是一个说明性示例:
假设我有以下 HTML: 我想在鼠标悬停在元素上时对图标应用一些规则,可以用以下 CSS 描述: .navigation__item__icon { color: black; } .n
我的 div text-button 没有与我在其兄弟 div 下想要的正确边距对齐。我将 position: absolute; 设置到位,因为每次我将其设置为相对位置时,jQuery 动画都不起作
这个问题在这里已经有了答案: CSS margin terror; Margin adds space outside parent element [duplicate] (7 个答案) 关闭
如果我有 3 个 NSManagedObjectContext。 一个。是根上下文。 B.是一个后台保存上下文,解析一个JSON后生成NSManagedObjects C.是在 NSFetchedRe
我在容器中有三个 div:http://jsfiddle.net/fBe9y/ 一个div内容很多。如何让内容较少的其他两个 div 与最长的 div 的高度匹配? 我尝试将 height: 100%
我正在尝试通过单击另一个元素对一个元素执行一个简单的 toggleClass。有多个元素具有相同的类,我只想切换同级/最近的元素。我相信我从根本上理解了针对 parent / child / sibl
我正在使用 AngularJS 开发一个小应用程序。我的项目包含一个包含 3 个 View 的 Body.html 文件:SideMenu、Header 和 Content,每个 View 都有自己的
在 CSS 方面,我不认为我是个笨蛋,但这个就是我。我的想法是我需要一个父元素,两侧有两个 float 子元素。我希望 parent 的高度与 child 的高度一样高,并让 child 的高度变得相
我有两个 span(s) 在父级 div 中彼此相邻。 我希望第二个 span 显示在最左边,然后是第一个 span。 (注意:由于某些原因,我不能简单地移动第二个跨度来代
今天跟大家分享下selenium中根据父子、兄弟、相邻节点定位的方法,很多人在实际应用中会遇到想定位的节点无法直接定位,需要通过附近节点来相对定位的问题,但从父节点定位子节点容易,从子节点定位父节点
这是 HTML 的结构:
我在一个包装器中并排放置了两个 div。其中一个 div 的内容比另一个多,我希望第二个 div 填充包装的垂直空间。 .wrapper { height: 50%; width: 50%;
我的网站顶部有一个带有此 CSS 的菜单: .menu { width: 100%; display: block; float: left; } 在里面,我有几个 div: .menu .menu-
我有两个 div 元素,第一个 div 中有一个按钮,如下所示。 Click 下面是我的 JavaScript 代码。 function nextDiv(el
两个同级 div(#one 和 #two),每个都包含一些文本。 我移动#two margin-top 为负,预计它会覆盖 #one , 但当文本位于 #one 前面时,背景位于下方。 只有在 #on
我有一个容器 div,它有一个 float 的左侧导航 Pane 和一个右侧的内容 Pane : CSS: body { text-align: cent
我是一名优秀的程序员,十分优秀!