Custom css via the API?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Custom css via the API?

arillbert
Hi,

I am trying to convert an adoc string to a stand-alone file via the ruby API. It works as expected as long as I use the default stylesheet but I would like to use a custom css and  I have failed miserably with this.

Working code for generating an html file with the default style sheet is:

    
...
Asciidoctor.convert(my_adoc_src_string, 
      to_file: "myfile.html,
      safe: :unsafe,
)
...

One version of the invocations I've unsuccessfully tried is:

    
...
Asciidoctor.convert(my_adoc_src_string, 
      to_file: "myfile.html,
      safe: :unsafe,
      attributes: {
        stylesheet: "path/to/my/stylesheet.css",
   }
)
...

The html is still generated using the default style sheet. What am I missing?

My goal is to have my custom css embedded in the output to make it more portable.

Regards
/Anders
Reply | Threaded
Open this post in threaded view
|

Re: Custom css via the API?

abelsromero
Hi,

I am no Ruby expert, but I see this syntax used in a test
    output = Asciidoctor.convert input, backend: :manpage, attributes: { 'xrefstyle' => 'full' }

regards,
Reply | Threaded
Open this post in threaded view
|

Re: Custom css via the API?

mojavelinux
Administrator
Abel is correct, the key in the attributes hash must be a string. So it should look like this:

attributes: {
  'stylesheet' => 'path/to/my/stylesheet.css'
}

Alternately, you can use the shorthand form:

attributes: 'stylesheet=path/to/my/stylesheet.css'


Best Regards,

-Dan

--
Dan Allen (he, him, his) | @mojavelinux | https://twitter.com/mojavelinux
Reply | Threaded
Open this post in threaded view
|

Re: Custom css via the API?

arillbert
This works beautifully. Thank you, thank you, thank you.... :)

/anders
Reply | Threaded
Open this post in threaded view
|

Re: Custom css via the API?

mojavelinux
Administrator
I'm so glad to hear that, anders!

Best Regards,

-Dan

On Thu, Mar 18, 2021 at 1:07 PM arillbert [via Asciidoctor :: Discussion] <[hidden email]> wrote:
This works beautifully. Thank you, thank you, thank you.... :)

/anders


If you reply to this email, your message will be added to the discussion below:
https://discuss.asciidoctor.org/Custom-css-via-the-API-tp8568p8571.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML


--
Dan Allen (he, him, his) | @mojavelinux | https://twitter.com/mojavelinux