title: Using App::Basis::ConvertText2 format: pdf author: Kevin Mulholland keywords: perl, readme, markdown template: default date: 2017-02-28 version: 8
If you are reading this document as a markdown document you may want to try [README PDF] as an alternative. This have been generated from this file and the software provided by this distribution.
This is a perl module and a script that makes use of %TITLE%
This is a wrapper for [pandoc] implementing extra fenced code-blocks to allow the creation of charts and graphs etc. Documents may be created a variety of formats. If you want to create nice PDFs then it can use [PrinceXML] to generate great looking PDFs or you can use [wkhtmltopdf] to create PDFs that are almost as good, the default is to use pandoc which, for me, does not work as well.
HTML templates can also be used to control the layout of your documents.
The fenced code block handlers are implemented as plugins and it is a simple process to add new ones.
There are plugins to handle
- ditaa
- mscgen
- graphviz
- uml
- gnuplot
- gle
- sparklines
- charts
- barcodes and qrcodes
- and many, many others
As a perl module you can obtain it from https://metacpan.org/pod/App::Basis::ConvertText2 or install
cpanm App::Basis::ConvertText2
Alternatively it is available from https://github.com/27escape/App-Basis-ConvertText2
You will then be able to use the ct2 script to process files
If you are reading this document in PDF form, then note that all the images are created by the various plugins and included in the output, there is no store of pre-built images. That you can read this proves the plugins all work!
Most of the chapters are based around the various plugins that are available and the commands that they expose.
If you are just creating simple things, then you do not need a document header, but to make full use of the templating system, having header information is vital.
Example |
---|
title: App::Basis::ConvertText2 format: pdf date: 2014-05-12 author: Kevin Mulholland keywords: perl, readme template: coverpage version: 5 |
As you can see, we use a series of key value pairs separated with a colon. The keys may be anything you like, except for the following which have special significance.
- format shows what output format we should default to.
- template shows which template we should use
The keys may be used as variables in your document or in the template, by upper-casing and prefixing and postfixing percent symbols '%'
Example |
---|
version as a variable %VERSION% |
If you want to display the name of a variable without it being interpreted, prefix it with a backslash '', this will be removed in the final document.
Example | Output |
---|---|
%TITLE% | %TITLE% |
- Variables used within the content area of a code-block will be evaluated before processing that block, if a variable has not yet been defined or saved to a buffer then it will only be evaluated at the end of document processing, so output may not be as expected.
- Variables used in markdown tables may not do what you expect if the variable is multi-line.
As documents are processed, the HTML headers (H2..H6) are collected together to make a table of contents. This can be used either in your template or document using the TOC variable.
Example |
---|
%TOdC% |
The built table of contents is at the top of this document.
Note that if using a TOC, then the HTML headers are changed to have a number prefixed to them, this helps ensure that all the TOC references are unique.
If you do not want an item added to the toc add the class 'toc_skip' to the header (or skiptoc)
Example |
---|
### Skipping header {.toc_skip} |
Hopefully you can see that the header for this section is not in the TOC
This feature is disabled at the moment while bugs are fixed.
There are certain statements that you may want to draw attention to by taking them out of the contentโs flow and labeling them with a priority. These are called admonitions. Itโs rendered style is determined by the assigned label (i.e., value). We provide twelve admonition style labels:
- NOTE
- INFO
- TIP
- IMPORTANT
- CAUTION
- WARNING
- DANGER
- TODO
- ASIDE
- QUESTION
- FIXME
- ERROR
When you want to call attention to a single paragraph, start the first line of the paragraph with the label you want to use. The label must be uppercase and followed by a colon ':'
WARNING: Something could go wrong if you do not follow the rules
- The label must be uppercase and immediately followed by a colon ':'
- Separate the first line of the paragraph from the label by a single space.
- Title is the name of the admonition, unless specified - see below
And here is the generated Admonition
WARNING: Something could go wrong if you do not follow the rules
Titles may be included in admonitions, add them in within brackets, note that there are no spaces between the admonition name and the colon.
NOTE(title for note): Something could go wrong if you do not follow the rules
And here is an example with a title
NOTE(title for note): Something could go wrong if you do not follow the rules
All the Admonitions have associated icons.
Normal Markup may be used in the paragraph.
Admonitions are processed before the rest of the document, so you cannot put their contents into buffers and expect them to work correctly.
Admonitions are a short cut to Admonition Boxes which allow multiple paragraphs to be used.
Font Awesome provides many useful icons,see [Font Awesome Cheatsheet], however there is a lot of hassle to add them to your document; we of course offer a simple shortcut, with the form
\:fa:font-name
E.g.
\:fa:trash
Will display a :fa:trash icon.
NOTE: We do not use the preceding 'fa-' in the name as Font Awesome does.
So 'trash' rather than 'fa-trash'.
It is possible to scale the images, give them colors and apply CSS classes to them by adding this information in square brackets
E.g.
\:fa:trash:[2x]
The options are
- size [lg], [2x], [3x], [4x], [5x]
- :fa:trash:[lg] :fa:trash:[2x], :fa:trash:[3x], :fa:trash:[4x], :fa:trash:[5x].
- foreground color [#red]
- :fa:trash:[2x #red]
- foreground and background color [#yellow.black]
- :fa:trash:[2x #yellow.black]
- rotate [90], [180], [270]
- :fa:flask:[2x 90], :fa:flask:[2x 180], :fa:flask:[2x 270]
- flip vertical [flipv]
- :fa:flask:[2x] vs :fa:flask:[2x flipv]
- flip horizontal [fliph]
- :fa:graduation-cap:[2x] vs :fa:graduation-cap:[2x fliph]
- fixed width [fw]
- :fa:gamepad:[2x]. vs :fa:gamepad:[2x fw].
- note the normal font (left) has a smaller space before the '.' than the fixed width font (right)
- border [border]
- :faโ๏ธ[ border]
Any thing remaining in the square brackets after handling the above options will be considered as a class to be applied to the icon.
Of course multiple options may be combined
\:fa:trash:[2x 90 #red border]
as :fa:trash:[2x 90 #red border]
Google also provides many useful icons,see [Google Material Font Cheatsheet], however there is a lot of hassle to add them to your document; we of course offer a simple shortcut, with the form
\:mi:font-name
E.g.
\:mi:add-shopping-cart
Will display a :mi:add-shopping-cart icon.
NOTE: Google Material fonts do not usually have a '-' in them, we use this to allow us to know where the font name ends. It is removed.
It is possible to scale the images, give them colors and apply CSS classes to them by adding this information in square brackets
E.g.
\:mi:alarm:[2x]
The options are
- size [lg] [2x], [3x], [4x], [5x]
- :mi:alarm:[lg] :mi:alarm:[2x], :mi:alarm:[3x], :mi:alarm:[4x], :mi:alarm:[5x]
- rotate [90], [180], [270]
- :mi๐[2x 90], :mi๐[2x 180], :mi๐[2x 270 ]
- flip vertical [flipv]
- :mi:build:[2x] vs :mi:build:[2x flipv]
- flip horizontal [fliph]
- :mi:add-shopping-cart:[2x] vs :mi:add-shopping-cart:[2x fliph]
- foreground color [#orangea700]
- :mi๐[2x #orangea700]
- foreground and background color [#yellow.black]
- :mi๐[2x #yellow.black]
Any thing remaining in the square brackets after handling the above options will be considered as a class to be applied to the icon.
Of course multiple options may be combined
\:mi:delete:[2x 90 #red border-inset-grey]
as :mi:delete:[2x 90 #red border-inset-grey]
All of the google material colors are available to be used both in css and style sections.
Orange with an accent of A700, is named as orangea700. Light blue 500 is lightblue500.
Anywhere in your document/css that uses color= or color: then these replacements can be made.
For the complete list of colors see [Google Colors]
It is possible to specify icons without type, however this is currently defaulting to Material Icons, until a third option is found, like the github set.
\:cake: should show a :cake:
It is possible to include content from other files, the methods match fenced code-block and their short cuts.
The optional arguments are
- class
- add a div with this CSS class name
- style
- add a div with this CSS style
- markdown
- import file is markdown and will need some tidying up
- headings
- if a markdown file, add this nunber of '#' characters to headers in the imported file
- date
- add the date the import file was updated to the end of the imported text
import can also be used as a synonym for include.
Example |
---|
|
Either of these methods will bring the contents of the file inline to the current document at the location where they are used.
Markdown does not include any facility for setting the maniulating the font of text in a document, however sometimes it is useful to be able to do some basic manipulation.
We have a HTML-like constructs
- For Underline - standard HTML
- <u> Your text </u>
- For Strikethroughs - standard HTML
- <s> Your text </s>
- For Colors
- <c:colorname> Your text </c>
- <c:#foreground.background> Your text </c>
Example | Output |
---|---|
|
<c:red>set this string to red <c:#white.blue>White foreground, blue background <c:#.green300>green300 background |
A fenced code-block is a way of showing that some text needs to be handled differently. Often this is used to allow markdown systems (and [pandoc] is no exception) to highlight program code.
code-blocks take the form
Example |
---|
|
Code-blocks ALWAYS start at the start of a line without any preceding whitespace. The 'top' line of the code-block can wrap onto subsequent lines, this line is considered complete when the final '}' is seen. There should be only whitespace after the closing '}' symbol before the next line.
We use this construct to create our own handlers to generate HTML or markdown.
Note that only code-blocks described in this documentation have special handlers and can make use of extra features such as buffering.
If using [pandoc] then you can take advantage of the code blocks for code syntax highlighting
Example | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Output | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
~~~~{.perl}
sub process
{
my $self = shift ;
my ( $tag, $content, $params, $cachedir ) = @_ ;
}
If the code-block would normally produce some output that we do not want displayed at the current location then we would need to use the no_output argument.
We can also have the content of a code-block replaced with content from a buffer by using the from_buffer argument. This is also displayed in the example above. To use the contents (or output of a buffered code-block) we wrap the name of the buffer once again with percent '%' symbols, once again we force upper case.
Buffering also allows us to add content into markdown constructs like bullets.
By using setting an ifnot attribute to a true value, it is possible to only set the contents of the buffer if the buffer is currently empty. This is useful in cases where a parent document wants to set a value and a child document, which may be used in other documents wants to have a default for instances when the parent document is not providing a value.
The text plugin has lots of simple handlers, they all output text/HTML. Software engineers often use [JSON] to transfer data between systems, this often is not nice to create for documentation. [YAML] which is a superset of [JSON] is much cleaner so we have a
Software engineers often use [XML] to transfer data between systems, this often is not nice to create for documentation. We cam create basic XML, we do not allow element attributes. If you want real XML layout use .xml in a fenced code block.
Create a simple table using CSV style data
This is very similar to Table but styled to look like a spreadsheet
The same cell align and color options from table are valid here too.
With one code-block we can create a list of links The code-block contents comprises a number of lines with a reference and a URL. The reference comes first, then a '|' to separate it from the URL. The reference may then be used elsewhere in your document if you enclose it with square ([]) brackets There is only one argument
These links used in this example are the ones used in this document.
Documents often need revision history. I use this code-block to create a nice version table of this history. The content for this code-block comprises a number of sections, each section then makes a row in the generated table.
The version may be any string, YYYY-MM-DD shows the date the change took place. Alternate date formats is DD-MM-YYYY and '/' may also be used as a field separator. So give proper formatting to the content in the changes column you should indent text after the version/date line with 4 spaces, not a tab character.
There are 2 ways for force the start of a new page, using the .page fenced code block or by having 4 '-' signs next to each other, i.e. '----' on a line on their own
Create a columner layout, like a newspaper. The full text in the content is split into columns, the height of the section is determined by the volume of the text. The optional arguments are
This should generally be used as a short block as an easy way to increment appendix values in headings. Appendicies will be created as 'Appendix A', 'Appendix B' etc.
This should generally be used as a short block as an easy way to increment counter values, e.g. in headings The optional arguments are
If its useful to comment your software, likely you will also find it useful to comment your documents. Having a comment construct allows sections to be removed/hidden too.
Import a file and indent it 4 spaces. This is useful if you want to pull code or config files etc into your document to explain them. The optional arguments are
Draw a percent bar The required arguments are
The optional arguments are
Draw a bulleted list as a directory tree. Bullets are expected to be indented by 4 spaces, we will only process bullets that are * + or -.
Badges (or shields) are a way to display information, often used to show status of an operation on websites such as github. Examples of shields can be seen at shields.io The badges are placed inline, so you can insert text around the fenced codeblock. Depending on your template the color of the text and the color for the status portion may clash, so take care! The required argument are
The optional arguments are
Buttons are like badges but with no status, just a simple styled item. The buttons are placed inline, so you can insert text around the fenced codeblock. The required argument are
The optional arguments are
Show that something is important by putting it in a box The optional arguments are
Show that something is important by putting it in a box with an icon This is the complete form of the Admonitions. There are thirteen types
The optional arguments are
{{.note explain=1 icon=1 content='sample text'}} {{.info explain=1 icon=1 content='sample text'}} {{.tip explain=1 icon=1 content='sample text'}} {{.important explain=1 icon=1 content='sample text'}} {{.warning explain=1 icon=1 content='sample text'}} {{.caution explain=1 icon=1 content='sample text'}} {{.danger explain=1 icon=1 content='sample text' style='background-color:green50;font-size:1.5em;'}} {{.todo explain=1 icon=1 content='sample text, 70% width' width='70%'}} {{.aside explain=1 icon=1 content='sample text' title='Try this'}} {{.question explain=1 icon=1 content='There is a lot to read' title='Have you read the docs'}} {{.note explain=1 icon=:mi:settings-bluetooth content='Google material icon' title='Bluetooth Settings' }} {{.sample icon=1 explain=1 content='Some sample code or notes etc' title='Sample' }} Build a glossary of terms or abbreviations as you progress with your document. Show them later on, there is no way (currently) to place the glossary ahead of any definitions.
If you find that you are using the same items in multiple documents, then you may wish to use a glossary file, this is a YAML file
The YAML file has the format
Pandoc provides for blockquotes, these are often like
as
We want something that can be styled differently and can have a title The optional arguments are
Sparklines are simple horizontal charts to give an indication of things, sometimes they are barcharts but we have nice smooth lines. The only valid contents of the code-block is a single line of comma separated numbers. The optional arguments are
Displaying charts is very important when creating reports, so we have a simple chart code-block.
We will buffer some data to start. The content comprises lines of comma separated data. The first line of the content is the legends; subsequent lines relate to each of these legends.
Message Sequence Charts Software (or process) engineers often want to be able to show the sequence in which a number of events take place. We use the [msc] program for this. This program needs to be installed onto your system to allow this to work The content for this code-block is EXACTLY the same that you would use as input to [msc] The optional arguments are
Software engineers love to draw diagrams, [PlantUML] is a java component to make this simple. You will need to have a script on your system called 'uml' that calls java with the plantuml component. Mine is available from [My Github] repo. The content for this code-block must be the same that you would use to with the [PlantUML] software The optional arguments are
[PlantUML] can also create simple application interfaces See [Salt]
Plantuml can generate random sudoku patterns
To always generate the same pattern, append a seed value after 'sudoku'
Draw a bulleted list as a tree using the plantuml salt GUI layout tool. Bullets are expected to be indented by 4 spaces, we will only process bullets that are * + or -.
Diagrams Through Ascii Art This is a special system to turn ASCII art into pretty pictures, nice to render diagrams. You do need to make sure that you are using a proper monospaced font with your editor otherwise things will go awry with spaces. Rather than use the [ditaa] application and to reduce the number of applications that need to be installed on the system, we use the ditaa component of plantuml. This does have some limitations, for example there is no way to switch spaces or shadows off. However this is a useful tradeoff The content for this code-block must be the same that you would use to with the ditaa software. The optional arguments are
[graphviz] allows you to draw connected graphs using text descriptions. The content for this code-block must be the same that you would use to with the [graphviz] software The optional arguments are
There is no nice way to convert plain text to mindmaps, the only way normally would be to use graphviz or something similar. However, converting a bulleted list into a simple mindmap would be ideal! Each bulleted item would be a node in the mindmap. Bullets can be '*', '+' or '-' and should be indented 4 spaces to indicate a child. Poor indenting can be managed to a degree. There should be a single top level bullet, which is used as the root of the map, see the example below. Multiple top level bullets will result in a badly organised mindmap. Markdown style bold and italics markers can be used, as can '\n' to start a new line in a node. Comments can be added and will be ignored when rendering the mindmap, anything following ' :' will be considered as a comment. The optional arguments are
Bullet text can override some shapes
Bullet text can include a color override
Creating venn diagrams may sometimes be useful, though to be honest this implementation is not great, if I could find a better way to do this then I would!
Sometimes having barcodes in your document may be useful, certainly qrcodes are popular. The code-block only allows a single line of content. Some of the barcode types need content of a specific length, warnings will be generated if the length is incorrect. The arguments allowed are
As qrcodes are now quite so prevalent, they have their own code-block type. We can do qr codes, just put in anything you like, this is a URL for bbc news
This is a complex graph/chart drawing package available from https://glx.sourceforge.net/ The optional arguments are
This is the granddaddy of charting/plotting programs, available from https://gnuplot.sourceforge.net/. The optional arguments are
This is a rather old school charting applitcation, though it can create some graphs and charts that the other plugins cannot, e.g. Timelines. The optional arguments are
Its best to let ploticus control the size of the generated images, you may need some trial and error with the ploticus 'pagesize:' directive.
Display an image with a bounding box so it looks like a polaroid snap. reate a polaroid style image with space underneath for writing on. Image may be automatically rotated depending upon the exif information The required arguments are
The optional arguments are
Blockdiag provides a number of ways to create nice diagrams. See https://blockdiag.com/ for more information, how to install and examples. To keep things simple, we add the correct wrapper around the fenced codeblock, so that there is no need to add blockdiag { etc to the start and end of the blocks. The optional arguments are
Similar to graphviz, layout is more grid based.
One for the system administrators, draw your network nicely with the various networks and systems connected to them.
Useful to describe packets of data, e.g. binary data passed between networks or stored to files.
Useful for system administrators to keep track of their server rooms.
The classic swim lanes.
Very similar to the output of mscgen and uml tags.
Dataflow diagrams allow multiple outputs from a single workflow description. See https://github.com/sonyxperiadev/dataflow/blob/master/USAGE.md for more information, how to install and examples. The optional arguments are
The example images are a bit compressed to fit in the table, normally they look a lot better than this!
Some of the charts from https://developers.google.com/chart/ have been implemented. This plugin requires phantomjs to be installed on your system. All the charts have some optional arguments in common
Timeline charts are useful for project management, as an alternative to gantt charts The optional arguments are
The timeline content consists of rows of lines with a task name, a task item, start and end times. Optionally a #color note at the end of the line (HTML color name or triplet) will set the color of the bar. Dates should be in yyyy-mm-dd format.
We will set some data into a buffer for ease of use
Gantt charts are useful for project management. The optional arguments are
The gantt content consists of rows of lines with a task id, a task name, a task group, start and end times and optionally dependencies and percent completed. Dates should be in yyyy-mm-dd format.
We will set some data into a buffer for ease of use
From google charts: A sankey diagram is a visualization used to depict a flow from one set of values to another. The things being connected are called nodes and the connections are called links. Sankeys are best used when you want to show a many-to-many mapping between two domains (e.g., universities and majors) or multiple paths through a set of stages (for instance, Google Analytics uses sankeys to show how traffic flows from pages to other pages on your web site). For the curious, they're named after Captain Sankey, who created a diagram of steam engine efficiency that used arrows having widths proportional to heat loss. The optional arguments are
Conversion of some smilies to icons. A small set of smilies are converted to UTF-8 characters, which can be tricky to show as not all fontsets support these. Basic text smilies are handled, however there is also a range of smilies that are also available as words pre/post fixed with a colon, e.g. ::word::. Some of these will generate fontawesome icons and some will be picked from the very extensive [Emoji Cheatsheet], check this latter link for the full list of emoji words supported. Note that some of these may result, when generating PDFs, emoji's that do not display, trial and error is key!
Some unicodes only work when viewed via a browser and would not appear if the HTML is converted to PDF, so images are used as replacements.
Included in the distribution is a script to make use of all of the above code-blocks to alter [Markdown] into nicely formatted documents. Here is the help
On the first time you run ct2 a default template will be created in ~/.ct2/templates/default/template.html, a config file to accompany this will be created in ~/.ct2/templates/default/template.html Create new templates in ~/.ct2/templates, one directory for each template, follow the example in the default directory. If you are using [PrinceXML], remember that it is only free for non-commercial use, it also adds a purple P to the top right of the first page of your document, though this does not appear when you print out the document. |