Login  Register

asciidoctorj generates different HTML than command line asciidoctor

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

asciidoctorj generates different HTML than command line asciidoctor

gregturn
My source README.adoc starts off like this:
=================================
---
categories: [rest,json,jackson,springmvc]
---
:toc:
:project_id: gs-rest-service
:spring_version: 3.2.4.RELEASE
:spring_boot_version: 0.5.0.M4
:icons: font
:source-highlighter: prettify

This guide walks you through the process of creating a "hello world" link:/understanding/REST[RESTful web service] with Spring.
...
==================================

When I run command line asciidoctor -S safe -a allow-uri-read,skip-front-matter README.adoc (because I have some include::https://urls/to/remote.adoc[] calls), this is what I see in README.html...

==================================
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="generator" content="Asciidoctor 0.1.4">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>What you’ll build</title>
<style> ...asciidoctor's styling </style><link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/3.2.1/css/font-awesome.min.css">
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.css">
<script src="http://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.js"></script><script>document.addEventListener('DOMContentLoaded', prettyPrint)</script></head>
<body class="article">
<div id="header">
<div id="toc" class="toc">
<div id="toctitle">Table of Contents</div>
...
==================================

But when the same document is run through asciidoctorj inside my web app like this:

==================================
    private final Asciidoctor asciidoctor = Asciidoctor.Factory.create();
...
            Attributes attributes = new Attributes();
            attributes.setAllowUriRead(true);
            attributes.setSkipFrontMatter(true);
            File readme = new File(unzippedRoot.getAbsolutePath() + File.separator + "README.adoc");
            content = asciidoctor.renderFile(
                    readme,
                    OptionsBuilder.options().safe(SafeMode.SAFE).attributes(attributes));
==================================

...this is what I see:

==================================
<div class="paragraph">
<p>This guide walks you through the process of creating a "hello world" RESTful web service with Spring.</p>
</div>
...
==================================

It appears the entire <html><header></header></html> part has been stripped out and only that which is inside the <div id="content"> tag. Is there a setting to give me ALL the HTML? I wanted to run a Jsoup query and extract the table of contents so I can stuff it in a sidebar. But that doesn't appear visible.
Greg Turnquist (@gregturn)
Author of Darklight and Hacking with Spring Boot 2.3
Sign up for my newsletter and get a FREE e-book
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: asciidoctorj generates different HTML than command line asciidoctor

gregturn
UPDATE: When I render the document "in place", then the HTML file on disk appears to have everything. Is this by design?

            Attributes attributes = new Attributes();
            attributes.setAllowUriRead(true);
            attributes.setSkipFrontMatter(true);
            File readme = new File(unzippedRoot.getAbsolutePath() + File.separator + "README.adoc");
            asciidoctor.renderFile(
                    readme,
                    OptionsBuilder.options().safe(SafeMode.SAFE).attributes(attributes).inPlace(true));
            content = StreamUtils.copyToString(new FileInputStream(new File(unzippedRoot.getAbsolutePath() + File.separator + "README.html")),
                    Charset.defaultCharset());
Greg Turnquist (@gregturn)
Author of Darklight and Hacking with Spring Boot 2.3
Sign up for my newsletter and get a FREE e-book
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: asciidoctorj generates different HTML than command line asciidoctor

mojavelinux
Administrator

Greg,

Whenever you invoke Asciidoctor through an API (either the Ruby one or the Java one), the document is rendered as embeddable HTML (body only, no header & footer). You'll need to explicitly enable the header/footer option in the API.

OptionsBuilder.options().headerFooter(true)

The one exception is when you write directly to disk. Since writing embeddable HTML in a standalone file rarely makes sense, we follow the intent.

The history behind this default in the API is that it was once a requirement for Asciidoctor to run on GitHub. We've kept it for backwards compatibility reasons.

Hopefully that clears things up!

-Dan

On Nov 27, 2013 6:47 AM, "gregturn [via Asciidoctor :: Discussion]" <[hidden email]> wrote:
UPDATE: When I render the document "in place", then the HTML file on disk appears to have everything. Is this by design?

            Attributes attributes = new Attributes();
            attributes.setAllowUriRead(true);
            attributes.setSkipFrontMatter(true);
            File readme = new File(unzippedRoot.getAbsolutePath() + File.separator + "README.adoc");
            asciidoctor.renderFile(
                    readme,
                    OptionsBuilder.options().safe(SafeMode.SAFE).attributes(attributes).inPlace(true));
            content = StreamUtils.copyToString(new FileInputStream(new File(unzippedRoot.getAbsolutePath() + File.separator + "README.html")),
                    Charset.defaultCharset());


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/asciidoctorj-generates-different-HTML-than-command-line-asciidoctor-tp1137p1138.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: asciidoctorj generates different HTML than command line asciidoctor

gregturn
Perfect! Change applied. I figured there was a historical basis for that with a switch. :)
Greg Turnquist (@gregturn)
Author of Darklight and Hacking with Spring Boot 2.3
Sign up for my newsletter and get a FREE e-book