skuro / plantuml-mode

A major mode for editing PlantUML sources in Emacs
GNU General Public License v3.0
514 stars 97 forks source link

Failed to run plantuml in an org-babel src block #165

Open exaos opened 1 year ago

exaos commented 1 year ago

Summary

In an org-mode file, I want that the following plantuml source block can generate an inline image automatically which executing org-babel-execute-src-block (or press C-cC-c).

#+BEGIN_SRC plantuml :file test_uml.png  :cmdline -charset UTF-8
  title Example Sequence Diagram
  activate Client
  Client -> Server: Session Initiation
  note right: Client requests new session
  activate Server
  Client <-- Server: Authorization Request
  note left: Server requires authentication
  Client -> Server: Authorization Response
  note right: Client provides authentication details
  Server --> Client: Session Token
  note left: Session established
  deactivate Server
  Client -> Client: Saves token
  deactivate Client
#+END_SRC

But I failed with the following output image test_uml.png which is actually an ASCII file:

$ head test_uml.png 
Usage: java [options] <mainclass> [args...]
           (to execute a class)
   or  java [options] -jar <jarfile> [args...]
           (to execute a jar file)
   or  java [options] -m <module>[/<mainclass>] [args...]
       java [options] --module <module>[/<mainclass>] [args...]
           (to execute the main class in a module)
   or  java [options] <sourcefile> [args]
           (to execute a single source-file program)

Configurations

The plantuml configuration clip is as the following:

(use-package plantuml-mode
  :config
  ;; setup plantuml-mode
  (setq plantuml-default-exec-mode 'executable)
  ;; (setq plantuml-default-exec-mode 'jar)
  (setq plantuml-executable-path
        (vl-util-find-1st-candidate
         `("/usr/bin/plantuml"
           "/usr/local/bin/plantuml"
           "/opt/homebrew/bin/plantuml"
           )))
  ;; setup plantuml for org-babel
  (add-to-list 'org-src-lang-modes '("plantuml" . plantuml))
  (setq org-plantuml-exec-mode 'executable)
  (setq org-plantuml-executable-path plantuml-executable-path)
  ;; (require 'ob-plantuml) ; OBSOLETED
  (setq org-plantuml-jar-path
        (vl-util-find-1st-candidate
         `("/usr/share/java/plantuml/plantuml.jar"
           "/opt/plantuml/plantuml.jar"
           "/usr/local/opt/plantuml/libexec/plantuml.jar"
           "/opt/homebrew/opt/plantuml/libexec/plantuml.jar"
           ,(expand-file-name "plantuml.jar" vl-prelude-utils-dir)
           )))
  (setq plantuml-jar-path org-plantuml-jar-path) ; OBSOLETED
  ;; (setq plantuml-jar-args '())
  ;; Enable puml-mode for PlantUML files
  (add-to-list 'auto-mode-alist '("\\.puml\\'" . plantuml-mode))
  (add-to-list 'auto-mode-alist '("\\.plantuml\\'" . plantuml-mode)))

I checked every variable (e.g., plantuml-jar-path, plantuml-default-exec-mode), and I confirm that they are correctly assigned.

zoechi commented 9 months ago

I had to wrap the content with @startuml and @enduml and then just include the content from a standalone .puml file like

#+begin_src plantuml :file ./0003_files/layout_architecture.svg
@startuml
!include 0003_files/layout_architecture.puml
@enduml
#+end_src

The standalone .puml file is wrapped in @startuml and @enduml as well (otherwise it wouldn't work as standalone.