Domanda

Running AsciiDoctor from the CLI creates a HTML document with an embedded stylesheet:

$ 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; }
...

However, running Asciidoctor in a Ruby file does not:

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">
...

The documentation doesn't indicate that there should be any difference. What am I missing?

Details:

  • Asciidoctor 0.1.4
  • ruby 2.0.0p247
È stato utile?

Soluzione

To embed the stylesheet, you must have to render the file in the "unsafe" mode:

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

Altri suggerimenti

Technically, you only need to set the safe mode to :server or :safe. Only the :secure safe mode (the default when using the API) forcefully enables the linkcss attribute.

I'm thinking about changing this in 1.5.0. I don't think that adding styles to the full document is insecure in any way. Besides, there are plenty of ways to override this behavior so nothing is lost, but usability is definitely gained.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top