Table of Contents

A2S Plugin

Compatible with DokuWiki

  • 2024-02-06 "Kaos" unknown
  • 2023-04-04 "Jack Jackrum" yes
  • 2022-07-31 "Igor" yes
  • 2020-07-29 "Hogfather" yes

plugin Convert ASCII art diagram to nice embedded SVG images.

Last updated on
2022-06-21
Provides
Syntax
Repository
Source

Similar to diagram, ditaa, flowcharts

Tagged with ascii, diagram, image, images, media, svg

a2s is a little plugin that turns ASCII art boxes, lines and arrows into nice SVG images. It is based on ASCIIToSVG by Devon H. O'Dell. It is very similar to the ditaa plugin but does not require external programs to run. It is compatible with the ODT export plugin.


june 2022: a2s works well with DW igor RC2 and php 8.1. But exports to odt with the odt plugin currently fails. There is no problem with php 7.4. See this bug report.

Installation

Search and install the plugin using the Extension Manager. Refer to Plugins on how to install plugins manually.

Examples/Usage

logo.a2s
<a2s>
 .-------------------------.
 |[Logo]                   |
 | .---.-. .-----. .-----. |
 | | .-. | +-->  | |  <--| |
 | | '-' | |  <--| +-->  | |
 | '---'-' '-----' '-----' |
 |  ascii     2      svg   |
 |                         |
 '-------------------------'
  https://9vx.org/~dho/a2s/
 
[Logo]:     {"fill":"#88d","a2s:delref":true}
</a2s>

tryme.a2s
<a2s> 
          +----+--------+                                :
          |    |        |             .----------------. |
          v    |        |             |[0]             | |
     #---------+---.    |        o----+----> Waow !    | v
     |             |<---+       /     |                | ^
====>| Hello       |           /      '----------------' |
====>| (svg) World '------.   /  #------#   .-------.    |
     |    .-----#         |==+   |      |   |       |    |
     '----#     '---------#      #------#   '-------'
[0]: {"a2s:link":"https://github.com/schplurtz/a2s","fill":"#CE3B83","stroke":"#F50078","stroke-dasharray":"5 5","stroke-width":4,"a2s:type":"cloud","a2s:delref":true}
</a2s>

Syntax

Please, note that the reference doc is on ASCIIToSVG site.

Styling shapes and linking

Colors are expressed either

It is not possible to choose text color. When background is dark, ASCIIToSVG uses white. When background is light, text is written in black.

Available styling parametre :

here is a full example example :

[0]: {"fill":"#d48","stroke":"#F50078","stroke-dasharray":"5 5","stroke-width":4,"a2s:type":"cloud","a2s:delref":true,"a2s:link":"https://github.com/schplurtz/a2s"}

Alignment

Just like with regular images, you can align your SVG graphics by inserting spaces after < and before >. If there are more spaces on the left of the word a2s, then the image is right-aligned, if there are more spaces on the right, the image is left-aligned. When there is the same number of spaces on both sides of a2s, the image is centered

< a2s>
 .---------.
 |[1]      |
 | .-----. |
 | |  <--+ |
 | +-->  | |
 | '-----' |
 |   svg   |
 |<    a2s>|
 '---------'

[1]:     {"fill":"#E97B11","a2s:delref":true}
</a2s>
<a2s  >
 .---------.
 |[blue]   |
 | .---.-. |
 | | .-. | |
 | | '-' | |
 | '---'-' |
 |  ascii  |
 |<a2s    >|
 '---------'

[blue]:     {"fill":"blue","a2s:delref":true}
</a2s>
<  a2s  >
 .---------.
 |[lc]     |
 | .-----. |
 | +-->  | |
 | |  <--+ |
 | '-----' |
 |    2    |
 |<  a2s  >|
 '---------'

[lc]:     {"fill":"LemonChiffon","a2s:delref":true}
</a2s>

< a2s>
 .---------.
 |[1]      |
 | .-----. |
 | |  <--+ |
 | +-->  | |
 | '-----' |
 |   svg   |
 |<    a2s>|
 '---------'
