使用 docutils.core.publish_string 而不是publish_cmdline,携带 HTML 特定选项的“settings_overrides”参数不起作用!
下面是我的代码,
from docutils.core import publish_string
from docutils.writers.html4css1 import Writer as HisWriter
args = {
'stylesheet' : '/home/wonder/lab/css/note.css',
'stylesheet-path' : None,
}
src = 'ccav'
print publish_string(src, writer=HisWriter(), settings_overrides=args)
我收到以下错误:
AssertionError: stylesheet and stylesheet_path are mutually exclusive.
因此,我将 args 更改为:
args = {
'stylesheet-path' : '/home/wonder/lab/css/note.css',
'stylesheet' : None,
}
现在,没有错误了。但是,插入到 HTML 输出中的样式表不是 /home/wonder/lab/css/note.css
的内容。它仍然是 /usr/local/lib/python2.7/dist-packages/docutils/writers/html4css1/html4css1.css
。
也就是说,与使用publish_cmdline时在命令行中指定选项不同,使用publish_string时,携带HTML特定选项的settings_overrides
参数不起作用。
Below is my code
from docutils.core import publish_string
from docutils.writers.html4css1 import Writer as HisWriter
args = {
'stylesheet' : '/home/wonder/lab/css/note.css',
'stylesheet-path' : None,
}
src = 'ccav'
print publish_string(src, writer=HisWriter(), settings_overrides=args)
I got the following error:
AssertionError: stylesheet and stylesheet_path are mutually exclusive.
So, I change args
to:
args = {
'stylesheet-path' : '/home/wonder/lab/css/note.css',
'stylesheet' : None,
}
Now, There is no errors. But, The stylesheet inserted into the HTML output is not the content of /home/wonder/lab/css/note.css
. It is still /usr/local/lib/python2.7/dist-packages/docutils/writers/html4css1/html4css1.css
.
That is to say, unlike specify options in command line when using publish_cmdline, the settings_overrides
argument carrying HTML-Specific Options takes no effect when using publish_string.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要执行
settings = None
并使用stylesheet_path
而不是stylesheet
来让它忽略内置样式表。编辑:请注意,我在 distutils 附带的示例脚本之一的源代码中找到了这个答案,因此即使
settings = None
看起来很糟糕,但似乎并非如此。You need to do
settings = None
and usestylesheet_path
rather thanstylesheet
to get it to ignore the built in stylesheet.Edit: Note that I found this answer in the source of one of the example scripts that comes with distutils, so even though
settings = None
seems bad, it doesn't seem to be.