Readme.rst 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. ================================================
  2. PlantUML plugin for Pelican rst and md documents
  3. ================================================
  4. This plugin allows you to define UML diagrams directly into rst or md documents using the great
  5. PlantUML_ tool.
  6. It gets the content of ``uml`` directive, passes it to the external
  7. program PlantUML_ and then links the generated image to the document.
  8. .. contents::
  9. Installation
  10. ============
  11. You need to install PlantUML_ (see the site for details) and Graphviz_ 2.26.3 or later.
  12. The plugin expects a program ``plantuml`` in the classpath. If not installed by your package
  13. manager, you can create a shell script and place it somewhere in the classpath. For example,
  14. save te following into ``/usr/local/bin/plantuml`` (supposing PlantUML_ installed into
  15. ``/opt/plantuml``):
  16. .. code-block:: bash
  17. #!/bin/bash
  18. java -jar /opt/plantuml/plantuml.jar ${@}
  19. For Gentoo_ there is an ebuild at http://gpo.zugaina.org/dev-util/plantuml/RDep: you can download
  20. the ebuild and the ``files`` subfolder or you can add the ``zugaina`` repository with _layman
  21. (reccomended).
  22. Usage
  23. =====
  24. Add ``plantuml`` to plugin list in ``pelicanconf.py``. For example:
  25. .. code-block:: ptyhon
  26. PLUGINS = [ "sitemap", "plantuml" ]
  27. One loaded the plugin register also the Pyhton-Markdown_ extension.
  28. RST usage
  29. ---------
  30. Use the ``uml`` directive to start UML diagram description. It is not necessary to enclose
  31. diagram body between ``@startuml`` and ``@enduml`` directives: they are added automatically
  32. before calling ``plantuml``.
  33. In addition to ``class`` and
  34. ``alt`` options common to all images, you can use the ``format`` option to select what kind
  35. of image must be produced. At the moment only ``png`` and ``svg`` are supported; the default
  36. is ``png``.
  37. Please note that the ``format`` option in not recognized by the ``plantuml`` extension of
  38. ``rst2pdf`` utility (call it with ``-e plantuml.py``) so if you use it you can get errors from
  39. that program.
  40. MD usage
  41. --------
  42. For use with the Pyhton-Markdown_ syntax, the UML block must be enclose with ``::uml::``:
  43. .. code-block:: markdown
  44. ::uml:: [format=...] [classes=...] [alt=...]
  45. PlantUML script
  46. ::end-uml::
  47. Please keep a blank line before ``::uml::`` and after ``::end-uml::`` to be sure that the UML code will be correctly
  48. recognized.
  49. See Examples_ for more details.
  50. With MD syntax options must be specified in the same line as the opening ``:uml::``, with the
  51. order ``format``, ``classes`` anmd ``alt``. The general syntax for option is
  52. .. code-block:: text
  53. option="value"
  54. Option can be enclosed with single or double quotes, as you like.
  55. Options defaults are the same as for the rst plugin.
  56. For pandoc_reader plugin users
  57. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  58. The plugin ``pandoc_reader`` sends the Markdown body to the pandoc_ tool which has it's own Markdown parser, written
  59. in Haskell_ language: Python_ plugins manipulating Markdown posts (such this) are not used because the entire body
  60. id passed to pandoc_ without any iteraction by Pelican_.
  61. For those who are using the ``pandoc_reader`` plugin and wants to include PlantUML_ diagrams, use the
  62. ``pandoc-plantuml`` script (only *nix, sorry): it is a wrapper for filtering the code blocks parsed by pandoc_ before
  63. writing out the converted file.
  64. It is an adaption of the great work by Kurt Bonne for his
  65. `pandoc-plantuml-filter <https://github.com/kbonne/pandoc-plantuml-filter.git>`_.
  66. To use it, copy the ``pandoc-plantuml`` file in a subdirectory of your pelican project (for example `pandoc_extensions`)
  67. and make sure it is executable (``chmod +x pandoc-plantuml``).
  68. In the ``pelicanconf.py`` configure the needed plugins:
  69. .. code-block:: python
  70. PLUGINS = ['pandoc_reader'] // Yes, plantuml plugin non necessary
  71. PANDOC_ARGS = ['--filter=pandoc_extensions/pandoc-plantuml']
  72. In Markdown posts use the following syntax to include PlantUML_ diagrams:
  73. .. code-block:: markdown
  74. ```plantuml
  75. @startuml
  76. Alice -> Bob: Authentication Request
  77. Bob --> Alice: Authentication Response
  78. Alice -> Bob: Another authentication Request
  79. Alice <-- Bob: another authentication Response
  80. @enduml
  81. ```
  82. Rendered images will bu put in the output/images folder.
  83. Debugging
  84. ---------
  85. The plugin can produce debugging informations to help to locate errors. To enable debugging
  86. execute ``pelican`` in debug mode:
  87. .. code-block:: console
  88. make DEBUG=1 html
  89. Examples
  90. ========
  91. Sequence diagram (from PlantUML_ site):
  92. .. code-block:: rst
  93. .. uml::
  94. :alt: Sample sequence diagram
  95. participant User
  96. User -> A: DoWork
  97. activate A #FFBBBB
  98. A -> A: Internal call
  99. activate A #DarkSalmon
  100. A -> B: << createRequest >>
  101. activate B
  102. B --> A: RequestCreated
  103. deactivate B
  104. deactivate A
  105. A -> User: Done
  106. deactivate A
  107. Output:
  108. .. image:: http://plantuml.sourceforge.net/imgp/sequence_022.png
  109. :alt: Sample sequence diagram
  110. Same diagram with Pyhton-Markdown_ syntax:
  111. .. code-block:: markdown
  112. ::uml:: format="png" alt="Sample sequence diagram"
  113. participant User
  114. User -> A: DoWork
  115. activate A #FFBBBB
  116. A -> A: Internal call
  117. activate A #DarkSalmon
  118. A -> B: << createRequest >>
  119. activate B
  120. B --> A: RequestCreated
  121. deactivate B
  122. deactivate A
  123. A -> User: Done
  124. deactivate A
  125. ::end-uml::
  126. Another example from PlantUML_ site (activity diagram):
  127. .. code-block:: rst
  128. .. uml::
  129. start
  130. :ClickServlet.handleRequest();
  131. :new page;
  132. if (Page.onSecurityCheck) then (true)
  133. :Page.onInit();
  134. if (isForward?) then (no)
  135. :Process controls;
  136. if (continue processing?) then (no)
  137. stop
  138. endif
  139. if (isPost?) then (yes)
  140. :Page.onPost();
  141. else (no)
  142. :Page.onGet();
  143. endif
  144. :Page.onRender();
  145. endif
  146. else (false)
  147. endif
  148. if (do redirect?) then (yes)
  149. :redirect process;
  150. else
  151. if (do forward?) then (yes)
  152. :Forward request;
  153. else (no)
  154. :Render page template;
  155. endif
  156. endif
  157. stop
  158. Generated image:
  159. .. image:: http://plantuml.sourceforge.net/imgp/activity2_009.png
  160. :alt: Sample activity diagram
  161. .. _PlantUML: http://plantuml.sourceforge.net
  162. .. _Sabayon: http://www.sabayon.org
  163. .. _Gentoo: http://www.gentoo.org
  164. .. _layman: http://wiki.gentoo.org/wiki/Layman
  165. .. _Graphviz: http://www.graphviz.org
  166. .. _Pyhton-Markdown: http://pythonhosted.org/Markdown
  167. .. _pandoc: http://johnmacfarlane.net/pandoc
  168. .. _Haskell: http://www.haskell.org/haskellwiki/Haskell
  169. .. _Python:: http://www.python.org
  170. .. _Pelican: http://docs.getpelican.com/en