Asciidoctor渲染文件缺少CSS。

3

从CLI运行AsciiDoctor将创建一个带有嵌入样式表的HTML文档:

$ asciidoctor mysample.adoc

....
<title>My First Experience with the Dangers of Documentation</title>
<style>
/* Asciidoctor default stylesheet | MIT License | http://asciidoctor.org */
article, aside, details, figcaption, figure, footer, header, hgroup, main, nav, section, summary { display: block; }
...

然而,在 Ruby 文件中运行 Asciidoctor 并不行:
r.rb:

#!/usr/bin/env ruby

require 'asciidoctor'
Asciidoctor.render_file('mysample.adoc', :in_place => true)

$ ./r.rb

...
<title>My First Experience with the Dangers of Documentation</title>
<link rel="stylesheet" href="./asciidoctor.css">
...
文档中没有说明应该有任何区别。我错过了什么吗?
详细信息:
  • Asciidoctor 0.1.4
  • ruby 2.0.0p247
2个回答

6

要嵌入样式表,您必须以“不安全”模式呈现文件:

require 'asciidoctor'
Asciidoctor.render_file('mysample.adoc', :in_place => true, :safe => 'unsafe')

1
为了将其嵌入到 guardfile 中,我必须使用语法 Asciidoctor.render_file('mysample.adoc', {:in_place => true, :safe => :unsafe}) - craig

1
技术上,你只需要将safe mode设置为:server或:safe。仅在使用API时默认的:secure safe mode强制启用linkcss属性。
我正在考虑在1.5.0中更改此设置。我认为在任何情况下都不会将样式添加到整个文档中是不安全的。此外,有很多方法可以覆盖此行为,因此不会有任何损失,但肯定会提高可用性。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接