How to Set xhtml Backend with Asciidoctor.js?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to Set xhtml Backend with Asciidoctor.js?

craigshoemaker
How do you generate XHTML using Asciidoctor.js? I have the following set up in my Node.js application:
const asciidoctor = require('asciidoctor.js')();
const opal = asciidoctor.Opal;

var options = opal.hash2(
    ['attributes'],
    {
        attributes: ['showtitle']
    });

var asciidoc = `= Test
:backend: xhtml

image:screenshot.png[alt="screenshot"]`;

var html = opal.Asciidoctor.$convert(asciidoc, options);
And while I am setting the backend to xhtml, the generated HTML is not XHTML markup. Do I need to explicitly load the XHTML backend, or perhaps I am doing something else wrong?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to Set xhtml Backend with Asciidoctor.js?

mojavelinux
Administrator
Craig,

The problem is the way in which you are specifying the options. The options should be defined as follows:

var options = opal.hash({safe: 'safe', attributes: ['showtitle']});

You don't need all that nested data structure business inside hash2(). You can just pass JSON directly to hash().

In order to set the backend from the document itself, you have to use safe mode "safe" or "unsafe". In the the default safe mode, "secure", the backend in the document is ignored. You can force the backend in any safe mode using an option:

var options = opal.hash({backend: 'xhtml', attributes: ['showtitle']});

Here's the complete script I used:

var options = opal.hash({backend: 'xhtml', attributes: ['showtitle']});
var asciidoc = "= Test\n\nimage:screenshot.png[screenshot]";
var html = asciidoctor.$convert(asciidoc, options);
console.log(html);

Do I need to explicitly load the XHTML backend?

No, the html and xhtml converter are the same converter. The leading "x" just changes a setting inside the converter.

-Dan

On Thu, Sep 15, 2016 at 10:46 AM, craigshoemaker [via Asciidoctor :: Discussion] <[hidden email]> wrote:
How do you generate XHTML using Asciidoctor.js? I have the following set up in my Node.js application:
const asciidoctor = require('asciidoctor.js')();
const opal = asciidoctor.Opal;

var options = opal.hash2(
    ['attributes'],
    {
        attributes: ['showtitle']
    });

var asciidoc = `= Test
:backend: xhtml

image:screenshot.png[alt="screenshot"]`;

var html = opal.Asciidoctor.$convert(asciidoc, options);
And while I am setting the backend to xhtml, the generated HTML is not XHTML markup. Do I need to explicitly load the XHTML backend, or perhaps I am doing something else wrong?


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/How-to-Set-xhtml-Backend-with-Asciidoctor-js-tp4957.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux
Loading...