使用 docutils.core.publish_string 而不是publish_cmdline,携带 HTML 特定选项的“settings_overrides”参数不起作用!

发布于 2024-11-25 14:33:39 字数 874 浏览 2 评论 0原文

下面是我的代码,

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千年*琉璃梦 2024-12-02 14:33:39
from docutils.core import publish_string
from docutils.writers.html4css1 import Writer as HisWriter

src = 'ccav'
args = {
    'stylesheet_path' : '/path/to/your/stylesheet'

}
print publish_string(src, writer=HisWriter(), settings=None, settings_overrides=args)

您需要执行 settings = None 并使用 stylesheet_path 而不是 stylesheet 来让它忽略内置样式表。

编辑:请注意,我在 distutils 附带的示例脚本之一的源代码中找到了这个答案,因此即使 settings = None 看起来很糟糕,但似乎并非如此。

from docutils.core import publish_string
from docutils.writers.html4css1 import Writer as HisWriter

src = 'ccav'
args = {
    'stylesheet_path' : '/path/to/your/stylesheet'

}
print publish_string(src, writer=HisWriter(), settings=None, settings_overrides=args)

You need to do settings = None and use stylesheet_path rather than stylesheet 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文