[1]:     {"fill":"#bcd2ee","a2s:delref":true}
</a2s>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed accumsan nec
odio quis aliquet. Nulla gravida ac est venenatis rhoncus. Aenean viverra
felis semper turpis commodo, ut vehicula dui mattis. Vivamus malesuada
vulputate justo. Suspendisse potenti. Etiam porttitor elementum nulla in
ultricies. Vestibulum volutpat nibh eu faucibus scelerisque. Suspendisse
eleifend arcu neque, at tristique metus tempus semper. Nullam ante leo,
convallis sit amet accumsan sed, semper nec quam. Curabitur fringilla,
orci id scelerisque varius, enim est ultrices est, et elementum magna
metus sit amet eros. Sed pharetra semper ligula sit amet efficitur. Mauris
congue accumsan egestas. Suspendisse potenti. Curabitur tincidunt
metus non justo tempus lacinia. Donec ornare velit a massa semper
ullamcorper. Donec dapibus ante vel lacus efficitur sodales. Integer
pretium eleifend nulla, at ullamcorper ipsum pellentesque placerat. Cras
condimentum iaculis leo. Sed sit amet pretium sem, sit amet suscipit
nibh. Nulla congue molestie purus sed congue. Fusce tincidunt ipsum
id molestie pellentesque. Curabitur lobortis placerat risus eget
vulputate. Maecenas ac feugiat ex, at facilisis nulla. Etiam rutrum
quis eros et facilisis. Nulla sodales molestie odio, id egestas massa
aliquam vel. Mauris vulputate ante sed volutpat euismod. Sed eleifend,
urna vitae auctor consequat, dui felis elementum ex, ut laoreet nunc
nisl convallis mi. Nullam id bibendum justo.

list of known SVG shapes

shapes
<a2s>
Shapes :
.----------.     .----------.     .----------.
|[cloud]   |     |[computer]|     |[diamond] |
|          |  +->|          |<-o->|          |
|          |  |  |          |  |  |          |
.----------.  |  .----------.  |  .----------.
--------------o----------------+
.----------.  |  .----------.  |  .----------.
|[document]|  :  |[storage] |  |  |[printer] |
|          |<-+->|          |  |  | Some txt |
|          |     |          |<-+->|          |
.----------.     .----------.     '----------'
 
.----------.     .----------.     .----------.
|[cl]      |     |[c]       |     |[yn]      |
|          |  +->|          |<-o->|          |
|          |  |  |          |  |  |          |
.----------.  |  .----------.  |  .----------.
--------------o----------------+
.----------.  |  .----------.  |  .----------.
|[d]       |  :  |[st]      |  |  |[p]       |
|          |<-+->|          |  |  | Some txt |
|          |     |          |<-+->|          |
.----------.     .----------.     '----------'
 
 
[printer]:  {"a2s:type":"printer","fill":"#ff1493"}
[computer]: {"a2s:type":"computer"}
[cloud]:    {"a2s:type":"cloud"}
[diamond]:  {"a2s:type":"diamond"}
[document]: {"a2s:type":"document"}
[storage]:  {"a2s:type":"storage"}
[p]:        {"a2s:type":"printer","fill":"#ff1493","a2s:delref":true}
[c]:        {"a2s:type":"computer","a2s:delref":true}
[cl]:       {"a2s:type":"cloud","a2s:delref":true}
[yn]:       {"a2s:type":"diamond","a2s:delref":true}
[d]:        {"a2s:type":"document","a2s:delref":true}
[st]:       {"a2s:type":"storage","a2s:delref":true}
</a2s>

shapes inside shapes and custom styles

Transparency is obtained by using an invalid colorname. This is undocumented. This may change depending on the browser or rendering library.

<a2s>
.---------------------------.   .----------.
|[storage]                  |   |[document]|
|         STORAGE           |   |          |
|                           |   |          |
|                           |   .----------.
|       .----------.    .---+-------.
|       |[document]|    |[0]|TRANS  |
|       |          |    |   |PARENT |
|       |          |    '---+-------'
|       .----------.        |
.---------------------------.


storage:          : document :
"fill":"#a7ffbe"  : "stroke":"#d627d8"
"a2s:delref":true : "stroke-width":9
                  : "stroke-dasharray":"5 3 3 7 10 5"
  5       3     3      7          10          5
.-----. .---. .---. .-------. .----------. .-----.
|[r]  | |   | |[r]| |       | |[r]       | |     |
'-----' '---' '---' '-------' '----------' '-----'

[document]: {"a2s:type":"document","stroke":"#d627d8","stroke-width":9,"stroke-dasharray":"5 3 3 7 10 5"}
[storage]:  {"a2s:type":"storage","fill":"#a7ffbe","a2s:delref":true}
[0]:        {"stroke":"#FFEE49","stroke-width":9,"a2s:delref":true,"fill":"caramba"}
[r]:        {"fill":"#d627d8","a2s:delref":true}
</a2s>

Configuration and Settings

There is nothing to configure.

Development

Change Log

FAQ

:?: When I export to pdf with dw2pdf, the arrowheads on line are not drawn, and alignment is not respected. Can you/I do something about that ?
:!: No. As of 2017/07/27, unless you are the a developer of dw2pdf or mpdf, its PDF library, there is nothing to do. Sorry.

:?: Is it possible to alter the line color using css or a configuration value? under the bootstrap / bootswatch / cyborg theme which is dark the lines are black on a black background. For now I've just worked around it using the following in a less css file to alter the background color

&.cyborg {
  svg.a2s {
    background-color:#303030;
  }
}