Mike Rules!

It's not much. But, it does what I want.

Introduction

A long-long time ago while working at IBM, I liked to use to use a program called GML to format my c-language source code for printing. By adding a few simple tags inclosed in c-language comments, my printouts would include a title page, table of contents, and page numbers. You would think that in this time of you can find anything in the internet, that someone would have written a GML processor for Windows or Linux. If they have, I have not seen it.

Instead, I stumbled upon something called AsciiDoc. This is a Python program that processes text files containing "tags" and generates formatted output in many formats including HTML, Markdown, Word Documents, and PDFs. It does much more, but those are the formats I am primarily interested in generating.

I suspect that it is possible to edit the AsciiDoc configuration files to do what I used to do with GML. It appears that this requires knowing how AsciiDoc works with regular expressions. I have come to the opinion over my carrier that if you need to use regular expressions to accomplish a task, you are doing it wrong. I am convinced that regular expressions were created by Satin himself.

Instead, I created a fairly simple program in C that reads my source code file with a few added tags and outputs a file that AsciiDoc uses as input.

You can go here to read more about it.

HTML

When I want to share a document, I usually generate an HTML file that I share. Few want to see the raw text file. Here is the command that does the trick.

asciidoc --backend html5 -a data-uri my_input_file.txt

The option -a data-uri embeds any images as part of the HTML file for easier sharing.

MS Word (DOCX)

Generating an MS Word compatible file is a two-step process. AsciiDoc converts the text file into a xlm format. Then a second program called pandoc converts the xml file into a docx file.

asciidoc --backend docbook my_input_file.txt
pandoc --from docbook --to docx --output=my_input_file.docx my_input_file.xml

The resulting Word file needs editing before you can consider it complete. Pandoc does not format the tables as shown in the HTML version and your title page will need lots of help. However, it is easier to fix the formatting then start with a blank sheet of paper.

Maybe pandoc can be customized to fix these problems. I’ll have to take some time to research this.

PDF

I use another program along with AsciiDoc to generate PDF files from text files. The program is called dblatex. Here is the command that does the trick.

asciidoc --backend docbook45 my_input_file.txt
dblatex  --pdf my_input_file.xml

The output looks nice enough. However, images are not sized correctly and the original may need to be sized to appear correct in the PDF. In the text document, set the image size width to 400 to make the figure fit.

.Block Diagram
image:BlockDiagram.jpg["Block Diagram",width=400]

There must be a better way…

Markdown (MD)

When working with a GIT repository, it helps to include related notes in Markdown (MD) format. To create Markdown files using AsciiDoc, use the following commands.

# convert asciidoc to docbook
asciidoc -b docbook my_input_file.txt

# convert docbook to markdown
pandoc -f docbook -t markdown_strict my_input_file.xml -o my_input_file.md

I suggest saving both the text file and markdown file in the repository. There is no need to save the xml file.

Diagrams

I settled on using ditaa style diagrams in my documents. As raw text, you can read them just fine. As compiled asciidoc output, they look even better. Getting the ditaa processor to work took a little doing.

To install it, go here and download the zip file. Create a folder named "dita" in the asciidoc filters folder. For my install, here is the command line.

sudo mkdir /usr/bin/asciidoc-8.6.9/filters/ditaa

Unzip the asciidoc-ditaa-filter file. Copy all the files to the ditaa folder you created above.

With that, you can change this…

["ditaa"]
---------------------------------------------------------------------
 +--------------------+
 |                    |
 |  In the Beginning  |
 |                    |
 +----------+---------+
            |
            |
            v
 +---------------------+
 |                     |
 |       The End       |
 |                     |
 +---------------------+
---------------------------------------------------------------------

…into this…

asciidoc__1.png

Kinda cool…

ascii-flow

To edit ascii-art flow diagrams, I like to use this site - ascii-flow. Start by copying your existing diagram into the editor, make your changes, and then export (copy) them back out.