Fruchtzwerg94 / PlantUmlViewer

A Notepad++ plugin to generate, view and export PlantUML diagrams
MIT License
82 stars 9 forks source link

PlantUML Build-In Function %filename not supported #30

Open SieDa opened 1 month ago

SieDa commented 1 month ago

Description Running the example file PlantUML-buildin-functions.puml in NotePad delivers no value to %filename. Running the example file in Windows 10 from Git Bash with the same JAR File provides a proper output.

Reproduction Steps to reproduce the behavior:

  1. Update to PlantUmlViewer/plantuml-1.2024.3.jar
  2. Process the file in Notepad and export to SVG PlantUML-buildin-functions-notepad.svg
  3. Process the file in Git Bash with
    java -jar "c:/Program Files/Notepad++/plugins/PlantUmlViewer/plantuml-1.2024.3.jar"
    -tsvg -charset UTF-8 PlantUML-buildin-functions.puml
  4. Compare both output files (attached examples) PlantUML-buildin-functions-gitBash-win10 PlantUML-buildin-functions-gitBash-win10 PlantUML-buildin-functions-notepad-win10 PlantUML-buildin-functions-notepad-win10

Expected behavior

  1. I would expect to be able to put the %filename() into the footer.
  2. The example might be good for the plantuml manual to explain buildin functions.
  3. The output of Notepad processing is supported by the windows explorer preview. But the embedding of code differs from that in the PlantUML Standard.

Can you explain the difference in processing XML Export results in Notepad to the Git Bash processing (Comparing the code makes this visible)?

Is it possible to run it in Notepad and achieve the same result:

bash:
<?xml version="1.0" encoding="us-ascii" standalone="no"?> ...
notepad:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">...

Code PlantUML-buildin-functions.puml

@startuml

left header
How to place an SVG-Logo here? 
'<img: src="image.png"{scale=0.12}>
endheader

left footer
Rendered with PlantUML version %version() on %date("yyyy-MM-dd' at 'hh:mm") from file: %filename()
endfooter

title PlantUML buildin functions

l -> r
note left
Name 
  Description 
  Example 
  > output

%date ("yyyy-MM-dd' at 'hh:mm")
  Retrieve current date. 
  You can provide an optional format for the date 
  > %date("yyyy-MM-dd' at 'hh:mm")

%dirpath ()
  Retrieve current dirpath 
  > %dirpath() 

%false ()
  Return always false 
  > %false() 

%file_exists ("./PlantUML-buildin-functions.puml")
  Check if a file exists on the local filesystem 
  > %file_exists("./PlantUML-buildin-functions.puml")

%filename ()
  Retrieve current filename 
  > %filename() 

%function_exists ("%filename")
  Check if a function exists 
  > %function_exists("%filename")

%set_variable_value ("$my_value","my_value")
  Set a global variable 
  > %set_variable_value("$my_value","my_value")

%get_variable_value ("$my_value")
  Retrieve some variable value  
  > %get_variable_value("$my_value")

%getenv ("Path")
  Retrieve environment variable value 
  > %getenv("Path") 

%intval ("42")
  Convert a String to Int 
  > %intval("42") 
end note
note right
%lower ("Hello")
  Return a lowercase string 
  > %lower("Hello")

%newline () X
  Return a newline 
  > %newline() X

%not (2+2==4)
  Return the logical negation of an expression 
  > %not(2+2==4)

%string (1 + 2)
  Convert an expression to String 
  > %string(1 + 2) 

%strlen ("foo")
  Calculate the length of a String 
  > %strlen("foo") 

%strpos ("abcdef", "ef")
  Search a substring in a string 
  > %strpos("abcdef", "ef") 

%substr ("abcdef", 3, 2)
  Extract a substring. Takes 2 or 3 arguments 
  > %substr("abcdef", 3, 2) 

%true ()
  Return always true 
  > %true() 

%upper ("Hello")
  Return an uppercase string 
  > %upper("Hello") 

%variable_exists ("$my_value")
  Check if a variable exists 
  > %variable_exists("$my_value") 

%version ()
  Return PlantUML current version 
  > %version()
end note

@enduml

Environment

Additional information

  1. Maybe the parameter -filedir might enable the proper setting.

  2. Also the !include of files with relative path descriptions ./file.puml or ../path/file.puml does not work in my environment of Notepad++.

SieDa commented 1 month ago

All environment variables are delivered by printenv, e.g.:

OS=Windows_NT
HOMEDRIVE=C:

We could not get this working for the %getenv() function at all, to access them, as shown in the example above:

%getenv ("OS")
  Retrieve environment variable value 
  > %getenv("OS") 
Fruchtzwerg94 commented 1 month ago

Hi @SieDa ,

thanks for your report. Filename was supported yet since it was not overridden by the plugin accordingly. I've fixed this in the latest commit. Try out the following build and let me know if it works for you: Run 10881066927.

Unfortunately, it seems like PlantUML isn't supporting %dirpath() the same way so this still will not work. I've created an issue at the PlantUML repository. Maybe they have a look at it soon.

BR, Philipp