Giter VIP home page Giter VIP logo

asciidoctor-packt's Introduction

43

Writing for Packt with Asciidoctor

In this chapter, you’ll learn:

  • How to create a Packt manuscript using asciidoctor (http://asciidoctor.org)

  • How to write your text calmly, and let the tools do the layouts for you.

  • How to embed images, source code, and create bullets, notes, etc.

  • Über easy ways to write your next book (and even use ü’s!)

If you’ll notice, all lines of that bullet list are tagged Bullet [PACKT], except the last. It’s tagged Bullet End [PACKT].

Getting started

After writing gobs of documents over the past year with AsciiDoc, I was strongly motivated to make that work as I embark on writing Learning Spring Boot.
— Greg L. Turnquist
  1. First, grab this project with git clone [email protected]:gregturn/asciidoc-packt.git

  2. Second, install http://asciidoctor.org

  3. Third, run this book and see what happens!

If you’ll notice, all lines of that numbered list are tagged Numbered Bullet [PACKT], except the last. It’s tagged Numbered Bullet End [PACKT].

To run things, you just need a handy dandy script:

$ asciidoctor -T slim -b packt README.adoc && xmllint -format README.fodt

The output will be compacted XML (FODT), so it will be hard to read. That why running it through xmllint is handy.

Note
You have to ensure xmllint is installed. It’s not part of this project.

You should see a nice output: README.fodt.

$ ls -ltr
total 616
-rw-r--r--@  1 gturnquist  staff   22836 May 30 08:27 packt_template.ott
-rw-r--r--   1 gturnquist  staff  145233 May 30 08:28 packt_template.fodt
drwxr-xr-x   4 gturnquist  staff     136 Jun 18 18:01 slim/
drwxr-xr-x   4 gturnquist  staff     136 Jun 18 20:36 samples/
drwxr-xr-x  11 gturnquist  staff     374 Jun 18 20:36 asciidoc/
-rw-r--r--@  1 gturnquist  staff    6332 Jun 19 08:42 README.adoc
-rw-r--r--   1 gturnquist  staff  131532 Jun 19 08:45 README.fodt

From here, you can start writing your own manuscript for Packt. The core content will be towards the end, inside the <office:body> tag. Everything before hand are Packt’s styles embedded so LibreOffice will make everything look nice.

Does your manuscript live elsewhere, and NOT in the same folder as this project? No problem!

$ asciidoctor -T /path/to/your/clone/of/asciidoc-packt/slim -b packt your.adoc

You should now see a nice output.

Important
In order to open FODT files on Fedora, you must have the libreoffice-xsltfilter package installed.

Cheers!

Warning
I have used this process to successfully publish Learning Spring Boot. I ran into a few hiccups, such as editors reporting they couldn’t see images. I had no problem viewing embedded images, but I had Mac and they had Windows, so who knows? Nonetheless, there are no guarantees provided. If you take this on you assume ALL risk. You have been warned.

Admonitions

Note
This is for notes. They are mapped to Information Box [Packt]

Break…​

Tip
Tips that are side items and break out of the flow of the main text. Mapped to Tip [Packt]

…​things…​

Warning
Warning - Red alert! Put inside a Information Box [Packt] and then wrapped in Italics [Packt]

…​up…​

Caution
Same as warning.

…​or they’ll…​

Important
HIGHLY important. Tip [Packt] with Italics [Packt]

…​run together in a single chunk in LibreOffice.

Quotes

I decided to add quotes. There seemed to a lot of proverbial good ones bubbling up regarding Spring Boot, the topic of this endeavor. So I needed a way to wrap them up properly. It turns out that I preferred the verse over quote, so that’s the styling I have implemented support for.

If Markdown is a 1st-grader, then AsciiDoc is a PhD student.
— Dan Allen

This one simply has the text, wrapped in quotes, followed by a long dash and the speaker’s name.

After writing gobs of documents over the past year with AsciiDoc, I was strongly motivated to make that work as I embark on writing Learning Spring Boot.

If you want to cite the source, add the third clause. It will be appended to the end after a ",". NOTE: There is no additional formatting applied, like URL types. Instead, the entire block is marked up with Packt’s QUOTE style. Hence, you might want to debate if this is REALLY needed.

Code

Nothing is complete without looking at code.

link:samples/app.groovy[role=include]

This chunk of code is Groovy (http://groovy.codehaus.org). It contains the @RestController to flag the entire class as being a controller that returns values directly back to the client, without invoking any views.

Every line of a code listing is marked Code [Packt] except the last. It’s marked Code End [Packt].

Console outputs

Create a listing block, but don’t prefix it with a source flag, and this backend will instead mark it up with Command Line[Packt].

$ asciidoctor -T slim -b packt README.adoc
$ xmllint -format README.fodt | tail -10
      <text:p text:style-name="Normal_20_5b_PACKT_5d_">This README page is structured in the theme of Packt. It might not render perfectly on GitHub, but when viewed through a text editor,
and certainly when converted by this backend to LibreOffice, it should provide a nice example of writing a manuscript for Packt.</text:p>
      <text:p text:style-name="Normal_20_5b_PACKT_5d_">Be advised, the nature of this doc is Packt-like, but don’t assume it represents the proper formatting of a book. This is how to
style things. Formatting governs what sections you’ll have in a chapter. When to use tips, quotes, etc. is strictly editorial and
YOUR responsibility.</text:p>
      <text:p text:style-name="Normal_20_5b_PACKT_5d_">NOTHING is done to make it look good on GitHub, because that is not the target. BUT…why waste a keen opportunity to document both
environments?</text:p>
    </office:text>
  </office:body>
</office:document>

Every line of a code listing is marked Command Line [Packt] except the last. It’s marked Command Line End [Packt].

Screen Text

Text seen on the screen must be wrapped with Screen Text [Packt].

Field Value

`Group'

learningspringboot

`Artifact'

issue-manager

`Name'

Issue Manager

`Description'

Learning Spring Boot

`Package Name'

learningspringboot

`Styles'

`Thymeleaf'

`Type'

`Maven Project'

`Packaging'

`Jar'

`Java Version'

`1.7'

`Language'

`Java'

This table contains embedded options picked from the screen as well as things typed in.

Subsections

Yes, we handle subsections, but so far, only levels 2-5.

  • Level 2 is for the chapter number

  • Level 3 is for the chapter title

  • Level 4 is for major sections

  • Level 5 is for sub-sections

It might be possible to go deeper, but I frankly haven’t needed that yet.

Note
This doesn’t apply to Packt Cookbook formats.
Tables

We sure do cover them. Tables are an integral part of writing any manuscript. Check out the following table.

Stuff Description

asciidoctor

command line tool to parse your doc

packt

name of the backend to process this

slim

THE simplest templating language designed to output XML. See http://slim-lang.com

key word

threw in a keyword inside a table just for fun

Images

Images are embedded through base64 encoding. They are NOT linked to external files.

cat

The backend also embeds a Layout[Packt] tag afterwards with the basename of the file.

Note
It’s up to YOU to properly name the images according to Packt guidelines.

What are some of the things you don’t cover?

Well, there are actually a lot of other styles provided by Packt not handled here.

  • Code-within-Tips

  • Tips-within-Tips

  • Bullets-within-Tips-within-Tips

  • The entire appendix section of Packt’s style guide.

  • etc.

That is too much, and frankly, I don’t much care for that stuff. Too detailed and really pulls me away from writing, so I don’t support it.

Warning
All styles embedded in this backend are owned by Packt Publishing Ltd. (http://packtpub.com) and potentially subject to their copyright notices.

Good to know stuff…​

  • Don’t embed :author: or :title: attributes at the top. They end up getting printed which fouls up the product you must ship to Packt.

  • Because asciidoc considers double-underscores indicators of emphasis, all styles names are edited to replace __ with _ to avoid clashing

In case you didn’t notice

This README page is structured in the theme of Packt. It might not render perfectly on GitHub, but when viewed through a text editor, and certainly when converted by this backend to LibreOffice, it should provide a nice example of writing a manuscript for Packt.

Be advised, the nature of this doc is Packt-like, but don’t assume it represents the proper formatting of a book. This is how to style things. Formatting governs what sections you’ll have in a chapter. When to use tips, quotes, etc. is strictly editorial and YOUR responsibility.

NOTHING is done to make it look good on GitHub, because that is not the target. BUT…​why waste a keen opportunity to document both environments?

asciidoctor-packt's People

Contributors

gregturn avatar mojavelinux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

asciidoctor-packt's Issues

Key_20_Word_20__5b_PACKT_5d_ won't work, but strong does??

Tried to code Keyword, but it goes nuts when plugging in Key_20_Word_20__5b_PACKT_5d_ as the style. So, using what I use in asciidoc: plugin strong and then replace it in post processing, only inside normal/tips/bullets. (Should probably expand post proessing to include numbered lists.)

Entertain code inside tips

Right now, the following chunk doesn't render properly:

[NOTE]
====
Yada yada.

[source,xml]
----
<my-xml>
</my-xml>
----
====

It looks fine in HTML with the code nicely inserted inside the admonition. But in FODT, nothing is visible probably because its a text:p inside a text:p.

Margins

Packt margins are pretty big (4 from each border) while asciidoctor created much smaller margins.

Make admonitions more details

So far, all admonitions result in a Tip. Already need the means to use Information Box. So...might as well come up with way to may all of them.

Obscure error message from asciidoc

I'm trying to use asciidoc-packt
I'd be grateful if someone could interpret the following error message
asciidoc: FAILED: asciidoc_manual.txt: line 8: illegal [miscellaneous] subsverbatim: specialcharacters,callouts,replacements3: replacements3

That was in response to this command
asciidoc -b packt --theme packt asciidoc_manual.txt

I'm running on Ubuntu 12.04

In case its relevant, here is what I did to install packt-theme-0.1.0.zip
sudo asciidoc --theme install packt-theme-0.1.0.zip /etc/asciidoc/themes/packt

And the second zip (packt-backend-0.1.0.zip)
sudo asciidoc --backend install packt-backend-0.1.0.zip /etc/asciidoc/backends/packt

Image include issue

I cannot have an inline image in the asciidoc file unless I know the aspect ratio. If I do not specify width and height then the picture will be a thumbnail.

If I say image:: .... [width="100%"]

then the height will be zero, and I get a line.

If I say image:: .... [width="100%" heigth="50%"]

then the image will be distorted based on the original aspect ratio and the size of the page (note 50% can be practically anything).

My workaround is that I have a python script that reads the width and the height from the SVG file and then inserts it automatically into the manuscript, but this is a hack.

Title

Hi,
Thanks a lot for this tool :).
I've noticed that the titles do not appear as "Heading 1,Heading 1 [PACKT]" but as "Heading 1". Is this because Packt has "copied" standard headings or it this a bug?

Thanks again for creating a sharing this awesome tool :), you made my day.

Are callouts supported?

I'm seeing this when using code sections with callouts.

Caused by: org.jruby.exceptions.RaiseException: (RuntimeError) Could not find a converter to handle transform: inline_callout

image::foo.png not working

I used docbook's image.xml.slim as a basis, but it won't insert any of the attributes.

I have:

text:p text:style-name="imageblock" 
  draw:frame draw:style-name="imageblock" draw:name="image" text:anchor-type="paragraph" draw:z-index="1" svg:width="(attr :width)" svg:height="(attr :height)" 
    draw:image xlink:href="(@target)" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"

docbook has:

figure id=@id role=(attr :role) xreflabel=(attr :reftext)
  - if title?
    title=title
  mediaobject
    imageobject
      imagedata fileref=image_uri(attr :target) contentwidth=(attr :width) contentdepth=(attr :height) scale=(attr :scale) width=(attr :scaledwidth) scalefit=((attr? :scaledwidth) ? 1 : nil) align=(attr :align)
    textobject: phrase=attr :alt

Might be the double quotes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.